Skip to content

Commit b550f87

Browse files
committed
test: enable integration tests for float32
1 parent 8d89694 commit b550f87

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

src/test/java/com/google/cloud/spanner/jdbc/it/ITJdbcPgNumericTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,7 @@ public void testPreparedStatement() throws Exception {
226226
preparedStatement.setShort(3, (short) 1);
227227
preparedStatement.setInt(4, 1);
228228
preparedStatement.setLong(5, 1L);
229-
// TODO: Change to setFloat(..) when float32 is supported.
230-
// preparedStatement.setFloat(6, 1f);
231-
preparedStatement.setDouble(6, 1d);
229+
preparedStatement.setFloat(6, 1f);
232230
preparedStatement.setDouble(7, 1D);
233231
preparedStatement.setBigDecimal(8, new BigDecimal("1"));
234232
preparedStatement.setObject(9, (byte) 1);
@@ -240,9 +238,7 @@ public void testPreparedStatement() throws Exception {
240238
preparedStatement.setObject(15, new BigDecimal("1"));
241239
preparedStatement.setObject(16, Value.pgNumeric("1"));
242240

243-
// TODO: Change to setFloat(..) when float32 is supported.
244-
// preparedStatement.setFloat(17, Float.NaN);
245-
preparedStatement.setDouble(17, Double.NaN);
241+
preparedStatement.setFloat(17, Float.NaN);
246242
preparedStatement.setDouble(18, Double.NaN);
247243
preparedStatement.setObject(19, Value.pgNumeric("NaN"));
248244

src/test/java/com/google/cloud/spanner/jdbc/it/ITJdbcPreparedStatementTest.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -922,16 +922,17 @@ public void test08_InsertAllColumnTypes() throws SQLException {
922922
dialect.dialect == Dialect.POSTGRESQL);
923923
String sql =
924924
"INSERT INTO TableWithAllColumnTypes ("
925-
+ "ColInt64, ColFloat64, ColBool, ColString, ColStringMax, ColBytes, ColBytesMax, ColDate, ColTimestamp, ColCommitTS, ColNumeric, ColJson, "
926-
+ "ColInt64Array, ColFloat64Array, ColBoolArray, ColStringArray, ColStringMaxArray, ColBytesArray, ColBytesMaxArray, ColDateArray, ColTimestampArray, ColNumericArray, ColJsonArray"
927-
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, PENDING_COMMIT_TIMESTAMP(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
925+
+ "ColInt64, ColFloat64, ColFloat32, ColBool, ColString, ColStringMax, ColBytes, ColBytesMax, ColDate, ColTimestamp, ColCommitTS, ColNumeric, ColJson, "
926+
+ "ColInt64Array, ColFloat64Array, ColFloat32Array, ColBoolArray, ColStringArray, ColStringMaxArray, ColBytesArray, ColBytesMaxArray, ColDateArray, ColTimestampArray, ColNumericArray, ColJsonArray"
927+
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, PENDING_COMMIT_TIMESTAMP(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
928928
try (Connection con = createConnection(env, database)) {
929929
try (PreparedStatement ps = con.prepareStatement(sql)) {
930930
ParameterMetaData metadata = ps.getParameterMetaData();
931-
assertEquals(22, metadata.getParameterCount());
931+
assertEquals(24, metadata.getParameterCount());
932932
int index = 0;
933933
assertEquals(Types.BIGINT, metadata.getParameterType(++index));
934934
assertEquals(Types.DOUBLE, metadata.getParameterType(++index));
935+
assertEquals(Types.REAL, metadata.getParameterType(++index));
935936
assertEquals(Types.BOOLEAN, metadata.getParameterType(++index));
936937
assertEquals(Types.NVARCHAR, metadata.getParameterType(++index));
937938
assertEquals(Types.NVARCHAR, metadata.getParameterType(++index));
@@ -952,10 +953,12 @@ public void test08_InsertAllColumnTypes() throws SQLException {
952953
assertEquals(Types.ARRAY, metadata.getParameterType(++index));
953954
assertEquals(Types.ARRAY, metadata.getParameterType(++index));
954955
assertEquals(Types.ARRAY, metadata.getParameterType(++index));
956+
assertEquals(Types.ARRAY, metadata.getParameterType(++index));
955957

956958
index = 0;
957959
ps.setLong(++index, 1L);
958960
ps.setDouble(++index, 2D);
961+
ps.setFloat(++index, 3.14f);
959962
ps.setBoolean(++index, true);
960963
ps.setString(++index, "test");
961964
ps.setObject(++index, UUID.fromString("2d37f522-e0a5-4f22-8e09-4d77d299c967"));
@@ -968,6 +971,7 @@ public void test08_InsertAllColumnTypes() throws SQLException {
968971

969972
ps.setArray(++index, con.createArrayOf("INT64", new Long[] {1L, 2L, 3L}));
970973
ps.setArray(++index, con.createArrayOf("FLOAT64", new Double[] {1.1D, 2.2D, 3.3D}));
974+
ps.setArray(++index, con.createArrayOf("FLOAT32", new Float[] {1.1f, 2.2f, 3.3f}));
971975
ps.setArray(
972976
++index, con.createArrayOf("BOOL", new Boolean[] {Boolean.TRUE, null, Boolean.FALSE}));
973977
ps.setArray(++index, con.createArrayOf("STRING", new String[] {"1", "2", "3"}));
@@ -1006,6 +1010,7 @@ public void test08_InsertAllColumnTypes() throws SQLException {
10061010
assertTrue(rs.next());
10071011
assertEquals(1L, rs.getLong(++index));
10081012
assertEquals(2d, rs.getDouble(++index), 0.0d);
1013+
assertEquals(3.14f, rs.getFloat(++index), 0.0f);
10091014
assertTrue(rs.getBoolean(++index));
10101015
assertEquals("test", rs.getString(++index));
10111016
assertEquals("2d37f522-e0a5-4f22-8e09-4d77d299c967", rs.getString(++index));
@@ -1020,6 +1025,8 @@ public void test08_InsertAllColumnTypes() throws SQLException {
10201025
assertArrayEquals(new Long[] {1L, 2L, 3L}, (Long[]) rs.getArray(++index).getArray());
10211026
assertArrayEquals(
10221027
new Double[] {1.1D, 2.2D, 3.3D}, (Double[]) rs.getArray(++index).getArray());
1028+
assertArrayEquals(
1029+
new Float[] {1.1f, 2.2f, 3.3f}, (Float[]) rs.getArray(++index).getArray());
10231030
assertArrayEquals(
10241031
new Boolean[] {true, null, false}, (Boolean[]) rs.getArray(++index).getArray());
10251032
assertArrayEquals(new String[] {"1", "2", "3"}, (String[]) rs.getArray(++index).getArray());
@@ -1049,13 +1056,14 @@ public void test08_PGInsertAllColumnTypes() throws SQLException {
10491056

10501057
String sql =
10511058
"INSERT INTO TableWithAllColumnTypes ("
1052-
+ "ColInt64, ColFloat64, ColBool, ColString, ColStringMax, ColBytes, ColDate, ColTimestamp, ColNumeric, ColJson"
1053-
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
1059+
+ "ColInt64, ColFloat64, ColFloat32, ColBool, ColString, ColStringMax, ColBytes, ColDate, ColTimestamp, ColNumeric, ColJson"
1060+
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
10541061
try (Connection con = createConnection(env, database)) {
10551062
try (PreparedStatement ps = con.prepareStatement(sql)) {
10561063
int index = 0;
10571064
ps.setLong(++index, 1L);
10581065
ps.setDouble(++index, 2D);
1066+
ps.setFloat(++index, 3.14f);
10591067
ps.setBoolean(++index, true);
10601068
ps.setString(++index, "test");
10611069
ps.setObject(++index, UUID.fromString("2d37f522-e0a5-4f22-8e09-4d77d299c967"));
@@ -1074,6 +1082,7 @@ public void test08_PGInsertAllColumnTypes() throws SQLException {
10741082
assertTrue(rs.next());
10751083
assertEquals(1L, rs.getLong(++index));
10761084
assertEquals(2d, rs.getDouble(++index), 0.0d);
1085+
assertEquals(3.14f, rs.getFloat(++index), 0.0f);
10771086
assertTrue(rs.getBoolean(++index));
10781087
assertEquals("test", rs.getString(++index));
10791088
assertEquals("2d37f522-e0a5-4f22-8e09-4d77d299c967", rs.getString(++index));
@@ -1097,10 +1106,11 @@ public void test09_MetaData_FromQuery() throws SQLException {
10971106
try (PreparedStatement ps =
10981107
con.prepareStatement("SELECT * FROM TableWithAllColumnTypes WHERE ColInt64=?")) {
10991108
ResultSetMetaData metadata = ps.getMetaData();
1100-
assertEquals(24, metadata.getColumnCount());
1109+
assertEquals(26, metadata.getColumnCount());
11011110
int index = 0;
11021111
assertEquals("ColInt64", metadata.getColumnLabel(++index));
11031112
assertEquals("ColFloat64", metadata.getColumnLabel(++index));
1113+
assertEquals("ColFloat32", metadata.getColumnLabel(++index));
11041114
assertEquals("ColBool", metadata.getColumnLabel(++index));
11051115
assertEquals("ColString", metadata.getColumnLabel(++index));
11061116
assertEquals("ColStringMax", metadata.getColumnLabel(++index));
@@ -1113,6 +1123,7 @@ public void test09_MetaData_FromQuery() throws SQLException {
11131123
assertEquals("ColJson", metadata.getColumnLabel(++index));
11141124
assertEquals("ColInt64Array", metadata.getColumnLabel(++index));
11151125
assertEquals("ColFloat64Array", metadata.getColumnLabel(++index));
1126+
assertEquals("ColFloat32Array", metadata.getColumnLabel(++index));
11161127
assertEquals("ColBoolArray", metadata.getColumnLabel(++index));
11171128
assertEquals("ColStringArray", metadata.getColumnLabel(++index));
11181129
assertEquals("ColStringMaxArray", metadata.getColumnLabel(++index));
@@ -1149,14 +1160,15 @@ public void test11_InsertDataUsingSpannerValue() throws SQLException {
11491160
dialect.dialect == Dialect.POSTGRESQL);
11501161
String sql =
11511162
"INSERT INTO TableWithAllColumnTypes ("
1152-
+ "ColInt64, ColFloat64, ColBool, ColString, ColStringMax, ColBytes, ColBytesMax, ColDate, ColTimestamp, ColCommitTS, ColNumeric, ColJson, "
1153-
+ "ColInt64Array, ColFloat64Array, ColBoolArray, ColStringArray, ColStringMaxArray, ColBytesArray, ColBytesMaxArray, ColDateArray, ColTimestampArray, ColNumericArray, ColJsonArray"
1154-
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, PENDING_COMMIT_TIMESTAMP(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
1163+
+ "ColInt64, ColFloat64, ColFloat32, ColBool, ColString, ColStringMax, ColBytes, ColBytesMax, ColDate, ColTimestamp, ColCommitTS, ColNumeric, ColJson, "
1164+
+ "ColInt64Array, ColFloat64Array, ColFloat32Array, ColBoolArray, ColStringArray, ColStringMaxArray, ColBytesArray, ColBytesMaxArray, ColDateArray, ColTimestampArray, ColNumericArray, ColJsonArray"
1165+
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, PENDING_COMMIT_TIMESTAMP(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
11551166
try (Connection con = createConnection(env, database)) {
11561167
try (PreparedStatement ps = con.prepareStatement(sql)) {
11571168
int index = 1;
11581169
ps.setObject(index++, Value.int64(2L));
11591170
ps.setObject(index++, Value.float64(2D));
1171+
ps.setObject(index++, Value.float32(3.14f));
11601172
ps.setObject(index++, Value.bool(true));
11611173
ps.setObject(index++, Value.string("testvalues"));
11621174
ps.setObject(index++, Value.string("2d37f522-e0a5-4f22-8e09-4d77d299c967"));
@@ -1170,6 +1182,7 @@ public void test11_InsertDataUsingSpannerValue() throws SQLException {
11701182

11711183
ps.setObject(index++, Value.int64Array(new long[] {1L, 2L, 3L}));
11721184
ps.setObject(index++, Value.float64Array(new double[] {1.1D, 2.2D, 3.3D}));
1185+
ps.setObject(index++, Value.float32Array(new float[] {1.1f, 2.2f, 3.3f}));
11731186
ps.setObject(index++, Value.boolArray(Arrays.asList(Boolean.TRUE, null, Boolean.FALSE)));
11741187
ps.setObject(index++, Value.stringArray(Arrays.asList("1", "2", "3")));
11751188
ps.setObject(index++, Value.stringArray(Arrays.asList("3", "2", "1")));
@@ -1207,6 +1220,7 @@ public void test11_InsertDataUsingSpannerValue() throws SQLException {
12071220
int index = 1;
12081221
assertEquals(Value.int64(2L), rs.getObject(index++, Value.class));
12091222
assertEquals(Value.float64(2d), rs.getObject(index++, Value.class));
1223+
assertEquals(Value.float32(3.14f), rs.getObject(index++, Value.class));
12101224
assertEquals(Value.bool(true), rs.getObject(index++, Value.class));
12111225
assertEquals(Value.string("testvalues"), rs.getObject(index++, Value.class));
12121226
assertEquals(
@@ -1229,6 +1243,8 @@ public void test11_InsertDataUsingSpannerValue() throws SQLException {
12291243
assertEquals(
12301244
Value.float64Array(new double[] {1.1D, 2.2D, 3.3D}),
12311245
rs.getObject(index++, Value.class));
1246+
assertEquals(
1247+
Value.float32Array(new float[] {1.1f, 2.2f, 3.3f}), rs.getObject(index++, Value.class));
12321248
assertEquals(
12331249
Value.boolArray(Arrays.asList(true, null, false)), rs.getObject(index++, Value.class));
12341250
assertEquals(

src/test/resources/com/google/cloud/spanner/jdbc/it/CreateMusicTables.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ CREATE TABLE Concerts (
7070
CREATE TABLE TableWithAllColumnTypes (
7171
ColInt64 INT64 NOT NULL,
7272
ColFloat64 FLOAT64 NOT NULL,
73+
ColFloat32 FLOAT32 NOT NULL,
7374
ColBool BOOL NOT NULL,
7475
ColString STRING(100) NOT NULL,
7576
ColStringMax STRING(MAX) NOT NULL,
@@ -83,6 +84,7 @@ CREATE TABLE TableWithAllColumnTypes (
8384

8485
ColInt64Array ARRAY<INT64>,
8586
ColFloat64Array ARRAY<FLOAT64>,
87+
ColFloat32Array ARRAY<FLOAT32>,
8688
ColBoolArray ARRAY<BOOL>,
8789
ColStringArray ARRAY<STRING(100)>,
8890
ColStringMaxArray ARRAY<STRING(MAX)>,
@@ -100,6 +102,7 @@ CREATE TABLE TableWithAllColumnTypes (
100102
CREATE TABLE all_nullable_types (
101103
ColInt64 INT64,
102104
ColFloat64 FLOAT64,
105+
ColFloat32 FLOAT32,
103106
ColBool BOOL,
104107
ColString STRING(100),
105108
ColBytes BYTES(100),
@@ -110,6 +113,7 @@ CREATE TABLE all_nullable_types (
110113

111114
ColInt64Array ARRAY<INT64>,
112115
ColFloat64Array ARRAY<FLOAT64>,
116+
ColFloat32Array ARRAY<FLOAT32>,
113117
ColBoolArray ARRAY<BOOL>,
114118
ColStringArray ARRAY<STRING(100)>,
115119
ColBytesArray ARRAY<BYTES(100)>,

src/test/resources/com/google/cloud/spanner/jdbc/it/CreateMusicTables_PG.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ CREATE TABLE Concerts (
7171
CREATE TABLE TableWithAllColumnTypes (
7272
ColInt64 BIGINT PRIMARY KEY,
7373
ColFloat64 FLOAT8 NOT NULL,
74+
ColFloat32 FLOAT4 NOT NULL,
7475
ColBool BOOL NOT NULL,
7576
ColString VARCHAR(100) NOT NULL,
7677
ColStringMax TEXT,
@@ -83,6 +84,7 @@ CREATE TABLE TableWithAllColumnTypes (
8384
CREATE TABLE all_nullable_types (
8485
ColInt64 bigint primary key,
8586
ColFloat64 float8,
87+
ColFloat32 float4,
8688
ColBool boolean,
8789
ColString varchar(100),
8890
ColBytes bytea,
@@ -93,6 +95,7 @@ CREATE TABLE all_nullable_types (
9395

9496
ColInt64Array bigint[],
9597
ColFloat64Array float8[],
98+
ColFloat32Array float4[],
9699
ColBoolArray boolean[],
97100
ColStringArray varchar(100)[],
98101
ColBytesArray bytea[],

0 commit comments

Comments
 (0)