Skip to content

Commit b64e627

Browse files
committed
Update float32UntypedParameters test to work with PG dialect too
1 parent 3e63abd commit b64e627

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITFloat32Test.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -342,23 +342,25 @@ public void float32Parameter() {
342342
verifyContents("param");
343343
}
344344

345+
private String getInsertStatementForUntypedParameters() {
346+
if (dialect.dialect == Dialect.POSTGRESQL) {
347+
return "INSERT INTO T (key, float32value, float32arrayvalue) VALUES "
348+
+ "('untyped1', ($1)::float4, ($2)::float4[])";
349+
}
350+
return "INSERT INTO T (Key, Float32Value, Float32ArrayValue) VALUES "
351+
+ "('untyped1', CAST(@p1 AS FLOAT32), CAST(@p2 AS ARRAY<FLOAT32>))";
352+
}
353+
345354
@Test
346355
public void float32UntypedParameter() {
347356
assumeTrue("FLOAT32 is currently only supported in cloud-devel", isUsingCloudDevel());
348357

349-
// TODO: Verify before submitting.
350-
assumeTrue(
351-
"This test is currently only supported in GoogleSQL",
352-
dialect.dialect == Dialect.GOOGLE_STANDARD_SQL);
353-
354358
client
355359
.readWriteTransaction()
356360
.run(
357361
transaction -> {
358362
transaction.executeUpdate(
359-
Statement.newBuilder(
360-
"INSERT INTO T (Key, Float32Value, Float32ArrayValue) VALUES "
361-
+ "('untyped1', CAST(@p1 AS FLOAT32), CAST(@p2 AS ARRAY<FLOAT32>))")
363+
Statement.newBuilder(getInsertStatementForUntypedParameters())
362364
.bind("p1")
363365
.to(
364366
Value.untyped(
@@ -380,11 +382,13 @@ public void float32UntypedParameter() {
380382
});
381383

382384
Struct row = readRow("T", "untyped1", "Float32Value", "Float32ArrayValue");
383-
assertThat(row.isNull("Float32Value")).isFalse();
384-
assertThat(row.getFloat("Float32Value")).isWithin(0.001f).of(3.14f);
385-
assertThat(row.isNull("Float32ArrayValue")).isFalse();
386-
assertThat(row.getFloatList("Float32ArrayValue")).hasSize(1);
387-
assertThat(row.getFloatList("Float32ArrayValue").get(0)).isWithin(0.001f).of(Float.MIN_NORMAL);
385+
// Float32Value
386+
assertThat(row.isNull(0)).isFalse();
387+
assertThat(row.getFloat(0)).isWithin(0.001f).of(3.14f);
388+
// Float32ArrayValue
389+
assertThat(row.isNull(1)).isFalse();
390+
assertThat(row.getFloatList(1)).hasSize(1);
391+
assertThat(row.getFloatList(1).get(0)).isWithin(0.001f).of(Float.MIN_NORMAL);
388392
}
389393

390394
private void verifyContents(String keyPrefix) {

0 commit comments

Comments
 (0)