More JDBC improvements

properly return the precision for VARCHAR
ignore type when specified in index pattern

Original commit: elastic/x-pack-elasticsearch@71a5ac1812
This commit is contained in:
Costin Leau 2017-09-30 00:40:57 +03:00
parent cc66bbaa00
commit e0d02033de
6 changed files with 18 additions and 6 deletions

View File

@ -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));
}
}

View File

@ -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, '', ''

View File

@ -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));
}
}

View File

@ -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();

View File

@ -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;

View File

@ -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) {