Switch JDBC metadata to indicate all columns nullable (elastic/x-pack-elasticsearch#2835)

We were returning "nullability unknown" but in Elasticsearch all columns
are nullable.

Original commit: elastic/x-pack-elasticsearch@6ceae418ea
This commit is contained in:
Nik Everett 2017-11-04 23:28:49 +00:00 committed by GitHub
parent 00d30285e1
commit a211077554
2 changed files with 25 additions and 25 deletions

View File

@ -25,19 +25,19 @@ CREATE TABLE mock (
) AS ) AS
SELECT '', 'test1', 'name', 12, 'VARCHAR', 2147483647, null, null, SELECT '', 'test1', 'name', 12, 'VARCHAR', 2147483647, null, null,
10, -- NOCOMMIT 10 seem wrong to hard code for stuff like strings 10, -- NOCOMMIT 10 seem wrong to hard code for stuff like strings
2, -- columnNullableUnknown NOCOMMIT I think it'd be more correct to return columnNullable 1, -- columnNullable
null, null, null, null, null, 1, '', null, null, null, null, '', '' null, null, null, null, null, 1, 'YES', null, null, null, null, '', ''
FROM DUAL FROM DUAL
UNION ALL UNION ALL
SELECT '', 'test2', 'date', 93, 'TIMESTAMP', 19, null, null, SELECT '', 'test2', 'date', 93, 'TIMESTAMP', 19, null, null,
10, 10,
2, -- columnNullableUnknown NOCOMMIT I think it'd be more correct to return columnNullable 1, -- columnNullable
null, null, null, null, null, 1, '', null, null, null, null, '', '' null, null, null, null, null, 1, 'YES', null, null, null, null, '', ''
FROM DUAL FROM DUAL
UNION ALL UNION ALL
SELECT '', 'test2', 'number', -5, 'BIGINT', 19, null, null, SELECT '', 'test2', 'number', -5, 'BIGINT', 19, null, null,
10, 10,
2, -- columnNullableUnknown NOCOMMIT I think it'd be more correct to return columnNullable 1, -- columnNullable
null, null, null, null, null, 2, '', null, null, null, null, '', '' null, null, null, null, null, 2, 'YES', null, null, null, null, '', ''
FROM DUAL FROM DUAL
; ;

View File

