diff --git a/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/jdbc/DatabaseMetaDataTestCase.java b/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/jdbc/DatabaseMetaDataTestCase.java index 4d785427ce7..f30722f6c40 100644 --- a/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/jdbc/DatabaseMetaDataTestCase.java +++ b/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/jdbc/DatabaseMetaDataTestCase.java @@ -76,6 +76,7 @@ public class DatabaseMetaDataTestCase extends JdbcIntegrationTestCase { index("test2", body -> { body.field("number", 7); body.field("date", "2017-01-01T01:01:01Z"); + body.field("float", 42.0); }); try (Connection h2 = LocalH2.anonymousDb(); diff --git a/qa/sql/src/main/resources/setup_mock_metadata_get_columns.sql b/qa/sql/src/main/resources/setup_mock_metadata_get_columns.sql index 6d221f6c135..1d1aef14a80 100644 --- a/qa/sql/src/main/resources/setup_mock_metadata_get_columns.sql +++ b/qa/sql/src/main/resources/setup_mock_metadata_get_columns.sql @@ -23,21 +23,23 @@ CREATE TABLE mock ( IS_AUTOINCREMENT VARCHAR, IS_GENERATEDCOLUMN VARCHAR ) AS -SELECT '', 'test1', 'name', 12, 'VARCHAR', 2147483647, null, null, - 10, -- TODO 10 seem wrong to hard code for non-numbers see https://github.com/elastic/x-pack-elasticsearch/issues/3085 +SELECT '', 'test1', 'name', 12, 'VARCHAR', 2147483647, null, null, null, 1, -- columnNullable null, null, null, null, null, 1, 'YES', null, null, null, null, '', '' FROM DUAL UNION ALL -SELECT '', 'test2', 'date', 93, 'TIMESTAMP', 19, null, null, - 10, +SELECT '', 'test2', 'date', 93, 'TIMESTAMP', 19, null, null, null, 1, -- columnNullable null, null, null, null, null, 1, 'YES', null, null, null, null, '', '' FROM DUAL UNION ALL -SELECT '', 'test2', 'number', -5, 'BIGINT', 19, null, null, - 10, +SELECT '', 'test2', 'float', 7, 'REAL', 7, null, null, 2, 1, -- columnNullable null, null, null, null, null, 2, 'YES', null, null, null, null, '', '' 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 ; diff --git a/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/jdbc/JdbcDatabaseMetaData.java b/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/jdbc/JdbcDatabaseMetaData.java index 0e87e4eb4e0..35af0b1f480 100644 --- a/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/jdbc/JdbcDatabaseMetaData.java +++ b/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/jdbc/JdbcDatabaseMetaData.java @@ -22,6 +22,8 @@ import java.sql.SQLFeatureNotSupportedException; import java.util.ArrayList; import java.util.List; +import static org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcUtils.numericPrecisionRadix; + /** * Implementation of {@link DatabaseMetaData} for Elasticsearch. Draws inspiration * from @@ -822,7 +824,7 @@ class JdbcDatabaseMetaData implements DatabaseMetaData, JdbcWrapper { row[ 6] = col.size; row[ 7] = null; row[ 8] = null; - row[ 9] = 10; + row[ 9] = numericPrecisionRadix(col.type.getVendorTypeNumber()); row[10] = columnNullable; row[11] = null; row[12] = null; diff --git a/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/jdbc/JdbcUtils.java b/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/jdbc/JdbcUtils.java index 0ee37e542a1..b27e0451d11 100644 --- a/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/jdbc/JdbcUtils.java +++ b/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/jdbc/JdbcUtils.java @@ -198,4 +198,22 @@ public abstract class JdbcUtils { static JDBCType type(int 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; + } + } } \ No newline at end of file