2121 */
2222package com .influxdb .v3 .client .internal ;
2323
24- import java .time .Instant ;
2524import java .time .LocalDateTime ;
26- import java .time .ZoneOffset ;
2725import java .util .List ;
2826import java .util .Objects ;
29- import java .util .concurrent .TimeUnit ;
3027import javax .annotation .Nonnull ;
3128import javax .annotation .concurrent .ThreadSafe ;
3229
3330import org .apache .arrow .vector .FieldVector ;
3431import org .apache .arrow .vector .VectorSchemaRoot ;
35- import org .apache .arrow .vector .types .pojo .ArrowType ;
36- import org .apache .arrow .vector .types .pojo .Field ;
3732import org .apache .arrow .vector .util .Text ;
3833
3934import com .influxdb .v3 .client .PointValues ;
35+ import com .influxdb .v3 .client .write .WritePrecision ;
4036
4137
4238/**
@@ -82,7 +78,8 @@ PointValues toPointValues(final int rowNumber,
8278
8379 if (metaType == null ) {
8480 if (Objects .equals (name , "time" ) && (value instanceof Long || value instanceof LocalDateTime )) {
85- setTimestamp (value , schema , p );
81+ var timeNano = NanosecondConverter .getTimestampNano (value , schema );
82+ p .setTimestamp (timeNano , WritePrecision .NS );
8683 } else {
8784 // just push as field If you don't know what type is it
8885 p .setField (name , value );
@@ -99,7 +96,8 @@ PointValues toPointValues(final int rowNumber,
9996 } else if ("tag" .equals (valueType ) && value instanceof String ) {
10097 p .setTag (name , (String ) value );
10198 } else if ("timestamp" .equals (valueType )) {
102- setTimestamp (value , schema , p );
99+ var timeNano = NanosecondConverter .getTimestampNano (value , schema );
100+ p .setTimestamp (timeNano , WritePrecision .NS );
103101 }
104102 }
105103 return p ;
@@ -128,38 +126,8 @@ private void setFieldWithMetaType(final PointValues p,
128126 p .setBooleanField (name , (Boolean ) value );
129127 break ;
130128 default :
131- }
132- }
133-
134- private void setTimestamp (@ Nonnull final Object value ,
135- @ Nonnull final Field schema ,
136- @ Nonnull final PointValues pointValues ) {
137- if (value instanceof Long ) {
138- if (schema .getFieldType ().getType () instanceof ArrowType .Timestamp ) {
139- ArrowType .Timestamp type = (ArrowType .Timestamp ) schema .getFieldType ().getType ();
140- TimeUnit timeUnit ;
141- switch (type .getUnit ()) {
142- case SECOND :
143- timeUnit = TimeUnit .SECONDS ;
144- break ;
145- case MILLISECOND :
146- timeUnit = TimeUnit .MILLISECONDS ;
147- break ;
148- case MICROSECOND :
149- timeUnit = TimeUnit .MICROSECONDS ;
150- break ;
151- default :
152- case NANOSECOND :
153- timeUnit = TimeUnit .NANOSECONDS ;
154- break ;
155- }
156- long nanoseconds = TimeUnit .NANOSECONDS .convert ((Long ) value , timeUnit );
157- pointValues .setTimestamp (Instant .ofEpochSecond (0 , nanoseconds ));
158- } else {
159- pointValues .setTimestamp (Instant .ofEpochMilli ((Long ) value ));
160- }
161- } else if (value instanceof LocalDateTime ) {
162- pointValues .setTimestamp (((LocalDateTime ) value ).toInstant (ZoneOffset .UTC ));
129+ p .setField (name , value );
130+ break ;
163131 }
164132 }
165133}
0 commit comments