Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scala): Add WriteAPI for Scala #347

Merged
merged 10 commits into from
May 18, 2022
Merged
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ _Briefly describe your proposed changes:_
- [ ] Rebased/mergeable
- [ ] A test has been added if appropriate
- [ ] `mvn test` completes successfully
- [ ] Commit messages are in [semantic format](https://seesparkbox.com/foundry/semantic_commit_messages)
- [ ] Commit messages are [conventional](https://www.conventionalcommits.org/en/v1.0.0/)
- [ ] Sign [CLA](https://www.influxdata.com/legal/cla/) (if not already signed)
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Features
1. [#337](https://github.com/influxdata/influxdb-client-java/pull/337): Supports `columns` function [FluxDSL]
1. [#347](https://github.com/influxdata/influxdb-client-java/pull/347): Add `Scala` WriteApi

### Bug Fixes
1. [#339](https://github.com/influxdata/influxdb-client-java/pull/339): Evaluation of connection string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ trait InfluxDBClientScala {
*/
@Nonnull def getQueryScalaApi(): QueryScalaApi

/**
* Create a new WriteApi client.
*
* @return the new client instance for the Write API
*/
@Nonnull def getWriteScalaApi: WriteScalaApi

/**
* Get the health of an instance.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/**
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.influxdb.client.scala

import akka.Done
import akka.stream.scaladsl.Sink
import com.influxdb.client.domain.WritePrecision
import com.influxdb.client.write.{Point, WriteParameters}

import javax.annotation.Nonnull
import scala.concurrent.Future

/**
* The Scala API to write time-series data into InfluxDB 2.x.
*
* @author Jakub Bednar (bednar@github) (05/09/2022 09:48)
*/
trait WriteScalaApi {
/**
* Write Line Protocol record into specified bucket.
*
* @param precision Precision for the unix timestamps within the body line-protocol.
* The [[com.influxdb.client.domain.WritePrecision.NS]] will be used as the precision if not specified.
* @param bucket Specifies the destination bucket for writes.
* The [[com.influxdb.client.InfluxDBClientOptions#getBucket]] will be used as the destination
* `bucket` if the `bucket` is not specified.
* @param org Specifies the destination organization for writes.
* The [[com.influxdb.client.InfluxDBClientOptions#getOrg]] will be used as the destination `organization`
* if the `org` is not specified.
* @return the sink that accept the record specified in InfluxDB Line Protocol. The `record` is considered as one batch unit.
*/
def writeRecord(precision: Option[WritePrecision] = None, bucket: Option[String] = None, org: Option[String] = None): Sink[String, Future[Done]]

/**
* Write Line Protocol records into specified bucket.
*
* @param precision Precision for the unix timestamps within the body line-protocol.
* The [[com.influxdb.client.domain.WritePrecision.NS]] will be used as the precision if not specified.
* @param bucket Specifies the destination bucket for writes.
* The [[com.influxdb.client.InfluxDBClientOptions#getBucket]] will be used as the destination
* `bucket` if the `bucket` is not specified.
* @param org Specifies the destination organization for writes.
* The [[com.influxdb.client.InfluxDBClientOptions#getOrg]] will be used as the destination `organization`
* if the `org` is not specified.
* @return the sink that accept the records specified in InfluxDB Line Protocol. The `records` are considered as one batch unit.
*/
def writeRecords(precision: Option[WritePrecision] = None, bucket: Option[String] = None, org: Option[String] = None): Sink[Seq[String], Future[Done]]

/**
* Write Line Protocol records into specified bucket.
*
* @param parameters specify InfluxDB Write endpoint parameters
* @return the sink that accept the records specified in InfluxDB Line Protocol. The `records` are considered as one batch unit.
*/
def writeRecords(@Nonnull parameters: WriteParameters): Sink[Seq[String], Future[Done]]

/**
* Write Data points into specified bucket.
*
* @param bucket Specifies the destination bucket for writes.
* The [[com.influxdb.client.InfluxDBClientOptions#getBucket]] will be used as the destination
* `bucket` if the `bucket` is not specified.
* @param org Specifies the destination organization for writes.
* The [[com.influxdb.client.InfluxDBClientOptions#getOrg]] will be used as the destination `organization`
* if the `org` is not specified.
* @return the sink that accept the Data points. The `point` is considered as one batch unit.
*/
def writePoint(bucket: Option[String] = None, org: Option[String] = None): Sink[Point, Future[Done]]

/**
* Write Data points into specified bucket.
*
* @param bucket Specifies the destination bucket for writes.
* The [[com.influxdb.client.InfluxDBClientOptions#getBucket]] will be used as the destination
* `bucket` if the `bucket` is not specified.
* @param org Specifies the destination organization for writes.
* The [[com.influxdb.client.InfluxDBClientOptions#getOrg]] will be used as the destination `organization`
* if the `org` is not specified.
* @return the sink that accept the Data points. The `points` are considered as one batch unit.
*/
def writePoints(bucket: Option[String] = None, org: Option[String] = None): Sink[Seq[Point], Future[Done]]

/**
* Write Data points into specified bucket.
*
* @param parameters specify InfluxDB Write endpoint parameters
* @return the sink that accept the Data points. The `points` are considered as one batch unit.
*/
def writePoints(@Nonnull parameters: WriteParameters): Sink[Seq[Point], Future[Done]]

/**
* Write Measurement into specified bucket.
*
* @param precision Precision for the unix timestamps within the body line-protocol.
* The [[com.influxdb.client.domain.WritePrecision.NS]] will be used as the precision if not specified.
* @param bucket Specifies the destination bucket for writes.
* The [[com.influxdb.client.InfluxDBClientOptions#getBucket]] will be used as the destination
* `bucket` if the `bucket` is not specified.
* @param org Specifies the destination organization for writes.
* The [[com.influxdb.client.InfluxDBClientOptions#getOrg]] will be used as the destination `organization`
* if the `org` is not specified.
* @tparam M the type of the measurement (POJO)
* @return the sink that accept the measurement. The `measurement` is considered as one batch unit.
*/
def writeMeasurement[M](precision: Option[WritePrecision] = None, bucket: Option[String] = None, org: Option[String] = None): Sink[M, Future[Done]]

/**
* Write Measurements into specified bucket.
*
* @param precision Precision for the unix timestamps within the body line-protocol.
* The [[com.influxdb.client.domain.WritePrecision.NS]] will be used as the precision if not specified.
* @param bucket Specifies the destination bucket for writes.
* The [[com.influxdb.client.InfluxDBClientOptions#getBucket]] will be used as the destination
* `bucket` if the `bucket` is not specified.
* @param org Specifies the destination organization for writes.
* The [[com.influxdb.client.InfluxDBClientOptions#getOrg]] will be used as the destination `organization`
* if the `org` is not specified.
* @tparam M the type of the measurement (POJO)
* @return the sink that accept the measurements. The `measurements` are considered as one batch unit.
*/
def writeMeasurements[M](precision: Option[WritePrecision] = None, bucket: Option[String] = None, org: Option[String] = None): Sink[Seq[M], Future[Done]]

/**
* Write Measurements into specified bucket.
*
* @param parameters specify InfluxDB Write endpoint parameters
* @tparam M the type of the measurement (POJO)
* @return the sink that accept the measurements. The `measurements` are considered as one batch unit.
*/
def writeMeasurements[M](@Nonnull parameters: WriteParameters): Sink[Seq[M], Future[Done]]
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import com.influxdb.LogLevel
import com.influxdb.client.InfluxDBClientOptions
import com.influxdb.client.domain.HealthCheck
import com.influxdb.client.internal.AbstractInfluxDBClient
import com.influxdb.client.scala.{InfluxDBClientScala, QueryScalaApi}
import com.influxdb.client.service.QueryService
import com.influxdb.client.scala.{InfluxDBClientScala, QueryScalaApi, WriteScalaApi}
import com.influxdb.client.service.{QueryService, WriteService}

import javax.annotation.Nonnull

Expand All @@ -41,6 +41,14 @@ class InfluxDBClientScalaImpl(@Nonnull options: InfluxDBClientOptions) extends A
*/
override def getQueryScalaApi(): QueryScalaApi = new QueryScalaApiImpl(retrofit.create(classOf[QueryService]), options)


/**
* Create a new WriteApi client.
*
* @return the new client instance for the Write API
*/
override def getWriteScalaApi: WriteScalaApi = new WriteScalaApiImpl(retrofit.create(classOf[WriteService]), options)

/**
* Get the health of an instance.
*
Expand Down
Loading