22
22
package com .influxdb .client .scala .internal
23
23
24
24
import akka .Done
25
- import akka .stream .scaladsl .{Flow , Keep , Sink }
25
+ import akka .stream .scaladsl .{Flow , Keep , Sink , Source }
26
26
import com .influxdb .client .InfluxDBClientOptions
27
27
import com .influxdb .client .domain .WritePrecision
28
28
import com .influxdb .client .internal .{AbstractWriteBlockingClient , AbstractWriteClient }
@@ -53,13 +53,12 @@ class WriteScalaApiImpl(@Nonnull service: WriteService, @Nonnull options: Influx
53
53
* @param org Specifies the destination organization for writes.
54
54
* The [[com.influxdb.client.InfluxDBClientOptions#getOrg ]] will be used as the destination `organization`
55
55
* if the `org` is not specified.
56
- * @return the sink that accept the record specified in InfluxDB Line Protocol. The `record` is considered as one batch unit.
56
+ * @return the sink that accept the record specified in InfluxDB Line Protocol.
57
57
*/
58
58
override def writeRecord (precision : Option [WritePrecision ], bucket : Option [String ], org : Option [String ]): Sink [String , Future [Done ]] = {
59
59
Flow [String ]
60
60
.map(record => Seq (new AbstractWriteClient .BatchWriteDataRecord (record)))
61
- .map(batch => writeHttp(precision, bucket, org, batch))
62
- .toMat(Sink .head)(Keep .right)
61
+ .toMat(Sink .foreach(batch => writeHttp(precision, bucket, org, batch)))(Keep .right)
63
62
}
64
63
65
64
/**
@@ -83,13 +82,12 @@ class WriteScalaApiImpl(@Nonnull service: WriteService, @Nonnull options: Influx
83
82
* Write Line Protocol records into specified bucket.
84
83
*
85
84
* @param parameters specify InfluxDB Write endpoint parameters
86
- * @return the sink that accept the records specified in InfluxDB Line Protocol. The `records` are considered as one batch unit.
85
+ * @return the sink that accept the records specified in InfluxDB Line Protocol.
87
86
*/
88
87
override def writeRecords (parameters : WriteParameters ): Sink [Seq [String ], Future [Done ]] = {
89
88
Flow [Seq [String ]]
90
89
.map(records => records.map(record => new AbstractWriteClient .BatchWriteDataRecord (record)))
91
- .map(batch => writeHttp(parameters, batch))
92
- .toMat(Sink .head)(Keep .right)
90
+ .toMat(Sink .foreach(batch => writeHttp(parameters, batch)))(Keep .right)
93
91
}
94
92
95
93
/**
@@ -101,13 +99,12 @@ class WriteScalaApiImpl(@Nonnull service: WriteService, @Nonnull options: Influx
101
99
* @param org Specifies the destination organization for writes.
102
100
* The [[com.influxdb.client.InfluxDBClientOptions#getOrg ]] will be used as the destination `organization`
103
101
* if the `org` is not specified.
104
- * @return the sink that accept the Data points. The `point` is considered as one batch unit.
102
+ * @return the sink that accept the Data points.
105
103
*/
106
104
override def writePoint (bucket : Option [String ], org : Option [String ]): Sink [Point , Future [Done ]] = {
107
105
Flow [Point ]
108
106
.map(point => (point.getPrecision, Seq (new AbstractWriteClient .BatchWriteDataPoint (point, options))))
109
- .map(batch => writeHttp(Some (batch._1), bucket, org, batch._2))
110
- .toMat(Sink .head)(Keep .right)
107
+ .toMat(Sink .foreach(batch => writeHttp(Some (batch._1), bucket, org, batch._2)))(Keep .right)
111
108
}
112
109
113
110
/**
@@ -119,7 +116,7 @@ class WriteScalaApiImpl(@Nonnull service: WriteService, @Nonnull options: Influx
119
116
* @param org Specifies the destination organization for writes.
120
117
* The [[com.influxdb.client.InfluxDBClientOptions#getOrg ]] will be used as the destination `organization`
121
118
* if the `org` is not specified.
122
- * @return the sink that accept the Data points. The `points` are considered as one batch unit.
119
+ * @return the sink that accept the Data points.
123
120
*/
124
121
override def writePoints (bucket : Option [String ], org : Option [String ]): Sink [Seq [Point ], Future [Done ]] = {
125
122
writePoints(new WriteParameters (bucket.orNull, org.orNull, null , null ))
@@ -129,7 +126,7 @@ class WriteScalaApiImpl(@Nonnull service: WriteService, @Nonnull options: Influx
129
126
* Write Data points into specified bucket.
130
127
*
131
128
* @param parameters specify InfluxDB Write endpoint parameters
132
- * @return the sink that accept the Data points. The `points` are considered as one batch unit.
129
+ * @return the sink that accept the Data points.
133
130
*/
134
131
override def writePoints (parameters : WriteParameters ): Sink [Seq [Point ], Future [Done ]] = {
135
132
Flow [Seq [Point ]]
@@ -138,9 +135,8 @@ class WriteScalaApiImpl(@Nonnull service: WriteService, @Nonnull options: Influx
138
135
case (point, map) => map.updated(point.getPrecision, point +: map.getOrElse(point.getPrecision, Seq ()))
139
136
}.toList.reverse)
140
137
.map(grouped => grouped.map(group => (group._1, group._2.map(point => new AbstractWriteClient .BatchWriteDataPoint (point, options)))))
141
- .map(batches => batches.foreach(batch => writeHttp(parameters.copy(batch._1, options), batch._2)))
142
- .map(_ => Done .done())
143
- .toMat(Sink .head)(Keep .right)
138
+ .flatMapConcat(batches => Source (batches))
139
+ .toMat(Sink .foreach(batch => writeHttp(parameters.copy(batch._1, options), batch._2)))(Keep .right)
144
140
}
145
141
146
142
/**
@@ -155,16 +151,15 @@ class WriteScalaApiImpl(@Nonnull service: WriteService, @Nonnull options: Influx
155
151
* The [[com.influxdb.client.InfluxDBClientOptions#getOrg ]] will be used as the destination `organization`
156
152
* if the `org` is not specified.
157
153
* @tparam M the type of the measurement (POJO)
158
- * @return the sink that accept the measurement. The `measurement` is considered as one batch unit.
154
+ * @return the sink that accept the measurement.
159
155
*/
160
156
override def writeMeasurement [M ](precision : Option [WritePrecision ], bucket : Option [String ], org : Option [String ]): Sink [M , Future [Done ]] = {
161
157
Flow [M ]
162
158
.map(measurement => {
163
159
val parameters = toWriteParameters(precision, bucket, org)
164
160
Seq (toMeasurementBatch(measurement, parameters.precisionSafe(options)))
165
161
})
166
- .map(batch => writeHttp(precision, bucket, org, batch))
167
- .toMat(Sink .head)(Keep .right)
162
+ .toMat(Sink .foreach(batch => writeHttp(precision, bucket, org, batch)))(Keep .right)
168
163
}
169
164
170
165
/**
@@ -179,7 +174,7 @@ class WriteScalaApiImpl(@Nonnull service: WriteService, @Nonnull options: Influx
179
174
* The [[com.influxdb.client.InfluxDBClientOptions#getOrg ]] will be used as the destination `organization`
180
175
* if the `org` is not specified.
181
176
* @tparam M the type of the measurement (POJO)
182
- * @return the sink that accept the measurements. The `measurements` are considered as one batch unit.
177
+ * @return the sink that accept the measurements.
183
178
*/
184
179
override def writeMeasurements [M ](precision : Option [WritePrecision ], bucket : Option [String ], org : Option [String ]): Sink [Seq [M ], Future [Done ]] = {
185
180
writeMeasurements(toWriteParameters(precision, bucket, org))
@@ -190,13 +185,12 @@ class WriteScalaApiImpl(@Nonnull service: WriteService, @Nonnull options: Influx
190
185
*
191
186
* @param parameters specify InfluxDB Write endpoint parameters
192
187
* @tparam M the type of the measurement (POJO)
193
- * @return the sink that accept the measurements. The `measurements` are considered as one batch unit.
188
+ * @return the sink that accept the measurements.
194
189
*/
195
190
override def writeMeasurements [M ](parameters : WriteParameters ): Sink [Seq [M ], Future [Done ]] = {
196
191
Flow [Seq [M ]]
197
192
.map(records => records.map(record => toMeasurementBatch(record, parameters.precisionSafe(options))))
198
- .map(batch => writeHttp(parameters, batch))
199
- .toMat(Sink .head)(Keep .right)
193
+ .toMat(Sink .foreach(batch => writeHttp(parameters, batch)))(Keep .right)
200
194
}
201
195
202
196
private def writeHttp (precision : Option [WritePrecision ], bucket : Option [String ], org : Option [String ], batch : Seq [AbstractWriteClient .BatchWriteData ]): Done = {
0 commit comments