SQL: Skip the nested and object field types in case of an ODBC request (#37948)

This commit is contained in:
Andrei Stefan 2019-01-30 11:34:47 +02:00 committed by GitHub
parent c8af0f4bfa
commit 908c8def06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 98 additions and 43 deletions

View File

@ -15,8 +15,8 @@ import org.elasticsearch.xpack.sql.proto.Mode;
import org.elasticsearch.xpack.sql.session.Rows;
import org.elasticsearch.xpack.sql.session.SchemaRowSet;
import org.elasticsearch.xpack.sql.session.SqlSession;
import org.elasticsearch.xpack.sql.tree.Source;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.tree.Source;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.type.DataTypes;
import org.elasticsearch.xpack.sql.type.EsField;
@ -133,6 +133,9 @@ public class SysColumns extends Command {
EsField field = entry.getValue();
DataType type = field.getDataType();
// skip the nested and object types only for ODBC
// https://github.com/elastic/elasticsearch/issues/35376
if (type.isPrimitive() || !isOdbcClient) {
if (columnMatcher == null || columnMatcher.matcher(name).matches()) {
rows.add(asList(clusterName,
// schema is not supported
@ -170,6 +173,7 @@ public class SysColumns extends Command {
"NO"
));
}
}
if (field.getProperties() != null) {
fillInRows(clusterName, indexName, field.getProperties(), name, rows, columnMatcher, isOdbcClient);
}

View File

@ -61,7 +61,7 @@ public class SysColumnsTests extends ESTestCase {
public void testSysColumnsInOdbcMode() {
List<List<?>> rows = new ArrayList<>();
SysColumns.fillInRows("test", "index", TypesTests.loadMapping("mapping-multi-field-variation.json", true), null, rows, null, true);
assertEquals(16, rows.size());
assertEquals(14, rows.size());
assertEquals(24, rows.get(0).size());
List<?> row = rows.get(0);
@ -90,6 +90,16 @@ public class SysColumnsTests extends ESTestCase {
assertEquals(Short.class, sqlDataType(row).getClass());
assertEquals(Short.class, sqlDataTypeSub(row).getClass());
row = rows.get(3);
assertEquals("keyword", name(row));
assertEquals((short) Types.VARCHAR, sqlType(row));
assertEquals(null, radix(row));
assertEquals(Integer.MAX_VALUE, bufferLength(row));
assertNull(decimalPrecision(row));
assertEquals(Short.class, nullable(row).getClass());
assertEquals(Short.class, sqlDataType(row).getClass());
assertEquals(Short.class, sqlDataTypeSub(row).getClass());
row = rows.get(4);
assertEquals("date", name(row));
assertEquals((short) Types.TIMESTAMP, sqlType(row));
@ -101,17 +111,58 @@ public class SysColumnsTests extends ESTestCase {
assertEquals(Short.class, sqlDataType(row).getClass());
assertEquals(Short.class, sqlDataTypeSub(row).getClass());
row = rows.get(7);
assertEquals("some.dotted", name(row));
assertEquals((short) Types.STRUCT, sqlType(row));
row = rows.get(5);
assertEquals("unsupported", name(row));
assertEquals((short) Types.OTHER, sqlType(row));
assertEquals(null, radix(row));
assertEquals(-1, bufferLength(row));
assertEquals(0, precision(row));
assertEquals(0, bufferLength(row));
assertNull(decimalPrecision(row));
assertEquals(Short.class, nullable(row).getClass());
assertEquals(Short.class, sqlDataType(row).getClass());
assertEquals(Short.class, sqlDataTypeSub(row).getClass());
row = rows.get(15);
row = rows.get(6);
assertEquals("some.dotted.field", name(row));
assertEquals((short) Types.VARCHAR, sqlType(row));
assertEquals(null, radix(row));
assertEquals(Integer.MAX_VALUE, bufferLength(row));
assertNull(decimalPrecision(row));
assertEquals(Short.class, nullable(row).getClass());
assertEquals(Short.class, sqlDataType(row).getClass());
assertEquals(Short.class, sqlDataTypeSub(row).getClass());
row = rows.get(7);
assertEquals("some.string", name(row));
assertEquals((short) Types.VARCHAR, sqlType(row));
assertEquals(null, radix(row));
assertEquals(Integer.MAX_VALUE, bufferLength(row));
assertNull(decimalPrecision(row));
assertEquals(Short.class, nullable(row).getClass());
assertEquals(Short.class, sqlDataType(row).getClass());
assertEquals(Short.class, sqlDataTypeSub(row).getClass());
row = rows.get(8);
assertEquals("some.string.normalized", name(row));
assertEquals((short) Types.VARCHAR, sqlType(row));
assertEquals(null, radix(row));
assertEquals(Integer.MAX_VALUE, bufferLength(row));
assertNull(decimalPrecision(row));
assertEquals(Short.class, nullable(row).getClass());
assertEquals(Short.class, sqlDataType(row).getClass());
assertEquals(Short.class, sqlDataTypeSub(row).getClass());
row = rows.get(9);
assertEquals("some.string.typical", name(row));
assertEquals((short) Types.VARCHAR, sqlType(row));
assertEquals(null, radix(row));
assertEquals(Integer.MAX_VALUE, bufferLength(row));
assertNull(decimalPrecision(row));
assertEquals(Short.class, nullable(row).getClass());
assertEquals(Short.class, sqlDataType(row).getClass());
assertEquals(Short.class, sqlDataTypeSub(row).getClass());
row = rows.get(13);
assertEquals("some.ambiguous.normalized", name(row));
assertEquals((short) Types.VARCHAR, sqlType(row));
assertEquals(null, radix(row));