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: report whether column is generated in JDBC metadata #291

Merged
merged 1 commit into from Dec 10, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -72,7 +72,10 @@ SELECT TABLE_CATALOG AS TABLE_CAT, TABLE_SCHEMA AS TABLE_SCHEM, TABLE_NAME, COLU
NULL AS SCOPE_TABLE,
NULL AS SOURCE_DATA_TYPE,
'NO' AS IS_AUTOINCREMENT,
'NO' AS IS_GENERATEDCOLUMN
CASE
WHEN (IS_GENERATED = 'NEVER') THEN 'NO'
ELSE 'YES'
END AS IS_GENERATEDCOLUMN
FROM INFORMATION_SCHEMA.COLUMNS C
WHERE UPPER(C.TABLE_CATALOG) LIKE ?
AND UPPER(C.TABLE_SCHEMA) LIKE ?
Expand Down
Expand Up @@ -25,6 +25,7 @@

import com.google.cloud.spanner.IntegrationTest;
import com.google.cloud.spanner.jdbc.ITAbstractJdbcTest;
import com.google.cloud.spanner.testing.EmulatorSpannerHelper;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
Expand Down Expand Up @@ -53,7 +54,8 @@ public class ITJdbcDatabaseMetaDataTest extends ITAbstractJdbcTest {

@BeforeClass
public static void skipOnEmulator() {
assumeFalse("foreign keys are not supported on the emulator", env.getTestHelper().isEmulator());
assumeFalse(
"foreign keys are not supported on the emulator", EmulatorSpannerHelper.isUsingEmulator());
}

@Override
Expand All @@ -70,6 +72,7 @@ private static final class Column {
private final Integer radix;
private final boolean nullable;
private final Integer charOctetLength;
private final boolean computed;

private Column(
String name,
Expand All @@ -80,6 +83,19 @@ private Column(
Integer radix,
boolean nullable,
Integer charOctetLength) {
this(name, type, typeName, colSize, decimalDigits, radix, nullable, charOctetLength, false);
}

private Column(
String name,
int type,
String typeName,
Integer colSize,
Integer decimalDigits,
Integer radix,
boolean nullable,
Integer charOctetLength,
boolean computed) {
this.name = name;
this.type = type;
this.typeName = typeName;
Expand All @@ -88,6 +104,7 @@ private Column(
this.radix = radix;
this.nullable = nullable;
this.charOctetLength = charOctetLength;
this.computed = computed;
}
}

Expand Down Expand Up @@ -133,7 +150,17 @@ private Column(
new Column("ColDateArray", Types.ARRAY, "ARRAY<DATE>", 10, null, null, true, null),
new Column(
"ColTimestampArray", Types.ARRAY, "ARRAY<TIMESTAMP>", 35, null, null, true, null),
new Column("ColNumericArray", Types.ARRAY, "ARRAY<NUMERIC>", 15, null, 10, true, null));
new Column("ColNumericArray", Types.ARRAY, "ARRAY<NUMERIC>", 15, null, 10, true, null),
new Column(
"ColComputed",
Types.NVARCHAR,
"STRING(MAX)",
2621440,
null,
null,
true,
2621440,
true));

@Test
public void testGetColumns() throws SQLException {
Expand Down Expand Up @@ -195,7 +222,7 @@ public void testGetColumns() throws SQLException {
assertThat(rs.getShort("SOURCE_DATA_TYPE"), is(equalTo((short) 0)));
assertThat(rs.wasNull(), is(true));
assertThat(rs.getString("IS_AUTOINCREMENT"), is(equalTo("NO")));
assertThat(rs.getString("IS_GENERATEDCOLUMN"), is(equalTo("NO")));
assertThat(rs.getString("IS_GENERATEDCOLUMN"), is(equalTo(col.computed ? "YES" : "NO")));
assertThat(rs.getMetaData().getColumnCount(), is(equalTo(24)));

pos++;
Expand Down
Expand Up @@ -84,7 +84,9 @@ CREATE TABLE TableWithAllColumnTypes (
ColBytesMaxArray ARRAY<BYTES(MAX)>,
ColDateArray ARRAY<DATE>,
ColTimestampArray ARRAY<TIMESTAMP>,
ColNumericArray ARRAY<NUMERIC>
ColNumericArray ARRAY<NUMERIC>,

ColComputed STRING(MAX) AS (CONCAT(COALESCE(ColString, ''), ' ', COALESCE(ColStringMax, ''))) STORED,
) PRIMARY KEY (ColInt64)
;

Expand Down