xtern commented on code in PR #3627:
URL: https://github.com/apache/ignite-3/pull/3627#discussion_r1572234538
##########
modules/catalog/src/test/java/org/apache/ignite/internal/catalog/storage/CatalogEntrySerializationTest.java:
##########
@@ -144,6 +174,85 @@ void test(MarshallableEntryType type) {
}
}
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("values")
+ public void constantDefault(ColumnType columnType, Object value) throws
IOException {
+ ConstantValue val = (ConstantValue) DefaultValue.constant(value);
+
+ log.info("{}: {}", columnType, value);
+
+ try (IgniteUnsafeDataOutput os = new IgniteUnsafeDataOutput(128)) {
+ DefaultValue.writeTo(val, os);
+
+ try (IgniteUnsafeDataInput in = new
IgniteUnsafeDataInput(os.internalArray())) {
+ DefaultValue actual = DefaultValue.readFrom(in);
+ assertEquals(val, actual);
+ }
+ }
+ }
+
+ private static Stream<Arguments> values() {
+ List<Object> list = new ArrayList<>();
+
+ list.add(null);
+ list.add(RND.nextBoolean());
+
+ list.add((byte) RND.nextInt());
+ list.add((short) RND.nextInt());
+ list.add(RND.nextInt());
+ list.add(RND.nextLong());
+ list.add((float) RND.nextDouble());
+ list.add(RND.nextDouble());
+
+ list.add(BigDecimal.valueOf(RND.nextLong()));
+ list.add(BigDecimal.valueOf(RND.nextLong(), RND.nextInt(100)));
+
+ list.add(BigInteger.valueOf(RND.nextLong()));
+
+ list.add(LocalTime.of(RND.nextInt(24), RND.nextInt(60),
RND.nextInt(60), RND.nextInt(100_000)));
+ list.add(LocalDate.of(RND.nextInt(4000) - 1000, RND.nextInt(12) + 1,
RND.nextInt(27) + 1));
+ list.add(LocalDateTime.of(
+ LocalDate.of(RND.nextInt(4000) - 1000, RND.nextInt(12) + 1,
RND.nextInt(27) + 1),
+ LocalTime.of(RND.nextInt(24), RND.nextInt(60),
RND.nextInt(60), RND.nextInt(100_000))
+ ));
+
+ byte[] bytes = new byte[RND.nextInt(1000)];
+ RND.nextBytes(bytes);
+ list.add(Base64.getEncoder().encodeToString(bytes));
+
+ list.add(UUID.randomUUID());
+
+ // TODO Include ignored values to test after
https://issues.apache.org/jira/browse/IGNITE-15200
+ // list.add(Duration.of(11, ChronoUnit.HOURS));
+ // list.add(Period.of(5, 4, 3));
+
+ BitSet bitSet = new BitSet();
+ for (int i = 0; i < RND.nextInt(100); i++) {
+ int b = RND.nextInt(1024);
+ bitSet.set(b);
+ }
+ list.add(bitSet);
+
+ return list.stream().map(val -> {
+ NativeType nativeType = NativeTypes.fromObject(val);
+ return Arguments.of(nativeType == null ? ColumnType.NULL :
nativeType.spec().asColumnType(), val);
+ });
+ }
+
+ @Test
+ public void functionCallDefault() throws IOException{
Review Comment:
Actually, such tests already exist (for example in `checkAlterColumnEntry`).
If you prefer to keep this test separate, I also suggest renaming it with a
"test" prefix :thinking:
##########
modules/catalog/src/test/java/org/apache/ignite/internal/catalog/storage/CatalogEntrySerializationTest.java:
##########
@@ -144,6 +174,85 @@ void test(MarshallableEntryType type) {
}
}
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("values")
+ public void constantDefault(ColumnType columnType, Object value) throws
IOException {
Review Comment:
```suggestion
public void testConstantDefaultAllTypes(ColumnType columnType, Object
value) throws IOException {
```
##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/DefaultValue.java:
##########
@@ -68,9 +92,25 @@ public Type type() {
return type;
}
+ /** Reads default value or {@code null}. */
+ public static @Nullable DefaultValue readFrom(IgniteDataInput in) throws
IOException {
Review Comment:
I suggest moving this method below just before `writeTo()`..
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]