@ -637,9 +637,9 @@ class JdbcDatabaseMetaData implements DatabaseMetaData, JdbcWrapper {
public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) throws SQLException { public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) throws SQLException {
return emptySet(con.cfg, return emptySet(con.cfg,
"ROUTINES", "ROUTINES",
"PROCEDURE_CAT", "PROCEDURE_CAT",
"PROCEDURE_SCHEM", "PROCEDURE_SCHEM",
"PROCEDURE_NAME", "PROCEDURE_NAME",
"NUM_INPUT_PARAMS", int.class, "NUM_INPUT_PARAMS", int.class,
"NUM_OUTPUT_PARAMS", int.class, "NUM_OUTPUT_PARAMS", int.class,
"NUM_RESULT_SETS", int.class, "NUM_RESULT_SETS", int.class,
@ -653,9 +653,9 @@ class JdbcDatabaseMetaData implements DatabaseMetaData, JdbcWrapper {
throws SQLException { throws SQLException {
return emptySet(con.cfg, return emptySet(con.cfg,
"PARAMETERS", "PARAMETERS",
"PROCEDURE_CAT", "PROCEDURE_CAT",
"PROCEDURE_SCHEM", "PROCEDURE_SCHEM",
"PROCEDURE_NAME", "PROCEDURE_NAME",
"COLUMN_NAME", "COLUMN_NAME",
"COLUMN_TYPE", short.class, "COLUMN_TYPE", short.class,
"DATA_TYPE", int.class, "DATA_TYPE", int.class,
@ -680,7 +680,7 @@ class JdbcDatabaseMetaData implements DatabaseMetaData, JdbcWrapper {
private String defaultCatalog() throws SQLException { private String defaultCatalog() throws SQLException {
return con.client.serverInfo().cluster; return con.client.serverInfo().cluster;
} }
private boolean isDefaultCatalog(String catalog) throws SQLException { private boolean isDefaultCatalog(String catalog) throws SQLException {
// null means catalog info is irrelevant // null means catalog info is irrelevant
// % means return all catalogs // % means return all catalogs
@ -699,16 +699,16 @@ class JdbcDatabaseMetaData implements DatabaseMetaData, JdbcWrapper {
public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException { public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException {
List<ColumnInfo> info = columnInfo("TABLES", List<ColumnInfo> info = columnInfo("TABLES",
"TABLE_CAT", //0 "TABLE_CAT", //0
"TABLE_SCHEM", //1 "TABLE_SCHEM", //1
"TABLE_NAME", //2 "TABLE_NAME", //2
"TABLE_TYPE", //3 "TABLE_TYPE", //3
"REMARKS", //4 "REMARKS", //4
"TYPE_CAT", //5 "TYPE_CAT", //5
"TYPE_SCHEM", //6 "TYPE_SCHEM", //6
"TYPE_NAME", //7 "TYPE_NAME", //7
"SELF_REFERENCING_COL_NAME", //8 "SELF_REFERENCING_COL_NAME", //8
"REF_GENERATION"); //9 "REF_GENERATION"); //9
// schema and catalogs are not being used, if these are specified return an empty result set // schema and catalogs are not being used, if these are specified return an empty result set
if (!isDefaultCatalog(catalog) || !isDefaultSchema(schemaPattern)) { if (!isDefaultCatalog(catalog) || !isDefaultSchema(schemaPattern)) {
return emptySet(con.cfg, info); return emptySet(con.cfg, info);
@ -739,7 +739,7 @@ class JdbcDatabaseMetaData implements DatabaseMetaData, JdbcWrapper {
public ResultSet getSchemas() throws SQLException { public ResultSet getSchemas() throws SQLException {
Object[][] data = { { "", defaultCatalog() } }; Object[][] data = { { "", defaultCatalog() } };
return memorySet(con.cfg, columnInfo("SCHEMATA", return memorySet(con.cfg, columnInfo("SCHEMATA",
"TABLE_SCHEM", "TABLE_SCHEM",
"TABLE_CATALOG"), data); "TABLE_CATALOG"), data);
} }
@ -812,7 +812,7 @@ class JdbcDatabaseMetaData implements DatabaseMetaData, JdbcWrapper {
data[i] = new Object[24]; data[i] = new Object[24];
Object[] row = data[i]; Object[] row = data[i];
MetaColumnInfo col = columns.get(i); MetaColumnInfo col = columns.get(i);
row[ 0] = cat; row[ 0] = cat;
row[ 1] = ""; row[ 1] = "";
row[ 2] = col.table; row[ 2] = col.table;
@ -823,14 +823,14 @@ class JdbcDatabaseMetaData implements DatabaseMetaData, JdbcWrapper {
row[ 7] = null; row[ 7] = null;
row[ 8] = null; row[ 8] = null;
row[ 9] = 10; row[ 9] = 10;
row[10] = columnNullableUnknown; row[10] = columnNullable;
row[11] = null; row[11] = null;
row[12] = null; row[12] = null;
row[13] = null; row[13] = null;
row[14] = null; row[14] = null;
row[15] = null; row[15] = null;
row[16] = col.position; row[16] = col.position;
row[17] = ""; row[17] = "YES";
row[18] = null; row[18] = null;
row[19] = null; row[19] = null;
row[20] = null; row[20] = null;
@ -1256,4 +1256,4 @@ class JdbcDatabaseMetaData implements DatabaseMetaData, JdbcWrapper {
return data.length; return data.length;
} }
} }
} }