Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support float32 type #2894

Merged
merged 28 commits into from
Feb 28, 2024
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1d64140
feat: float32 changes with unit and integration tests
arawind Dec 1, 2023
5a7fdc2
Merge branch 'main' into float32-v2
arawind Feb 15, 2024
1358bbb
Undo the changes to GceTestEnvConfig
arawind Feb 16, 2024
74b01e5
Update formatting and clirr
arawind Feb 16, 2024
6789155
Update the hashCode logic to account for NaN equality
arawind Feb 16, 2024
f1dbc8f
Prevent FLOAT32 integration tests from running on emulator and produc…
arawind Feb 19, 2024
5b493fa
Add a kokoro presubmit workflow to run on cloud-devel.
arawind Feb 20, 2024
80f80a9
Prevent FLOAT32 schema from being added if the env is not cloud-devel
arawind Feb 20, 2024
924ef75
Merge branch 'main' into float32-v2
arawind Feb 20, 2024
253c5f1
Merge branch 'main' into float32-v2
arawind Feb 22, 2024
fac44f0
Revert "Add a kokoro presubmit workflow to run on cloud-devel."
arawind Feb 22, 2024
391f735
Merge branch 'main' into float32-v2
arawind Feb 22, 2024
3e63abd
Fix integration tests for FLOAT32
arawind Feb 23, 2024
b64e627
Update float32UntypedParameters test to work with PG dialect too
arawind Feb 23, 2024
e18fd3f
Remove FLOAT32 changes in CreateMusicTables.sql as the type isn't ful…
arawind Feb 23, 2024
202b10c
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Feb 23, 2024
34a10e2
Merge branch 'float32-v2' of github.com:arawind/java-spanner into flo…
arawind Feb 23, 2024
fda3987
Split the parameters test in ITQueryTest into supported + currently-u…
arawind Feb 23, 2024
dbd12a9
Merge branch 'main' into float32-v2
arawind Feb 23, 2024
646e6eb
Minor changes in comments
arawind Feb 23, 2024
2988656
Split the Mutation.isNaN method to make it more readable
arawind Feb 23, 2024
738916c
Merge branch 'main' into float32-v2
arawind Feb 23, 2024
187182b
test: added some additional tests
olavloite Feb 23, 2024
7543083
Merge branch 'main' into float32-v2
arawind Feb 25, 2024
1057826
Update to resolve comments on PR#2894.
arawind Feb 25, 2024
dedf17e
Merge branch 'main' into float32-v2
arawind Feb 28, 2024
2dfe0df
Un-ignore the skipped FLOAT32 tests as the backend fixes have been de…
arawind Feb 28, 2024
8f6e21f
Un-ignore the float32 tests in ITQueryTest
arawind Feb 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix integration tests for FLOAT32
  • Loading branch information
arawind committed Feb 23, 2024
commit 3e63abdc9b9f73e8dca176dbe4dd40d20e630dd2
Expand Up @@ -54,14 +54,11 @@
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.threeten.bp.Duration;

@Category(ParallelIntegrationTest.class)
@RunWith(Parameterized.class)
public class ITFloat32Test {

private static final Duration OPERATION_TIMEOUT = Duration.ofMinutes(5);

@ClassRule public static IntegrationTestEnv env = new IntegrationTestEnv();

@Parameterized.Parameters(name = "Dialect = {0}")
Expand Down Expand Up @@ -172,6 +169,7 @@ public void writeFloat32() {
assertThat(row.getFloat(0)).isWithin(0.0f).of(2.0f);
}

@Ignore("Needs a fix in the backend.")
@Test
public void writeFloat32NonNumbers() {
assumeTrue("FLOAT32 is currently only supported in cloud-devel", isUsingCloudDevel());
arawind marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -260,14 +258,14 @@ private String getInsertStatementWithLiterals() {
"('dml1', 3.14::float8, array[1.1]::float4[]), "
+ "('dml2', '3.14'::float4, array[3.14::float4, 3.14::float8]::float4[]), "
+ "('dml3', 'nan'::real, array['inf'::real, (3.14::float8)::float4, 1.2, '-inf']::float4[]), "
+ "('dml4', 1.175494e-38::real, array[1.175494e-38, 3.402e38, -3.402e38]::real[]), "
+ "('dml4', 1.175494e-38::real, array[1.175494e-38, 3.4028234e38, -3.4028234e38]::real[]), "
+ "('dml5', null, null)";
} else {
statement +=
"('dml1', 3.14, [CAST(1.1 AS FLOAT32)]), "
+ "('dml2', CAST('3.14' AS FLOAT32), array[CAST(3.14 AS FLOAT32), 3.14]), "
+ "('dml3', CAST('nan' AS FLOAT32), array[CAST('inf' AS FLOAT32), CAST(CAST(3.14 AS FLOAT64) AS FLOAT32), 1.2, CAST('-inf' AS FLOAT32)]), "
+ "('dml4', 1.175494e-38, [CAST(1.175494e-38 AS FLOAT32), 3.402e38, -3.402e38]), "
+ "('dml4', 1.175494e-38, [CAST(1.175494e-38 AS FLOAT32), 3.4028234e38, -3.4028234e38]), "
+ "('dml5', null, null)";
}
return statement;
Expand All @@ -285,7 +283,7 @@ public void float32Literals() {
return null;
});

verifyContents();
verifyContents("dml");
}

