Skip to content

Commit e6f38cc

Browse files
wip
1 parent 465187a commit e6f38cc

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

src/main/java/com/influxdb/v3/client/internal/InfluxDBClientImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public Stream<Object[]> query(@Nonnull final String query,
221221
} else if ("timestamp".equals(valueType)
222222
|| Objects.equals(schema.getName(), "time")) {
223223
var timestamp = fieldVectors.get(i).getObject(rowNumber);
224-
BigInteger time = NanosecondConverter.getTimestamp(timestamp, schema);
224+
BigInteger time = NanosecondConverter.getTimestampNanoSecond(timestamp, schema);
225225
row.add(time);
226226
} else {
227227
Object value = fieldVectors.get(i).getObject(rowNumber);

src/main/java/com/influxdb/v3/client/internal/NanosecondConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public static BigInteger convert(final Instant instant, final WritePrecision pre
119119
return FROM_NANOS.get(precision).apply(nanos);
120120
}
121121

122-
public static BigInteger getTimestamp(@Nonnull final Object value, @Nonnull final Field schema) {
122+
public static BigInteger getTimestampNanoSecond(@Nonnull final Object value, @Nonnull final Field schema) {
123123
BigInteger result = null;
124124

125125
if (value instanceof Long) {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.influxdb.v3.client.internal;
2+
3+
import java.math.BigInteger;
4+
5+
import org.apache.arrow.vector.types.TimeUnit;
6+
import org.apache.arrow.vector.types.pojo.ArrowType;
7+
import org.apache.arrow.vector.types.pojo.Field;
8+
import org.apache.arrow.vector.types.pojo.FieldType;
9+
import org.junit.jupiter.api.Assertions;
10+
import org.junit.jupiter.api.Test;
11+
12+
public class NanosecondConverterTest {
13+
14+
@Test
15+
void testGetTimestampNanosecond() {
16+
BigInteger timestampNanoSecond = null;
17+
18+
// Second
19+
FieldType timeTypeSecond = new FieldType(true,
20+
new ArrowType.Timestamp(TimeUnit.SECOND, "UTC"),
21+
null);
22+
Field timeFieldSecond = new Field("time", timeTypeSecond, null);
23+
timestampNanoSecond = NanosecondConverter.getTimestampNanoSecond(123_456L, timeFieldSecond);
24+
Assertions.assertEquals(
25+
BigInteger.valueOf(123_456L)
26+
.multiply(BigInteger.valueOf(1_000_000_000)), timestampNanoSecond
27+
);
28+
29+
// MilliSecond
30+
FieldType timeTypeMilliSecond = new FieldType(true,
31+
new ArrowType.Timestamp(TimeUnit.MILLISECOND, "UTC"),
32+
null);
33+
Field timeFieldMilliSecond = new Field("time", timeTypeMilliSecond, null);
34+
timestampNanoSecond = NanosecondConverter.getTimestampNanoSecond(123_456L, timeFieldMilliSecond);
35+
Assertions.assertEquals(
36+
BigInteger.valueOf(123_456L)
37+
.multiply(BigInteger.valueOf(1_000_000)), timestampNanoSecond
38+
);
39+
40+
// MicroSecond
41+
FieldType timeTypeMicroSecond = new FieldType(true,
42+
new ArrowType.Timestamp(TimeUnit.MICROSECOND, "UTC"),
43+
null);
44+
Field timeFieldMicroSecond = new Field("time", timeTypeMicroSecond, null);
45+
timestampNanoSecond = NanosecondConverter.getTimestampNanoSecond(123_456L, timeFieldMicroSecond);
46+
Assertions.assertEquals(
47+
BigInteger.valueOf(123_456L)
48+
.multiply(BigInteger.valueOf(1_000)), timestampNanoSecond
49+
);
50+
51+
// Nano Second
52+
FieldType timeTypeNanoSecond = new FieldType(true,
53+
new ArrowType.Timestamp(TimeUnit.NANOSECOND, "UTC"),
54+
null);
55+
Field timeFieldNanoSecond = new Field("time", timeTypeNanoSecond, null);
56+
timestampNanoSecond = NanosecondConverter.getTimestampNanoSecond(123_456L, timeFieldNanoSecond);
57+
Assertions.assertEquals(BigInteger.valueOf(123_456L), timestampNanoSecond
58+
);
59+
}
60+
}

0 commit comments

Comments
 (0)