Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7abfedc

Browse files
committedJan 17, 2025·
rebase branch
1 parent b437917 commit 7abfedc

File tree

3 files changed

+95
-24
lines changed

3 files changed

+95
-24
lines changed
 

Diff for: ‎query/pom.xml

+16
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,20 @@
3636
<scope>test</scope>
3737
</dependency>
3838
</dependencies>
39+
40+
<build>
41+
<plugins>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-surefire-plugin</artifactId>
45+
<version>3.1.0</version>
46+
<configuration>
47+
<environmentVariables>
48+
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>
49+
<YDB_DOCKER_IMAGE>ydbplatform/local-ydb:trunk</YDB_DOCKER_IMAGE>
50+
</environmentVariables>
51+
</configuration>
52+
</plugin>
53+
</plugins>
54+
</build>
3955
</project>

Diff for: ‎table/src/main/java/tech/ydb/table/values/PrimitiveValue.java

+77-20
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,13 @@ public static PrimitiveValue newTimestamp(Instant value) {
358358
}
359359

360360
public static PrimitiveValue newTimestamp64(long microsSinceEpoch) {
361-
return new InstantValue(PrimitiveType.Timestamp, microsSinceEpoch);
361+
return new InstantValue(PrimitiveType.Timestamp64, microsSinceEpoch);
362362
}
363363

364364
public static PrimitiveValue newTimestamp64(Instant value) {
365365
long micros = TimeUnit.SECONDS.toMicros(value.getEpochSecond()) +
366366
TimeUnit.NANOSECONDS.toMicros(value.getNano());
367-
return new InstantValue(PrimitiveType.Timestamp, micros);
367+
return new InstantValue(PrimitiveType.Timestamp64, micros);
368368
}
369369

370370
public static PrimitiveValue newInterval(long micros) {
@@ -380,7 +380,7 @@ public static PrimitiveValue newInterval64(long micros) {
380380
}
381381

382382
public static PrimitiveValue newInterval64(Duration value) {
383-
return newInterval(TimeUnit.NANOSECONDS.toMicros(value.toNanos()));
383+
return newInterval64(TimeUnit.NANOSECONDS.toMicros(value.toNanos()));
384384
}
385385

386386
public static PrimitiveValue newTzDate(ZonedDateTime dateTime) {
@@ -1018,8 +1018,8 @@ public int hashCode() {
10181018
@Override
10191019
public String toString() {
10201020
final int length = (value instanceof byte[])
1021-
? ((byte[]) value).length
1022-
: ((ByteString) value).size();
1021+
? ((byte[]) value).length
1022+
: ((ByteString) value).size();
10231023

10241024
if (length == 0) {
10251025
return "\"\"";
@@ -1094,9 +1094,9 @@ private static final class Text extends PrimitiveValue {
10941094
private static final Text EMPTY_JSON_DOCUMENT = new Text(PrimitiveType.JsonDocument, "");
10951095

10961096
private static final Escaper ESCAPER = Escapers.builder()
1097-
.addEscape('\\', "\\\\")
1098-
.addEscape('\"', "\\\"")
1099-
.build();
1097+
.addEscape('\\', "\\\\")
1098+
.addEscape('\"', "\\\"")
1099+
.build();
11001100

11011101
private final PrimitiveType type;
11021102
private final String value;
@@ -1198,6 +1198,24 @@ public Instant getTimestamp() {
11981198
return ProtoValue.toTimestamp(microsSinceEpoch);
11991199
}
12001200

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+
12011219
@Override
12021220
public boolean equals(Object o) {
12031221
if (this == o) {
@@ -1220,9 +1238,18 @@ public int hashCode() {
12201238
@Override
12211239
public String toString() {
12221240
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());
12261253
default:
12271254
throw new IllegalStateException("unsupported type: " + type);
12281255
}
@@ -1231,32 +1258,48 @@ public String toString() {
12311258
@Override
12321259
public ValueProtos.Value toPb() {
12331260
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);
12371273
default:
12381274
throw new IllegalStateException("unsupported type: " + type);
12391275
}
12401276
}
12411277
}
12421278

12431279
private static final class IntervalValue extends PrimitiveValue {
1280+
private final PrimitiveType type;
12441281
private final long micros;
12451282

1246-
IntervalValue(long micros) {
1283+
IntervalValue(PrimitiveType type, long micros) {
1284+
this.type = type;
12471285
this.micros = micros;
12481286
}
12491287

12501288
@Override
12511289
public PrimitiveType getType() {
1252-
return PrimitiveType.Interval;
1290+
return type;
12531291
}
12541292

12551293
@Override
12561294
public Duration getInterval() {
12571295
return Duration.of(micros, ChronoUnit.MICROS);
12581296
}
12591297

1298+
@Override
1299+
public Duration getInterval64() {
1300+
return Duration.of(micros, ChronoUnit.MICROS);
1301+
}
1302+
12601303
@Override
12611304
public boolean equals(Object o) {
12621305
if (this == o) {
@@ -1278,12 +1321,26 @@ public int hashCode() {
12781321

12791322
@Override
12801323
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+
}
12821332
}
12831333

12841334
@Override
12851335
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+
}
12871344
}
12881345
}
12891346

@@ -1343,8 +1400,8 @@ public int hashCode() {
13431400
@Override
13441401
public String toString() {
13451402
String timeStr = (type == PrimitiveType.TzDate)
1346-
? dateTime.toLocalDate().toString()
1347-
: dateTime.toLocalDateTime().toString();
1403+
? dateTime.toLocalDate().toString()
1404+
: dateTime.toLocalDateTime().toString();
13481405

13491406
return timeStr + ',' + dateTime.getZone().getId();
13501407
}

Diff for: ‎table/src/main/java/tech/ydb/table/values/proto/ProtoValue.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,15 @@ public static LocalDate toDate(ValueProtos.Value value) {
264264
}
265265

266266
public static ValueProtos.Value fromDate32(long daysSinceEpoch) {
267-
int daysInt = (int) (daysSinceEpoch & 0xffffffffL);
268-
269-
return ValueProtos.Value.newBuilder().setInt32Value(daysInt).build();
267+
return ValueProtos.Value.newBuilder().setInt32Value((int)daysSinceEpoch).build();
270268
}
271269

272270
public static LocalDate toDate32(long daysSinceEpoch) {
273271
return LocalDate.ofEpochDay(daysSinceEpoch);
274272
}
275273

276274
public static LocalDate toDate32(ValueProtos.Value value) {
277-
return toDate(value.getInt32Value());
275+
return toDate32(value.getInt32Value());
278276
}
279277

280278
// - datetime -

0 commit comments

Comments
 (0)
Please sign in to comment.