private String getInsertStatementWithParameters() {
Expand All @@ -300,6 +298,7 @@ private String getInsertStatementWithParameters() {
return (dialect.dialect == Dialect.POSTGRESQL) ? pgStatement : pgStatement.replace("$", "@p");
}

@Ignore("Needs a fix in the backend.")
@Test
public void float32Parameter() {
assumeTrue("FLOAT32 is currently only supported in cloud-devel", isUsingCloudDevel());
Expand All @@ -326,12 +325,12 @@ public void float32Parameter() {
Arrays.asList(
Float.POSITIVE_INFINITY, 3.14f, 1.2f, Float.POSITIVE_INFINITY)))
.bind("p7")
.to(Value.float32(Float.MIN_VALUE))
.to(Value.float32(Float.MIN_NORMAL))
.bind("p8")
.to(
Value.float32Array(
Arrays.asList(
Float.MIN_VALUE, Float.MAX_VALUE, -1 * Float.MAX_VALUE)))
Float.MIN_NORMAL, Float.MAX_VALUE, -1 * Float.MAX_VALUE)))
.bind("p9")
.to(Value.float32(null))
.bind("p10")
Expand All @@ -340,17 +339,16 @@ public void float32Parameter() {
return null;
});

verifyContents();
verifyContents("param");
}

@Ignore("This will be supported before submission")
@Test
public void float32UntypedParameter() {
assumeTrue("FLOAT32 is currently only supported in cloud-devel", isUsingCloudDevel());

// TODO: Verify before submitting.
assumeTrue(
"This is currently only supported in GoogleSQL??",
"This test is currently only supported in GoogleSQL",
dialect.dialect == Dialect.GOOGLE_STANDARD_SQL);

client
Expand All @@ -360,7 +358,7 @@ public void float32UntypedParameter() {
transaction.executeUpdate(
Statement.newBuilder(
"INSERT INTO T (Key, Float32Value, Float32ArrayValue) VALUES "
+ "('param1', CAST(@p1 AS FLOAT32), CAST(@p2 AS ARRAY<FLOAT32>))")
+ "('untyped1', CAST(@p1 AS FLOAT32), CAST(@p2 AS ARRAY<FLOAT32>))")
.bind("p1")
.to(
Value.untyped(
Expand All @@ -375,57 +373,70 @@ public void float32UntypedParameter() {
com.google.protobuf.ListValue.newBuilder()
.addValues(
com.google.protobuf.Value.newBuilder()
.setNumberValue(Float.MIN_VALUE)))
.setNumberValue((double) Float.MIN_NORMAL)))
.build()))
.build());
return null;
});

// TODO: add verifier.
Struct row = readRow("T", "untyped1", "Float32Value", "Float32ArrayValue");
assertThat(row.isNull("Float32Value")).isFalse();
assertThat(row.getFloat("Float32Value")).isWithin(0.001f).of(3.14f);
assertThat(row.isNull("Float32ArrayValue")).isFalse();
assertThat(row.getFloatList("Float32ArrayValue")).hasSize(1);
assertThat(row.getFloatList("Float32ArrayValue").get(0)).isWithin(0.001f).of(Float.MIN_NORMAL);
}

