Skip to content

Commit f09decb

Browse files
authored
Add toString() support for all datum types #1553 (#1802)
1 parent 46d05e3 commit f09decb

30 files changed

+714
-38
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ rewritten to their query representation
3939
- `ABS` function support on `INTERVAL` values
4040
- Support for `OVERLAPS` predicate
4141
- Add cli option -e to load PartiQL literal data as default catalog data
42+
- Add toString() support for all datum types
4243

4344
### Changed
4445

buildSrc/src/main/kotlin/partiql.versions.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ object Versions {
5353
const val junit4 = "4.12"
5454
const val junit4Params = "1.1.1"
5555
const val mockito = "4.5.0"
56+
const val snapshotTest = "4.0.8"
57+
const val slf4j = "2.0.17"
5658
}
5759

5860
object Deps {
@@ -96,6 +98,8 @@ object Deps {
9698
const val kotlinTestJunit = "org.jetbrains.kotlin:kotlin-test-junit5:${Versions.kotlin}"
9799
const val mockito = "org.mockito:mockito-junit-jupiter:${Versions.mockito}"
98100
const val ktlintTest = "com.pinterest.ktlint:ktlint-test:${Versions.ktlint}"
101+
const val snapshotTest = "io.github.origin-energy:java-snapshot-testing-junit5:${Versions.snapshotTest}"
102+
const val slf4j = "org.slf4j:slf4j-simple:${Versions.slf4j}"
99103
}
100104

101105
object Plugins {

partiql-spi/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ dependencies {
2323
api(Deps.ionElement)
2424
implementation(Deps.kotlinxCollections)
2525
testImplementation(Deps.kasechange)
26+
testImplementation(Deps.snapshotTest)
27+
testImplementation(Deps.slf4j)
2628
}
2729

2830
tasks.shadowJar {

partiql-spi/src/main/java/org/partiql/spi/value/DatumBoolean.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,12 @@ public boolean getBoolean() {
2626
public PType getType() {
2727
return _type;
2828
}
29+
30+
@Override
31+
public String toString() {
32+
return "DatumBoolean{" +
33+
"_type=" + _type +
34+
", _value=" + _value +
35+
'}';
36+
}
2937
}

partiql-spi/src/main/java/org/partiql/spi/value/DatumByte.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.partiql.spi.value;
22

3+
import kotlin.text.HexFormat;
34
import org.jetbrains.annotations.NotNull;
45
import org.partiql.spi.types.PType;
56

@@ -31,4 +32,13 @@ public byte getByte() {
3132
public PType getType() {
3233
return _type;
3334
}
35+
36+
@Override
37+
public String toString() {
38+
39+
return "DatumByte{" +
40+
"_type=" + _type +
41+
", _value=" + _value +
42+
'}';
43+
}
3444
}

partiql-spi/src/main/java/org/partiql/spi/value/DatumBytes.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import org.jetbrains.annotations.NotNull;
44
import org.partiql.spi.types.PType;
55

6+
import java.util.StringJoiner;
7+
68
/**
79
* This shall always be package-private (internal).
810
* <p></p>
@@ -34,4 +36,18 @@ public byte[] getBytes() {
3436
public PType getType() {
3537
return _type;
3638
}
39+
40+
@Override
41+
public String toString() {
42+
StringJoiner joiner = new StringJoiner(", ", "[", "]");
43+
for (byte b : _value) {
44+
joiner.add(Byte.toString(b));
45+
}
46+
47+
return "DatumBytes{" +
48+
"_type=" + _type +
49+
", _value=" + joiner +
50+
'}';
51+
52+
}
3753
}

partiql-spi/src/main/java/org/partiql/spi/value/DatumChars.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,12 @@ public String getString() {
3030
public PType getType() {
3131
return _type;
3232
}
33+
34+
@Override
35+
public String toString() {
36+
return "DatumChars{" +
37+
"_type=" + _type +
38+
", _value=" + _value +
39+
'}';
40+
}
3341
}

partiql-spi/src/main/java/org/partiql/spi/value/DatumCollection.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import org.partiql.spi.types.PType;
55

66
import java.util.Iterator;
7+
import java.util.List;
8+
import java.util.Map;
9+
import java.util.StringJoiner;
710

811
/**
912
* This shall always be package-private (internal).
@@ -41,7 +44,7 @@ public PType getType() {
4144
public String toString() {
4245
return "DatumCollection{" +
4346
"_type=" + _type +
44-
", _value=" + _value +
47+
", _value=" + DatumUtils.formatListToString(_value) +
4548
'}';
4649
}
4750
}

partiql-spi/src/main/java/org/partiql/spi/value/DatumDate.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public LocalDate getLocalDate() {
3535

3636
@Override
3737
public String toString() {
38-
return this.value.toString();
38+
return "DatumDate{" +
39+
"_type=" + type +
40+
", _value=" + value +
41+
'}';
3942
}
4043
}

partiql-spi/src/main/java/org/partiql/spi/value/DatumDecimal.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public int hashCode() {
5454
@Override
5555
public String toString() {
5656
return "DatumDecimal{" +
57-
"_value=" + _value +
58-
", _type=" + _type +
57+
"_type=" + _type +
58+
", _value=" + _value +
5959
'}';
6060
}
6161
}

0 commit comments

Comments
 (0)