diff --git a/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/jdbc/DatabaseMetaDataIT.java b/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/jdbc/DatabaseMetaDataIT.java index 6da23f393ae..52a7cc42393 100644 --- a/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/jdbc/DatabaseMetaDataIT.java +++ b/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/jdbc/DatabaseMetaDataIT.java @@ -64,8 +64,8 @@ public class DatabaseMetaDataIT extends JdbcIntegrationTestCase { h2.createStatement().executeQuery("SELECT '" + clusterName() + "' AS TABLE_CAT, * FROM mock"); assertResultSets(expected.get(), es.getMetaData().getTables("%", "%", "%", null)); assertResultSets(expected.get(), es.getMetaData().getTables("%", "%", "te%", null)); - // NOCOMMIT with a wildcard type is broken: -// assertResultSets(expected.get(), es.getMetaData().getTables("%", "%", "test.d%", null)); + // types are stripped from the query so specifying them won't matter; H2 also doesn't support them + assertResultSets(expected.get(), es.getMetaData().getTables("%", "%", "test.d%", null)); } } 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 d3403f90ee2..56213737172 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 @@ -22,7 +22,7 @@ CREATE TABLE mock ( SOURCE_DATA_TYPE SMALLINT, IS_AUTOINCREMENT VARCHAR, IS_GENERATEDCOLUMN VARCHAR -) AS SELECT '', 'test', 'name', 12, 'VARCHAR', 1, null, null, +) AS SELECT '', 'test', 'name', 12, 'VARCHAR', 2147483647, null, null, 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 null, null, null, null, null, 1, '', null, null, null, null, '', '' diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlJdbcAction.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlJdbcAction.java index a3cf59a89a4..7a75239652e 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlJdbcAction.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlJdbcAction.java @@ -140,6 +140,7 @@ public class RestSqlJdbcAction extends AbstractSqlProtocolRestAction { String name = entry.getKey(); if (columnMatcher == null || columnMatcher.matcher(name).matches()) { DataType type = entry.getValue(); + // the column size it's actually its precision (based on the Javadocs) columns.add(new MetaColumnInfo(esIndex.name(), name, type.sqlType(), type.precision(), pos)); } } diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/session/RowSet.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/session/RowSet.java index bcf9a51439c..957ac5f2fec 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/session/RowSet.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/session/RowSet.java @@ -20,7 +20,8 @@ public interface RowSet extends RowView { boolean advanceRow(); - int size(); // NOCOMMIT why do we have this? It looks like the count of the rows in this chunk. + // number or rows in this set; while not really necessary (the return of advanceRow works) + int size(); void reset(); diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/type/JdbcUtils.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/type/JdbcUtils.java index e91cf3041db..0862f256e2f 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/type/JdbcUtils.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/type/JdbcUtils.java @@ -48,7 +48,9 @@ abstract class JdbcUtils { // 53 bits precision ~ 16(15.95) decimal digits (53log10(2)) case FLOAT: case DOUBLE: return 16; - case VARBINARY: return Integer.MAX_VALUE; + case VARBINARY: + case VARCHAR: + return Integer.MAX_VALUE; case TIME_WITH_TIMEZONE: return displaySize(type); default: return -1; diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/util/StringUtils.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/util/StringUtils.java index 4d4a3166579..4b70bd2f4cc 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/util/StringUtils.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/util/StringUtils.java @@ -161,7 +161,15 @@ public abstract class StringUtils { //TODO: likely this needs to be changed to probably its own indexNameResolver public static String jdbcToEsPattern(String sqlPattern) { - return Strings.hasText(sqlPattern) ? sqlPattern.replace('%', '*').replace('_', '*') : EMPTY; + if (Strings.hasText(sqlPattern)) { + // the index might include a type - since we only support only support one type per index, remove the type + int dotIndex = sqlPattern.indexOf("."); + if (dotIndex >= 0) { + sqlPattern = sqlPattern.substring(0, dotIndex); + } + return sqlPattern.replace('%', '*').replace('_', '*'); + } + return EMPTY; } public static String sqlToJavaPattern(CharSequence sqlPattern) {