@@ -358,13 +358,13 @@ public static PrimitiveValue newTimestamp(Instant value) {
358
358
}
359
359
360
360
public static PrimitiveValue newTimestamp64 (long microsSinceEpoch ) {
361
- return new InstantValue (PrimitiveType .Timestamp , microsSinceEpoch );
361
+ return new InstantValue (PrimitiveType .Timestamp64 , microsSinceEpoch );
362
362
}
363
363
364
364
public static PrimitiveValue newTimestamp64 (Instant value ) {
365
365
long micros = TimeUnit .SECONDS .toMicros (value .getEpochSecond ()) +
366
366
TimeUnit .NANOSECONDS .toMicros (value .getNano ());
367
- return new InstantValue (PrimitiveType .Timestamp , micros );
367
+ return new InstantValue (PrimitiveType .Timestamp64 , micros );
368
368
}
369
369
370
370
public static PrimitiveValue newInterval (long micros ) {
@@ -380,7 +380,7 @@ public static PrimitiveValue newInterval64(long micros) {
380
380
}
381
381
382
382
public static PrimitiveValue newInterval64 (Duration value ) {
383
- return newInterval (TimeUnit .NANOSECONDS .toMicros (value .toNanos ()));
383
+ return newInterval64 (TimeUnit .NANOSECONDS .toMicros (value .toNanos ()));
384
384
}
385
385
386
386
public static PrimitiveValue newTzDate (ZonedDateTime dateTime ) {
@@ -1018,8 +1018,8 @@ public int hashCode() {
1018
1018
@ Override
1019
1019
public String toString () {
1020
1020
final int length = (value instanceof byte [])
1021
- ? ((byte []) value ).length
1022
- : ((ByteString ) value ).size ();
1021
+ ? ((byte []) value ).length
1022
+ : ((ByteString ) value ).size ();
1023
1023
1024
1024
if (length == 0 ) {
1025
1025
return "\" \" " ;
@@ -1094,9 +1094,9 @@ private static final class Text extends PrimitiveValue {
1094
1094
private static final Text EMPTY_JSON_DOCUMENT = new Text (PrimitiveType .JsonDocument , "" );
1095
1095
1096
1096
private static final Escaper ESCAPER = Escapers .builder ()
1097
- .addEscape ('\\' , "\\ \\ " )
1098
- .addEscape ('\"' , "\\ \" " )
1099
- .build ();
1097
+ .addEscape ('\\' , "\\ \\ " )
1098
+ .addEscape ('\"' , "\\ \" " )
1099
+ .build ();
1100
1100
1101
1101
private final PrimitiveType type ;
1102
1102
private final String value ;
@@ -1198,6 +1198,24 @@ public Instant getTimestamp() {
1198
1198
return ProtoValue .toTimestamp (microsSinceEpoch );
1199
1199
}
1200
1200
1201
+ @ Override
1202
+ public LocalDate getDate32 () {
1203
+ checkType (PrimitiveType .Date32 , type );
1204
+ return ProtoValue .toDate32 (TimeUnit .MICROSECONDS .toDays (microsSinceEpoch ));
1205
+ }
1206
+
1207
+ @ Override
1208
+ public LocalDateTime getDatetime64 () {
1209
+ checkType (PrimitiveType .Datetime64 , type );
1210
+ return ProtoValue .toDatetime64 (TimeUnit .MICROSECONDS .toSeconds (microsSinceEpoch ));
1211
+ }
1212
+
1213
+ @ Override
1214
+ public Instant getTimestamp64 () {
1215
+ checkType (PrimitiveType .Timestamp64 , type );
1216
+ return ProtoValue .toTimestamp64 (microsSinceEpoch );
1217
+ }
1218
+
1201
1219
@ Override
1202
1220
public boolean equals (Object o ) {
1203
1221
if (this == o ) {
@@ -1220,9 +1238,18 @@ public int hashCode() {
1220
1238
@ Override
1221
1239
public String toString () {
1222
1240
switch (type ) {
1223
- case Date : return DateTimeFormatter .ISO_DATE .format (getDate ());
1224
- case Datetime : return DateTimeFormatter .ISO_DATE_TIME .format (getDatetime ());
1225
- case Timestamp : return DateTimeFormatter .ISO_INSTANT .format (getTimestamp ());
1241
+ case Date :
1242
+ return DateTimeFormatter .ISO_DATE .format (getDate ());
1243
+ case Datetime :
1244
+ return DateTimeFormatter .ISO_DATE_TIME .format (getDatetime ());
1245
+ case Timestamp :
1246
+ return DateTimeFormatter .ISO_INSTANT .format (getTimestamp ());
1247
+ case Date32 :
1248
+ return DateTimeFormatter .ISO_DATE .format (getDate32 ());
1249
+ case Datetime64 :
1250
+ return DateTimeFormatter .ISO_DATE_TIME .format (getDatetime64 ());
1251
+ case Timestamp64 :
1252
+ return DateTimeFormatter .ISO_INSTANT .format (getTimestamp64 ());
1226
1253
default :
1227
1254
throw new IllegalStateException ("unsupported type: " + type );
1228
1255
}
@@ -1231,32 +1258,48 @@ public String toString() {
1231
1258
@ Override
1232
1259
public ValueProtos .Value toPb () {
1233
1260
switch (type ) {
1234
- case Date : return ProtoValue .fromDate (TimeUnit .MICROSECONDS .toDays (microsSinceEpoch ));
1235
- case Datetime : return ProtoValue .fromDatetime (TimeUnit .MICROSECONDS .toSeconds (microsSinceEpoch ));
1236
- case Timestamp : return ProtoValue .fromTimestamp (microsSinceEpoch );
1261
+ case Date :
1262
+ return ProtoValue .fromDate (TimeUnit .MICROSECONDS .toDays (microsSinceEpoch ));
1263
+ case Datetime :
1264
+ return ProtoValue .fromDatetime (TimeUnit .MICROSECONDS .toSeconds (microsSinceEpoch ));
1265
+ case Timestamp :
1266
+ return ProtoValue .fromTimestamp (microsSinceEpoch );
1267
+ case Date32 :
1268
+ return ProtoValue .fromDate32 (TimeUnit .MICROSECONDS .toDays (microsSinceEpoch ));
1269
+ case Datetime64 :
1270
+ return ProtoValue .fromDatetime64 (TimeUnit .MICROSECONDS .toSeconds (microsSinceEpoch ));
1271
+ case Timestamp64 :
1272
+ return ProtoValue .fromTimestamp64 (microsSinceEpoch );
1237
1273
default :
1238
1274
throw new IllegalStateException ("unsupported type: " + type );
1239
1275
}
1240
1276
}
1241
1277
}
1242
1278
1243
1279
private static final class IntervalValue extends PrimitiveValue {
1280
+ private final PrimitiveType type ;
1244
1281
private final long micros ;
1245
1282
1246
- IntervalValue (long micros ) {
1283
+ IntervalValue (PrimitiveType type , long micros ) {
1284
+ this .type = type ;
1247
1285
this .micros = micros ;
1248
1286
}
1249
1287
1250
1288
@ Override
1251
1289
public PrimitiveType getType () {
1252
- return PrimitiveType . Interval ;
1290
+ return type ;
1253
1291
}
1254
1292
1255
1293
@ Override
1256
1294
public Duration getInterval () {
1257
1295
return Duration .of (micros , ChronoUnit .MICROS );
1258
1296
}
1259
1297
1298
+ @ Override
1299
+ public Duration getInterval64 () {
1300
+ return Duration .of (micros , ChronoUnit .MICROS );
1301
+ }
1302
+
1260
1303
@ Override
1261
1304
public boolean equals (Object o ) {
1262
1305
if (this == o ) {
@@ -1278,12 +1321,26 @@ public int hashCode() {
1278
1321
1279
1322
@ Override
1280
1323
public String toString () {
1281
- return getInterval ().toString ();
1324
+ switch (type ) {
1325
+ case Interval :
1326
+ return getInterval ().toString ();
1327
+ case Interval64 :
1328
+ return getInterval64 ().toString ();
1329
+ default :
1330
+ throw new IllegalStateException ("unsupported type: " + type );
1331
+ }
1282
1332
}
1283
1333
1284
1334
@ Override
1285
1335
public ValueProtos .Value toPb () {
1286
- return ProtoValue .fromInterval (micros );
1336
+ switch (type ) {
1337
+ case Interval :
1338
+ return ProtoValue .fromInterval (micros );
1339
+ case Interval64 :
1340
+ return ProtoValue .fromInterval64 (micros );
1341
+ default :
1342
+ throw new IllegalStateException ("unsupported type: " + type );
1343
+ }
1287
1344
}
1288
1345
}
1289
1346
@@ -1343,8 +1400,8 @@ public int hashCode() {
1343
1400
@ Override
1344
1401
public String toString () {
1345
1402
String timeStr = (type == PrimitiveType .TzDate )
1346
- ? dateTime .toLocalDate ().toString ()
1347
- : dateTime .toLocalDateTime ().toString ();
1403
+ ? dateTime .toLocalDate ().toString ()
1404
+ : dateTime .toLocalDateTime ().toString ();
1348
1405
1349
1406
return timeStr + ',' + dateTime .getZone ().getId ();
1350
1407
}
0 commit comments