SQL: Skip the nested and object field types in case of an ODBC request (#37948)
This commit is contained in:
parent
c8af0f4bfa
commit
908c8def06
|
@ -15,8 +15,8 @@ import org.elasticsearch.xpack.sql.proto.Mode;
|
||||||
import org.elasticsearch.xpack.sql.session.Rows;
|
import org.elasticsearch.xpack.sql.session.Rows;
|
||||||
import org.elasticsearch.xpack.sql.session.SchemaRowSet;
|
import org.elasticsearch.xpack.sql.session.SchemaRowSet;
|
||||||
import org.elasticsearch.xpack.sql.session.SqlSession;
|
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.NodeInfo;
|
||||||
|
import org.elasticsearch.xpack.sql.tree.Source;
|
||||||
import org.elasticsearch.xpack.sql.type.DataType;
|
import org.elasticsearch.xpack.sql.type.DataType;
|
||||||
import org.elasticsearch.xpack.sql.type.DataTypes;
|
import org.elasticsearch.xpack.sql.type.DataTypes;
|
||||||
import org.elasticsearch.xpack.sql.type.EsField;
|
import org.elasticsearch.xpack.sql.type.EsField;
|
||||||
|
@ -133,42 +133,46 @@ public class SysColumns extends Command {
|
||||||
EsField field = entry.getValue();
|
EsField field = entry.getValue();
|
||||||
DataType type = field.getDataType();
|
DataType type = field.getDataType();
|
||||||
|
|
||||||
if (columnMatcher == null || columnMatcher.matcher(name).matches()) {
|
// skip the nested and object types only for ODBC
|
||||||
rows.add(asList(clusterName,
|
// https://github.com/elastic/elasticsearch/issues/35376
|
||||||
// schema is not supported
|
if (type.isPrimitive() || !isOdbcClient) {
|
||||||
null,
|
if (columnMatcher == null || columnMatcher.matcher(name).matches()) {
|
||||||
indexName,
|
rows.add(asList(clusterName,
|
||||||
name,
|
// schema is not supported
|
||||||
odbcCompatible(type.sqlType.getVendorTypeNumber(), isOdbcClient),
|
null,
|
||||||
type.esType.toUpperCase(Locale.ROOT),
|
indexName,
|
||||||
type.displaySize,
|
name,
|
||||||
// TODO: is the buffer_length correct?
|
odbcCompatible(type.sqlType.getVendorTypeNumber(), isOdbcClient),
|
||||||
type.size,
|
type.esType.toUpperCase(Locale.ROOT),
|
||||||
// no DECIMAL support
|
type.displaySize,
|
||||||
null,
|
// TODO: is the buffer_length correct?
|
||||||
odbcCompatible(DataTypes.metaSqlRadix(type), isOdbcClient),
|
type.size,
|
||||||
// everything is nullable
|
// no DECIMAL support
|
||||||
odbcCompatible(DatabaseMetaData.columnNullable, isOdbcClient),
|
null,
|
||||||
// no remarks
|
odbcCompatible(DataTypes.metaSqlRadix(type), isOdbcClient),
|
||||||
null,
|
// everything is nullable
|
||||||
// no column def
|
odbcCompatible(DatabaseMetaData.columnNullable, isOdbcClient),
|
||||||
null,
|
// no remarks
|
||||||
// SQL_DATA_TYPE apparently needs to be same as DATA_TYPE except for datetime and interval data types
|
null,
|
||||||
odbcCompatible(DataTypes.metaSqlDataType(type), isOdbcClient),
|
// no column def
|
||||||
// SQL_DATETIME_SUB ?
|
null,
|
||||||
odbcCompatible(DataTypes.metaSqlDateTimeSub(type), isOdbcClient),
|
// SQL_DATA_TYPE apparently needs to be same as DATA_TYPE except for datetime and interval data types
|
||||||
// char octet length
|
odbcCompatible(DataTypes.metaSqlDataType(type), isOdbcClient),
|
||||||
type.isString() || type == DataType.BINARY ? type.size : null,
|
// SQL_DATETIME_SUB ?
|
||||||
// position
|
odbcCompatible(DataTypes.metaSqlDateTimeSub(type), isOdbcClient),
|
||||||
pos,
|
// char octet length
|
||||||
"YES",
|
type.isString() || type == DataType.BINARY ? type.size : null,
|
||||||
null,
|
// position
|
||||||
null,
|
pos,
|
||||||
null,
|
"YES",
|
||||||
null,
|
null,
|
||||||
"NO",
|
null,
|
||||||
"NO"
|
null,
|
||||||
));
|
null,
|
||||||
|
"NO",
|
||||||
|
"NO"
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (field.getProperties() != null) {
|
if (field.getProperties() != null) {
|
||||||
fillInRows(clusterName, indexName, field.getProperties(), name, rows, columnMatcher, isOdbcClient);
|
fillInRows(clusterName, indexName, field.getProperties(), name, rows, columnMatcher, isOdbcClient);
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class SysColumnsTests extends ESTestCase {
|
||||||
public void testSysColumnsInOdbcMode() {
|
public void testSysColumnsInOdbcMode() {
|
||||||
List<List<?>> rows = new ArrayList<>();
|
List<List<?>> rows = new ArrayList<>();
|
||||||
SysColumns.fillInRows("test", "index", TypesTests.loadMapping("mapping-multi-field-variation.json", true), null, rows, null, true);
|
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());
|
assertEquals(24, rows.get(0).size());
|
||||||
|
|
||||||
List<?> row = rows.get(0);
|
List<?> row = rows.get(0);
|
||||||
|
@ -90,6 +90,16 @@ public class SysColumnsTests extends ESTestCase {
|
||||||
assertEquals(Short.class, sqlDataType(row).getClass());
|
assertEquals(Short.class, sqlDataType(row).getClass());
|
||||||
assertEquals(Short.class, sqlDataTypeSub(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);
|
row = rows.get(4);
|
||||||
assertEquals("date", name(row));
|
assertEquals("date", name(row));
|
||||||
assertEquals((short) Types.TIMESTAMP, sqlType(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, sqlDataType(row).getClass());
|
||||||
assertEquals(Short.class, sqlDataTypeSub(row).getClass());
|
assertEquals(Short.class, sqlDataTypeSub(row).getClass());
|
||||||
|
|
||||||
row = rows.get(7);
|
row = rows.get(5);
|
||||||
assertEquals("some.dotted", name(row));
|
assertEquals("unsupported", name(row));
|
||||||
assertEquals((short) Types.STRUCT, sqlType(row));
|
assertEquals((short) Types.OTHER, sqlType(row));
|
||||||
assertEquals(null, radix(row));
|
assertEquals(null, radix(row));
|
||||||
assertEquals(-1, bufferLength(row));
|
assertEquals(0, precision(row));
|
||||||
|
assertEquals(0, bufferLength(row));
|
||||||
assertNull(decimalPrecision(row));
|
assertNull(decimalPrecision(row));
|
||||||
assertEquals(Short.class, nullable(row).getClass());
|
assertEquals(Short.class, nullable(row).getClass());
|
||||||
assertEquals(Short.class, sqlDataType(row).getClass());
|
assertEquals(Short.class, sqlDataType(row).getClass());
|
||||||
assertEquals(Short.class, sqlDataTypeSub(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("some.ambiguous.normalized", name(row));
|
||||||
assertEquals((short) Types.VARCHAR, sqlType(row));
|
assertEquals((short) Types.VARCHAR, sqlType(row));
|
||||||
assertEquals(null, radix(row));
|
assertEquals(null, radix(row));
|
||||||
|
|
Loading…
Reference in New Issue