|
| 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