private void verifyContents() {
private void verifyContents(String keyPrefix) {
try (ResultSet resultSet =
client.singleUse().executeQuery(Statement.of("SELECT * FROM T ORDER BY Key"))) {
client
.singleUse()
.executeQuery(
Statement.of(
"SELECT Key AS key, Float32Value AS float32value, Float32ArrayValue AS float32arrayvalue FROM T WHERE Key LIKE '{keyPrefix}%' ORDER BY key"
.replace("{keyPrefix}", keyPrefix)))) {

assertTrue(resultSet.next());

assertThat(resultSet.getFloat("Float32Value")).isWithin(0.001f).of(3.14f);
assertThat(resultSet.getValue("Float32Value")).isEqualTo(Value.float32(3.14f));
assertThat(resultSet.getFloat("float32value")).isWithin(0.001f).of(3.14f);
assertThat(resultSet.getValue("float32value")).isEqualTo(Value.float32(3.14f));
;
assertThat(resultSet.getFloatArray("Float32ArrayValue")).isEqualTo(new float[] {1.1f});
assertThat(resultSet.getFloatArray("float32arrayvalue")).isEqualTo(new float[] {1.1f});

assertTrue(resultSet.next());

assertThat(resultSet.getFloat("Float32Value")).isWithin(0.001f).of(3.14f);
assertThat(resultSet.getFloatList("Float32ArrayValue")).containsExactly(3.14f, 3.14f);
assertThat(resultSet.getValue("Float32ArrayValue"))
assertThat(resultSet.getFloat("float32value")).isWithin(0.001f).of(3.14f);
assertThat(resultSet.getFloatList("float32arrayvalue")).containsExactly(3.14f, 3.14f);
assertThat(resultSet.getValue("float32arrayvalue"))
.isEqualTo(Value.float32Array(new float[] {3.14f, 3.14f}));

assertTrue(resultSet.next());
assertThat(resultSet.getFloat("Float32Value")).isNaN();
assertThat(resultSet.getValue("Float32Value")).isEqualTo(Value.float32(Float.NaN));
;
assertThat(resultSet.getFloatList("Float32ArrayValue"))
assertThat(resultSet.getFloat("float32value")).isNaN();
assertThat(resultSet.getValue("float32value").getFloat32()).isNaN();
assertThat(resultSet.getFloatList("float32arrayvalue"))
.containsExactly(Float.POSITIVE_INFINITY, 3.14f, 1.2f, Float.NEGATIVE_INFINITY);
assertThat(resultSet.getValue("Float32ArrayValue"))
assertThat(resultSet.getValue("float32arrayvalue"))
.isEqualTo(
Value.float32Array(
Arrays.asList(Float.POSITIVE_INFINITY, 3.14f, 1.2f, Float.NEGATIVE_INFINITY)));

assertTrue(resultSet.next());
assertThat(resultSet.getFloat("Float32Value")).isWithin(0.001f).of(Float.MIN_VALUE);
assertThat(resultSet.getValue("Float32Value")).isEqualTo(Value.float32(Float.MIN_VALUE));
assertThat(resultSet.getFloatList("Float32ArrayValue"))
.containsExactly(Float.MIN_VALUE, Float.MAX_VALUE, -1 * Float.MAX_VALUE);
assertThat(resultSet.getValue("Float32ArrayValue"))
.isEqualTo(
Value.float32Array(
Arrays.asList(Float.MIN_VALUE, Float.MAX_VALUE, -1 * Float.MAX_VALUE)));
assertThat(resultSet.getFloat("float32value")).isWithin(0.1f).of(Float.MIN_NORMAL);
assertThat(resultSet.getValue("float32value").getFloat32())
.isWithin(0.1f)
.of(Float.MIN_NORMAL);
assertThat(resultSet.getFloatList("float32arrayvalue")).hasSize(3);
assertThat(resultSet.getFloatList("float32arrayvalue").get(0))
.isWithin(0.1f)
.of(Float.MIN_NORMAL);
assertThat(resultSet.getFloatList("float32arrayvalue").get(1)).isEqualTo(Float.MAX_VALUE);
assertThat(resultSet.getFloatList("float32arrayvalue").get(2))
.isEqualTo(-1 * Float.MAX_VALUE);
assertThat(resultSet.getValue("float32arrayvalue").getFloat32Array()).hasSize(3);

assertTrue(resultSet.next());
assertTrue(resultSet.isNull("Float32Value"));
assertTrue(resultSet.isNull("Float32ArrayValue"));
assertTrue(resultSet.isNull("float32value"));
assertTrue(resultSet.isNull("float32arrayvalue"));

assertFalse(resultSet.next());
}
Expand Down