SQL: Return proper NUM_PREC_RADIX for non-numeric types (elastic/x-pack-elasticsearch#3086)
NUM_PREC_RADIX should be 10 for integer types, 2 for rational types and null for everything else. relates elastic/x-pack-elasticsearch#3085 Original commit: elastic/x-pack-elasticsearch@81d5ee04b3
This commit is contained in:
parent
0cc153f6d3
commit
d5525f38f3
|
@ -76,6 +76,7 @@ public class DatabaseMetaDataTestCase extends JdbcIntegrationTestCase {
|
||||||
index("test2", body -> {
|
index("test2", body -> {
|
||||||
body.field("number", 7);
|
body.field("number", 7);
|
||||||
body.field("date", "2017-01-01T01:01:01Z");
|
body.field("date", "2017-01-01T01:01:01Z");
|
||||||
|
body.field("float", 42.0);
|
||||||
});
|
});
|
||||||
|
|
||||||
try (Connection h2 = LocalH2.anonymousDb();
|
try (Connection h2 = LocalH2.anonymousDb();
|
||||||
|
|
|
@ -23,21 +23,23 @@ CREATE TABLE mock (
|
||||||
IS_AUTOINCREMENT VARCHAR,
|
IS_AUTOINCREMENT VARCHAR,
|
||||||
IS_GENERATEDCOLUMN VARCHAR
|
IS_GENERATEDCOLUMN VARCHAR
|
||||||
) AS
|
) AS
|
||||||
SELECT '', 'test1', 'name', 12, 'VARCHAR', 2147483647, null, null,
|
SELECT '', 'test1', 'name', 12, 'VARCHAR', 2147483647, null, null, null,
|
||||||
10, -- TODO 10 seem wrong to hard code for non-numbers see https://github.com/elastic/x-pack-elasticsearch/issues/3085
|
|
||||||
1, -- columnNullable
|
1, -- columnNullable
|
||||||
null, null, null, null, null, 1, 'YES', 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, null,
|
||||||
10,
|
|
||||||
1, -- columnNullable
|
1, -- columnNullable
|
||||||
null, null, null, null, null, 1, 'YES', 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', 'float', 7, 'REAL', 7, null, null, 2,
|
||||||
10,
|
|
||||||
1, -- columnNullable
|
1, -- columnNullable
|
||||||
null, null, null, null, null, 2, 'YES', null, null, null, null, '', ''
|
null, null, null, null, null, 2, 'YES', null, null, null, null, '', ''
|
||||||
FROM DUAL
|
FROM DUAL
|
||||||
|
UNION ALL
|
||||||
|
SELECT '', 'test2', 'number', -5, 'BIGINT', 19, null, null, 10,
|
||||||
|
1, -- columnNullable
|
||||||
|
null, null, null, null, null, 3, 'YES', null, null, null, null, '', ''
|
||||||
|
FROM DUAL
|
||||||
;
|
;
|
||||||
|
|
|
@ -22,6 +22,8 @@ import java.sql.SQLFeatureNotSupportedException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcUtils.numericPrecisionRadix;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of {@link DatabaseMetaData} for Elasticsearch. Draws inspiration
|
* Implementation of {@link DatabaseMetaData} for Elasticsearch. Draws inspiration
|
||||||
* from <a href="https://www.postgresql.org/docs/9.0/static/information-schema.html">
|
* from <a href="https://www.postgresql.org/docs/9.0/static/information-schema.html">
|
||||||
|
@ -822,7 +824,7 @@ class JdbcDatabaseMetaData implements DatabaseMetaData, JdbcWrapper {
|
||||||
row[ 6] = col.size;
|
row[ 6] = col.size;
|
||||||
row[ 7] = null;
|
row[ 7] = null;
|
||||||
row[ 8] = null;
|
row[ 8] = null;
|
||||||
row[ 9] = 10;
|
row[ 9] = numericPrecisionRadix(col.type.getVendorTypeNumber());
|
||||||
row[10] = columnNullable;
|
row[10] = columnNullable;
|
||||||
row[11] = null;
|
row[11] = null;
|
||||||
row[12] = null;
|
row[12] = null;
|
||||||
|
|
|
@ -198,4 +198,22 @@ public abstract class JdbcUtils {
|
||||||
static JDBCType type(int jdbcType) {
|
static JDBCType type(int jdbcType) {
|
||||||
return JDBCType.valueOf(jdbcType);
|
return JDBCType.valueOf(jdbcType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Integer numericPrecisionRadix(int type) {
|
||||||
|
switch (type) {
|
||||||
|
case TINYINT:
|
||||||
|
case SMALLINT:
|
||||||
|
case INTEGER:
|
||||||
|
case BIGINT:
|
||||||
|
return 10;
|
||||||
|
case REAL:
|
||||||
|
case DOUBLE:
|
||||||
|
case FLOAT:
|
||||||
|
case DECIMAL:
|
||||||
|
case NUMERIC:
|
||||||
|
return 2;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue