Skip to content

Commit 16b218e

Browse files
committed
Support prepared statement
1 parent 16bfe5d commit 16b218e

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

graphmdl-base/src/main/java/io/graphmdl/base/type/IntervalType.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ public class IntervalType
6060
.appendSecondsWithOptionalMillis()
6161
.toFormatter();
6262

63+
private static final PeriodFormatter PG_INTERVAL_FORMATTER = new PeriodFormatterBuilder()
64+
.appendYears()
65+
.appendSuffix(" years ")
66+
.appendMonths()
67+
.appendSuffix(" mons ")
68+
.appendDays()
69+
.appendSuffix(" days ")
70+
.appendHours()
71+
.appendSuffix(" hours ")
72+
.appendMinutes()
73+
.appendSuffix(" mins ")
74+
.appendSecondsWithOptionalMillis()
75+
.appendSuffix(" secs")
76+
.toFormatter();
77+
6378
private IntervalType()
6479
{
6580
super(OID, TYPE_LEN, TYPE_MOD, "interval");
@@ -154,7 +169,6 @@ public byte[] encodeAsUTF8Text(@Nonnull Period value)
154169
@Override
155170
public Period decodeUTF8Text(byte[] bytes)
156171
{
157-
// return IntervalType.PERIOD_FORMATTER.parsePeriod(new String(bytes, StandardCharsets.UTF_8));
158-
return new Period(new String(bytes, StandardCharsets.UTF_8));
172+
return PG_INTERVAL_FORMATTER.parsePeriod(new String(bytes, StandardCharsets.UTF_8));
159173
}
160174
}

graphmdl-connector-client/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
<groupId>javax.ws.rs</groupId>
7979
<artifactId>javax.ws.rs-api</artifactId>
8080
</dependency>
81+
<dependency>
82+
<groupId>joda-time</groupId>
83+
<artifactId>joda-time</artifactId>
84+
</dependency>
8185
<dependency>
8286
<groupId>org.duckdb</groupId>
8387
<artifactId>duckdb_jdbc</artifactId>

graphmdl-connector-client/src/main/java/io/graphmdl/connector/bigquery/BigQueryType.java

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.graphmdl.base.type.NumericType;
2323
import io.graphmdl.base.type.PGType;
2424
import io.graphmdl.base.type.TimestampType;
25+
import org.joda.time.Period;
2526

2627
import java.util.Map;
2728
import java.util.Optional;
@@ -106,6 +107,9 @@ public static Object toBqValue(PGType<?> pgType, Object value)
106107
if (pgType.equals(SMALLINT) && value instanceof Short) {
107108
return ((Short) value).intValue();
108109
}
110+
if (pgType.equals(IntervalType.INTERVAL) && value instanceof Period) {
111+
return value.toString();
112+
}
109113
return value;
110114
}
111115
}

graphmdl-tests/src/test/java/io/graphmdl/testing/bigquery/TestWireProtocolWithBigquery.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.graphmdl.testing.TestingWireProtocolClient;
2323
import org.assertj.core.api.AssertionsForClassTypes;
2424
import org.intellij.lang.annotations.Language;
25+
import org.postgresql.util.PGInterval;
2526
import org.testng.annotations.DataProvider;
2627
import org.testng.annotations.Test;
2728

@@ -887,7 +888,8 @@ public Object[][] paramTypes()
887888
// TODO support timestamptz
888889
// {"timestamptz", ZonedDateTime.of(LocalDateTime.of(1900, 1, 3, 12, 10, 16, 123000000), ZoneId.of("America/Los_Angeles"))},
889890
{"json", "{\"test\":3, \"test2\":4}"},
890-
{"bytea", "test1".getBytes(UTF_8)}
891+
{"bytea", "test1".getBytes(UTF_8)},
892+
{"interval", new PGInterval(1, 5, -3, 7, 55, 20)}
891893

892894
// TODO: type support
893895
// {"any", new Object[] {1, "test", new BigDecimal(10)}}

0 commit comments

Comments
 (0)