Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ SELECT TABLE_CATALOG AS TABLE_CAT, TABLE_SCHEMA AS TABLE_SCHEM, TABLE_NAME, COLU
WHEN SPANNER_TYPE LIKE 'BYTES%' THEN -2
WHEN SPANNER_TYPE = 'DATE' THEN 91
WHEN SPANNER_TYPE = 'FLOAT64' THEN 8
WHEN SPANNER_TYPE = 'FLOAT32' THEN 7
WHEN SPANNER_TYPE = 'INT64' THEN -5
WHEN SPANNER_TYPE = 'NUMERIC' THEN 2
WHEN SPANNER_TYPE LIKE 'STRING%' THEN -9
Expand All @@ -34,6 +35,7 @@ SELECT TABLE_CATALOG AS TABLE_CAT, TABLE_SCHEMA AS TABLE_SCHEM, TABLE_NAME, COLU
WHEN SPANNER_TYPE = 'INT64' OR SPANNER_TYPE = 'ARRAY<INT64>' THEN 19
WHEN SPANNER_TYPE = 'NUMERIC' OR SPANNER_TYPE = 'ARRAY<NUMERIC>' THEN 15
WHEN SPANNER_TYPE = 'FLOAT64' OR SPANNER_TYPE = 'ARRAY<FLOAT64>' THEN 15
WHEN SPANNER_TYPE = 'FLOAT32' OR SPANNER_TYPE = 'ARRAY<FLOAT32>' THEN 15
WHEN SPANNER_TYPE = 'BOOL' OR SPANNER_TYPE = 'ARRAY<BOOL>' THEN NULL
WHEN SPANNER_TYPE = 'DATE' OR SPANNER_TYPE = 'ARRAY<DATE>' THEN 10
WHEN SPANNER_TYPE = 'TIMESTAMP' OR SPANNER_TYPE = 'ARRAY<TIMESTAMP>' THEN 35
Expand All @@ -45,12 +47,14 @@ SELECT TABLE_CATALOG AS TABLE_CAT, TABLE_SCHEMA AS TABLE_SCHEM, TABLE_NAME, COLU
0 AS BUFFER_LENGTH,
CASE
WHEN SPANNER_TYPE LIKE '%FLOAT64%' THEN 16
WHEN SPANNER_TYPE LIKE '%FLOAT32%' THEN 16
ELSE NULL
END AS DECIMAL_DIGITS,
CASE
WHEN SPANNER_TYPE LIKE '%INT64%' THEN 10
WHEN SPANNER_TYPE LIKE '%NUMERIC%' THEN 10
WHEN SPANNER_TYPE LIKE '%FLOAT64%' THEN 2
WHEN SPANNER_TYPE LIKE '%FLOAT32%' THEN 2
ELSE NULL
END AS NUM_PREC_RADIX,
CASE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ SELECT TABLE_CATALOG AS "TABLE_CAT", TABLE_SCHEMA AS "TABLE_SCHEM", TABLE_NAME A
WHEN DATA_TYPE LIKE 'bytea' THEN -2
WHEN DATA_TYPE = 'date' THEN 91
WHEN DATA_TYPE = 'double precision' THEN 8
WHEN DATA_TYPE = 'real' THEN 7
WHEN DATA_TYPE = 'bigint' THEN -5
WHEN DATA_TYPE = 'numeric' THEN 2
WHEN DATA_TYPE LIKE 'character varying' THEN -9
Expand All @@ -34,6 +35,7 @@ SELECT TABLE_CATALOG AS "TABLE_CAT", TABLE_SCHEMA AS "TABLE_SCHEM", TABLE_NAME A
WHEN DATA_TYPE LIKE 'bytea' THEN 10485760
WHEN DATA_TYPE = 'date' THEN 10
WHEN DATA_TYPE = 'double precision' THEN 15
WHEN DATA_TYPE = 'real' THEN 15
WHEN DATA_TYPE = 'bigint' THEN 19
WHEN DATA_TYPE = 'numeric' THEN 15
WHEN DATA_TYPE LIKE 'character varying' THEN CHARACTER_MAXIMUM_LENGTH
Expand All @@ -43,13 +45,15 @@ SELECT TABLE_CATALOG AS "TABLE_CAT", TABLE_SCHEMA AS "TABLE_SCHEM", TABLE_NAME A
0 AS "BUFFER_LENGTH",
CASE
WHEN DATA_TYPE LIKE 'double precision' THEN 16
WHEN DATA_TYPE LIKE 'real' THEN 16
WHEN DATA_TYPE LIKE 'numeric' THEN 16383
ELSE NULL
END AS "DECIMAL_DIGITS",
CASE
WHEN DATA_TYPE LIKE 'bigint' THEN 10
WHEN DATA_TYPE LIKE 'numeric' THEN 10
WHEN DATA_TYPE LIKE 'double precision' THEN 2
WHEN DATA_TYPE LIKE 'real' THEN 2
ELSE NULL
END AS "NUM_PREC_RADIX",
CASE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ private Column(
Arrays.asList(
new Column("ColInt64", Types.BIGINT, "INT64", 19, null, 10, false, null),
new Column("ColFloat64", Types.DOUBLE, "FLOAT64", 15, 16, 2, false, null),
new Column("ColFloat32", Types.REAL, "FLOAT32", 15, 16, 2, false, null),
new Column("ColBool", Types.BOOLEAN, "BOOL", null, null, null, false, null),
new Column("ColString", Types.NVARCHAR, "STRING(100)", 100, null, null, false, 100),
new Column(
Expand All @@ -162,6 +163,7 @@ private Column(
new Column("ColJson", Types.NVARCHAR, "JSON", 2621440, null, null, false, 2621440),
new Column("ColInt64Array", Types.ARRAY, "ARRAY<INT64>", 19, null, 10, true, null),
new Column("ColFloat64Array", Types.ARRAY, "ARRAY<FLOAT64>", 15, 16, 2, true, null),
new Column("ColFloat32Array", Types.ARRAY, "ARRAY<FLOAT32>", 15, 16, 2, true, null),
new Column("ColBoolArray", Types.ARRAY, "ARRAY<BOOL>", null, null, null, true, null),
new Column(
"ColStringArray", Types.ARRAY, "ARRAY<STRING(100)>", 100, null, null, true, 100),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ private Column(
Arrays.asList(
new Column("colint64", Types.BIGINT, "bigint", 19, null, 10, false, null),
new Column("colfloat64", Types.DOUBLE, "double precision", 15, 16, 2, false, null),
new Column("colfloat32", Types.REAL, "real", 15, 16, 2, false, null),
new Column("colbool", Types.BOOLEAN, "boolean", null, null, null, false, null),
new Column("colstring", Types.NVARCHAR, "character varying", 100, null, null, false, 100),
new Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ public void testPreparedStatement() throws Exception {
preparedStatement.setShort(3, (short) 1);
preparedStatement.setInt(4, 1);
preparedStatement.setLong(5, 1L);
// TODO: Change to setFloat(..) when float32 is supported.
// preparedStatement.setFloat(6, 1f);
preparedStatement.setDouble(6, 1d);
preparedStatement.setFloat(6, 1f);
preparedStatement.setDouble(7, 1D);
preparedStatement.setBigDecimal(8, new BigDecimal("1"));
preparedStatement.setObject(9, (byte) 1);
Expand All @@ -240,9 +238,7 @@ public void testPreparedStatement() throws Exception {
preparedStatement.setObject(15, new BigDecimal("1"));
preparedStatement.setObject(16, Value.pgNumeric("1"));

// TODO: Change to setFloat(..) when float32 is supported.
// preparedStatement.setFloat(17, Float.NaN);
preparedStatement.setDouble(17, Double.NaN);
preparedStatement.setFloat(17, Float.NaN);
preparedStatement.setDouble(18, Double.NaN);
preparedStatement.setObject(19, Value.pgNumeric("NaN"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -922,16 +922,17 @@ public void test08_InsertAllColumnTypes() throws SQLException {
dialect.dialect == Dialect.POSTGRESQL);
String sql =
"INSERT INTO TableWithAllColumnTypes ("
+ "ColInt64, ColFloat64, ColBool, ColString, ColStringMax, ColBytes, ColBytesMax, ColDate, ColTimestamp, ColCommitTS, ColNumeric, ColJson, "
+ "ColInt64Array, ColFloat64Array, ColBoolArray, ColStringArray, ColStringMaxArray, ColBytesArray, ColBytesMaxArray, ColDateArray, ColTimestampArray, ColNumericArray, ColJsonArray"
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, PENDING_COMMIT_TIMESTAMP(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ "ColInt64, ColFloat64, ColFloat32, ColBool, ColString, ColStringMax, ColBytes, ColBytesMax, ColDate, ColTimestamp, ColCommitTS, ColNumeric, ColJson, "
+ "ColInt64Array, ColFloat64Array, ColFloat32Array, ColBoolArray, ColStringArray, ColStringMaxArray, ColBytesArray, ColBytesMaxArray, ColDateArray, ColTimestampArray, ColNumericArray, ColJsonArray"
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, PENDING_COMMIT_TIMESTAMP(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
try (Connection con = createConnection(env, database)) {
try (PreparedStatement ps = con.prepareStatement(sql)) {
ParameterMetaData metadata = ps.getParameterMetaData();
assertEquals(22, metadata.getParameterCount());
assertEquals(24, metadata.getParameterCount());
int index = 0;
assertEquals(Types.BIGINT, metadata.getParameterType(++index));
assertEquals(Types.DOUBLE, metadata.getParameterType(++index));
assertEquals(Types.REAL, metadata.getParameterType(++index));
assertEquals(Types.BOOLEAN, metadata.getParameterType(++index));
assertEquals(Types.NVARCHAR, metadata.getParameterType(++index));
assertEquals(Types.NVARCHAR, metadata.getParameterType(++index));
Expand All @@ -952,10 +953,12 @@ public void test08_InsertAllColumnTypes() throws SQLException {
assertEquals(Types.ARRAY, metadata.getParameterType(++index));
assertEquals(Types.ARRAY, metadata.getParameterType(++index));
assertEquals(Types.ARRAY, metadata.getParameterType(++index));
assertEquals(Types.ARRAY, metadata.getParameterType(++index));

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

ps.setArray(++index, con.createArrayOf("INT64", new Long[] {1L, 2L, 3L}));
ps.setArray(++index, con.createArrayOf("FLOAT64", new Double[] {1.1D, 2.2D, 3.3D}));
ps.setArray(++index, con.createArrayOf("FLOAT32", new Float[] {1.1f, 2.2f, 3.3f}));
ps.setArray(
++index, con.createArrayOf("BOOL", new Boolean[] {Boolean.TRUE, null, Boolean.FALSE}));
ps.setArray(++index, con.createArrayOf("STRING", new String[] {"1", "2", "3"}));
Expand Down Expand Up @@ -1006,6 +1010,7 @@ public void test08_InsertAllColumnTypes() throws SQLException {
assertTrue(rs.next());
assertEquals(1L, rs.getLong(++index));
assertEquals(2d, rs.getDouble(++index), 0.0d);
assertEquals(3.14f, rs.getFloat(++index), 0.0f);
assertTrue(rs.getBoolean(++index));
assertEquals("test", rs.getString(++index));
assertEquals("2d37f522-e0a5-4f22-8e09-4d77d299c967", rs.getString(++index));
Expand All @@ -1020,6 +1025,8 @@ public void test08_InsertAllColumnTypes() throws SQLException {
assertArrayEquals(new Long[] {1L, 2L, 3L}, (Long[]) rs.getArray(++index).getArray());
assertArrayEquals(
new Double[] {1.1D, 2.2D, 3.3D}, (Double[]) rs.getArray(++index).getArray());
assertArrayEquals(
new Float[] {1.1f, 2.2f, 3.3f}, (Float[]) rs.getArray(++index).getArray());
assertArrayEquals(
new Boolean[] {true, null, false}, (Boolean[]) rs.getArray(++index).getArray());
assertArrayEquals(new String[] {"1", "2", "3"}, (String[]) rs.getArray(++index).getArray());
Expand Down Expand Up @@ -1049,13 +1056,14 @@ public void test08_PGInsertAllColumnTypes() throws SQLException {

String sql =
"INSERT INTO TableWithAllColumnTypes ("
+ "ColInt64, ColFloat64, ColBool, ColString, ColStringMax, ColBytes, ColDate, ColTimestamp, ColNumeric, ColJson"
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ "ColInt64, ColFloat64, ColFloat32, ColBool, ColString, ColStringMax, ColBytes, ColDate, ColTimestamp, ColNumeric, ColJson"
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
try (Connection con = createConnection(env, database)) {
try (PreparedStatement ps = con.prepareStatement(sql)) {
int index = 0;
ps.setLong(++index, 1L);
ps.setDouble(++index, 2D);
ps.setFloat(++index, 3.14f);
ps.setBoolean(++index, true);
ps.setString(++index, "test");
ps.setObject(++index, UUID.fromString("2d37f522-e0a5-4f22-8e09-4d77d299c967"));
Expand All @@ -1074,6 +1082,7 @@ public void test08_PGInsertAllColumnTypes() throws SQLException {
assertTrue(rs.next());
assertEquals(1L, rs.getLong(++index));
assertEquals(2d, rs.getDouble(++index), 0.0d);
assertEquals(3.14f, rs.getFloat(++index), 0.0f);
assertTrue(rs.getBoolean(++index));
assertEquals("test", rs.getString(++index));
assertEquals("2d37f522-e0a5-4f22-8e09-4d77d299c967", rs.getString(++index));
Expand All @@ -1097,10 +1106,11 @@ public void test09_MetaData_FromQuery() throws SQLException {
try (PreparedStatement ps =
con.prepareStatement("SELECT * FROM TableWithAllColumnTypes WHERE ColInt64=?")) {
ResultSetMetaData metadata = ps.getMetaData();
assertEquals(24, metadata.getColumnCount());
assertEquals(26, metadata.getColumnCount());
int index = 0;
assertEquals("ColInt64", metadata.getColumnLabel(++index));
assertEquals("ColFloat64", metadata.getColumnLabel(++index));
assertEquals("ColFloat32", metadata.getColumnLabel(++index));
assertEquals("ColBool", metadata.getColumnLabel(++index));
assertEquals("ColString", metadata.getColumnLabel(++index));
assertEquals("ColStringMax", metadata.getColumnLabel(++index));
Expand All @@ -1113,6 +1123,7 @@ public void test09_MetaData_FromQuery() throws SQLException {
assertEquals("ColJson", metadata.getColumnLabel(++index));
assertEquals("ColInt64Array", metadata.getColumnLabel(++index));
assertEquals("ColFloat64Array", metadata.getColumnLabel(++index));
assertEquals("ColFloat32Array", metadata.getColumnLabel(++index));
assertEquals("ColBoolArray", metadata.getColumnLabel(++index));
assertEquals("ColStringArray", metadata.getColumnLabel(++index));
assertEquals("ColStringMaxArray", metadata.getColumnLabel(++index));
Expand Down Expand Up @@ -1149,14 +1160,15 @@ public void test11_InsertDataUsingSpannerValue() throws SQLException {
dialect.dialect == Dialect.POSTGRESQL);
String sql =
"INSERT INTO TableWithAllColumnTypes ("
+ "ColInt64, ColFloat64, ColBool, ColString, ColStringMax, ColBytes, ColBytesMax, ColDate, ColTimestamp, ColCommitTS, ColNumeric, ColJson, "
+ "ColInt64Array, ColFloat64Array, ColBoolArray, ColStringArray, ColStringMaxArray, ColBytesArray, ColBytesMaxArray, ColDateArray, ColTimestampArray, ColNumericArray, ColJsonArray"
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, PENDING_COMMIT_TIMESTAMP(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ "ColInt64, ColFloat64, ColFloat32, ColBool, ColString, ColStringMax, ColBytes, ColBytesMax, ColDate, ColTimestamp, ColCommitTS, ColNumeric, ColJson, "
+ "ColInt64Array, ColFloat64Array, ColFloat32Array, ColBoolArray, ColStringArray, ColStringMaxArray, ColBytesArray, ColBytesMaxArray, ColDateArray, ColTimestampArray, ColNumericArray, ColJsonArray"
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, PENDING_COMMIT_TIMESTAMP(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
try (Connection con = createConnection(env, database)) {
try (PreparedStatement ps = con.prepareStatement(sql)) {
int index = 1;
ps.setObject(index++, Value.int64(2L));
ps.setObject(index++, Value.float64(2D));
ps.setObject(index++, Value.float32(3.14f));
ps.setObject(index++, Value.bool(true));
ps.setObject(index++, Value.string("testvalues"));
ps.setObject(index++, Value.string("2d37f522-e0a5-4f22-8e09-4d77d299c967"));
Expand All @@ -1170,6 +1182,7 @@ public void test11_InsertDataUsingSpannerValue() throws SQLException {

ps.setObject(index++, Value.int64Array(new long[] {1L, 2L, 3L}));
ps.setObject(index++, Value.float64Array(new double[] {1.1D, 2.2D, 3.3D}));
ps.setObject(index++, Value.float32Array(new float[] {1.1f, 2.2f, 3.3f}));
ps.setObject(index++, Value.boolArray(Arrays.asList(Boolean.TRUE, null, Boolean.FALSE)));
ps.setObject(index++, Value.stringArray(Arrays.asList("1", "2", "3")));
ps.setObject(index++, Value.stringArray(Arrays.asList("3", "2", "1")));
Expand Down Expand Up @@ -1207,6 +1220,7 @@ public void test11_InsertDataUsingSpannerValue() throws SQLException {
int index = 1;
assertEquals(Value.int64(2L), rs.getObject(index++, Value.class));
assertEquals(Value.float64(2d), rs.getObject(index++, Value.class));
assertEquals(Value.float32(3.14f), rs.getObject(index++, Value.class));
assertEquals(Value.bool(true), rs.getObject(index++, Value.class));
assertEquals(Value.string("testvalues"), rs.getObject(index++, Value.class));
assertEquals(
Expand All @@ -1229,6 +1243,8 @@ public void test11_InsertDataUsingSpannerValue() throws SQLException {
assertEquals(
Value.float64Array(new double[] {1.1D, 2.2D, 3.3D}),
rs.getObject(index++, Value.class));
assertEquals(
Value.float32Array(new float[] {1.1f, 2.2f, 3.3f}), rs.getObject(index++, Value.class));
assertEquals(
Value.boolArray(Arrays.asList(true, null, false)), rs.getObject(index++, Value.class));
assertEquals(
Expand Down Expand Up @@ -1448,9 +1464,9 @@ public void test13_InsertUntypedNullValues() throws SQLException {
try (PreparedStatement preparedStatement =
connection.prepareStatement(
"insert into all_nullable_types ("
+ "ColInt64, ColFloat64, ColBool, ColString, ColBytes, ColDate, ColTimestamp, ColNumeric, ColJson, "
+ "ColInt64, ColFloat64, ColFloat32, ColBool, ColString, ColBytes, ColDate, ColTimestamp, ColNumeric, ColJson, "
+ "ColInt64Array, ColFloat64Array, ColBoolArray, ColStringArray, ColBytesArray, ColDateArray, ColTimestampArray, ColNumericArray, ColJsonArray) "
+ "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
+ "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
for (int param = 1;
param <= preparedStatement.getParameterMetaData().getParameterCount();
param++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ CREATE TABLE Concerts (
CREATE TABLE TableWithAllColumnTypes (
ColInt64 INT64 NOT NULL,
ColFloat64 FLOAT64 NOT NULL,
ColFloat32 FLOAT32 NOT NULL,
ColBool BOOL NOT NULL,
ColString STRING(100) NOT NULL,
ColStringMax STRING(MAX) NOT NULL,
Expand All @@ -83,6 +84,7 @@ CREATE TABLE TableWithAllColumnTypes (

ColInt64Array ARRAY<INT64>,
ColFloat64Array ARRAY<FLOAT64>,
ColFloat32Array ARRAY<FLOAT32>,
ColBoolArray ARRAY<BOOL>,
ColStringArray ARRAY<STRING(100)>,
ColStringMaxArray ARRAY<STRING(MAX)>,
Expand All @@ -100,6 +102,7 @@ CREATE TABLE TableWithAllColumnTypes (
CREATE TABLE all_nullable_types (
ColInt64 INT64,
ColFloat64 FLOAT64,
ColFloat32 FLOAT32,
ColBool BOOL,
ColString STRING(100),
ColBytes BYTES(100),
Expand All @@ -110,6 +113,7 @@ CREATE TABLE all_nullable_types (

ColInt64Array ARRAY<INT64>,
ColFloat64Array ARRAY<FLOAT64>,
ColFloat32Array ARRAY<FLOAT32>,
ColBoolArray ARRAY<BOOL>,
ColStringArray ARRAY<STRING(100)>,
ColBytesArray ARRAY<BYTES(100)>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ CREATE TABLE Concerts (
CREATE TABLE TableWithAllColumnTypes (
ColInt64 BIGINT PRIMARY KEY,
ColFloat64 FLOAT8 NOT NULL,
ColFloat32 FLOAT4 NOT NULL,
ColBool BOOL NOT NULL,
ColString VARCHAR(100) NOT NULL,
ColStringMax TEXT,
Expand All @@ -83,6 +84,7 @@ CREATE TABLE TableWithAllColumnTypes (
CREATE TABLE all_nullable_types (
ColInt64 bigint primary key,
ColFloat64 float8,
ColFloat32 float4,
ColBool boolean,
ColString varchar(100),
ColBytes bytea,
Expand All @@ -93,6 +95,7 @@ CREATE TABLE all_nullable_types (

ColInt64Array bigint[],
ColFloat64Array float8[],
ColFloat32Array float4[],
ColBoolArray boolean[],
ColStringArray varchar(100)[],
ColBytesArray bytea[],
Expand Down
Loading