@@ -28,11 +28,11 @@ import com.influxdb.client.internal.AbstractWriteClient
28
28
import com.influxdb.client.kotlin.WriteKotlinApi
29
29
import com.influxdb.client.service.WriteService
30
30
import com.influxdb.client.write.Point
31
+ import com.influxdb.client.write.WriteParameters
31
32
import kotlinx.coroutines.flow.Flow
32
33
import kotlinx.coroutines.flow.asFlow
33
34
import kotlinx.coroutines.flow.map
34
35
import kotlinx.coroutines.flow.toList
35
- import java.util.*
36
36
37
37
/* *
38
38
* @author Jakub Bednar (20/04/2021 9:27)
@@ -58,6 +58,10 @@ internal class WriteKotlinApiImpl(service: WriteService, options: InfluxDBClient
58
58
write(records.map { AbstractWriteClient .BatchWriteDataRecord (it) }, precision, bucket, org)
59
59
}
60
60
61
+ override suspend fun writeRecords (records : Flow <String >, parameters : WriteParameters ) {
62
+ write(records.map { AbstractWriteClient .BatchWriteDataRecord (it) }, parameters)
63
+ }
64
+
61
65
override suspend fun writePoint (point : Point , bucket : String? , org : String? ) {
62
66
writePoints(listOf (point), bucket, org)
63
67
}
@@ -67,15 +71,17 @@ internal class WriteKotlinApiImpl(service: WriteService, options: InfluxDBClient
67
71
}
68
72
69
73
override suspend fun writePoints (points : Flow <Point >, bucket : String? , org : String? ) {
74
+ writePoints(points, WriteParameters (bucket, org, options.precision, options.consistency))
75
+ }
76
+
77
+ override suspend fun writePoints (points : Flow <Point >, parameters : WriteParameters ) {
70
78
points
71
79
.toList()
72
80
.groupByTo(LinkedHashMap (), { it.precision }, { it })
73
81
.forEach { group ->
74
82
write(
75
83
group.value.asFlow().map { AbstractWriteClient .BatchWriteDataPoint (it, options) },
76
- group.key,
77
- bucket,
78
- org
84
+ parameters.copy(group.key, options)
79
85
)
80
86
}
81
87
}
@@ -107,6 +113,10 @@ internal class WriteKotlinApiImpl(service: WriteService, options: InfluxDBClient
107
113
write(measurements.map { toMeasurementBatch(it, precision) }, precision, bucket, org)
108
114
}
109
115
116
+ override suspend fun <M > writeMeasurements (measurements : Flow <M >, parameters : WriteParameters ) {
117
+ write(measurements.map { toMeasurementBatch(it, parameters.precisionSafe(options)) }, parameters)
118
+ }
119
+
110
120
private suspend fun write (
111
121
records : Flow <AbstractWriteClient .BatchWriteData >,
112
122
precision : WritePrecision ,
@@ -117,7 +127,15 @@ internal class WriteKotlinApiImpl(service: WriteService, options: InfluxDBClient
117
127
val bucketOrOption = bucket ? : options.bucket.orEmpty()
118
128
val orgOrOption = org ? : options.org.orEmpty()
119
129
120
- write(bucketOrOption, orgOrOption, precision, records.toList().stream())
130
+ write(records, WriteParameters (bucketOrOption, orgOrOption, precision))
131
+ }
132
+
133
+ private suspend fun write (
134
+ records : Flow <AbstractWriteClient .BatchWriteData >,
135
+ parameters : WriteParameters
136
+ ) {
137
+
138
+ write(parameters, records.toList().stream())
121
139
}
122
140
}
123
141
0 commit comments