Skip to content

Commit a824566

Browse files
committed
SQL: ignore UNSUPPORTED fields for JDBC and ODBC modes in 'SYS COLUMNS' (#39518)
* SYS COLUMNS will skip UNSUPPORTED field types in ODBC and JDBC, as well. NESTED and OBJECT types were already skipped in ODBC mode, now they are skipped in JDBC mode, as well. (cherry picked from commit 9e0df64)
1 parent ffd0828 commit a824566

File tree

5 files changed

+250
-26
lines changed

5 files changed

+250
-26
lines changed

docs/reference/sql/limitations.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ beta[]
99
=== Nested fields in `SYS COLUMNS` and `DESCRIBE TABLE`
1010

1111
{es} has a special type of relationship fields called `nested` fields. In {es-sql} they can be used by referencing their inner
12-
sub-fields. Even though `SYS COLUMNS` and `DESCRIBE TABLE` will still display them as having the type `NESTED`, they cannot
13-
be used in a query. One can only reference its sub-fields in the form:
12+
sub-fields. Even though `SYS COLUMNS` in non-driver mode (in the CLI and in REST calls) and `DESCRIBE TABLE` will still display
13+
them as having the type `NESTED`, they cannot be used in a query. One can only reference its sub-fields in the form:
1414

1515
[source, sql]
1616
--------------------------------------------------

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plan/logical/command/sys/SysColumns.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ private List<Attribute> output(boolean odbcCompatible) {
9797

9898
@Override
9999
public void execute(SqlSession session, ActionListener<SchemaRowSet> listener) {
100-
boolean isOdbcClient = session.configuration().mode() == Mode.ODBC;
101-
List<Attribute> output = output(isOdbcClient);
100+
Mode mode = session.configuration().mode();
101+
List<Attribute> output = output(mode == Mode.ODBC);
102102
String cluster = session.indexResolver().clusterName();
103103

104104
// bail-out early if the catalog is present but differs
@@ -115,16 +115,17 @@ public void execute(SqlSession session, ActionListener<SchemaRowSet> listener) {
115115
session.indexResolver().resolveAsSeparateMappings(idx, regex, ActionListener.wrap(esIndices -> {
116116
List<List<?>> rows = new ArrayList<>();
117117
for (EsIndex esIndex : esIndices) {
118-
fillInRows(cluster, esIndex.name(), esIndex.mapping(), null, rows, columnMatcher, isOdbcClient);
118+
fillInRows(cluster, esIndex.name(), esIndex.mapping(), null, rows, columnMatcher, mode);
119119
}
120120

121121
listener.onResponse(Rows.of(output, rows));
122122
}, listener::onFailure));
123123
}
124124

125125
static void fillInRows(String clusterName, String indexName, Map<String, EsField> mapping, String prefix, List<List<?>> rows,
126-
Pattern columnMatcher, boolean isOdbcClient) {
126+
Pattern columnMatcher, Mode mode) {
127127
int pos = 0;
128+
boolean isOdbcClient = mode == Mode.ODBC;
128129
for (Map.Entry<String, EsField> entry : mapping.entrySet()) {
129130
pos++; // JDBC is 1-based so we start with 1 here
130131

@@ -133,9 +134,8 @@ static void fillInRows(String clusterName, String indexName, Map<String, EsField
133134
EsField field = entry.getValue();
134135
DataType type = field.getDataType();
135136

136-
// skip the nested and object types only for ODBC
137-
// https://github.com/elastic/elasticsearch/issues/35376
138-
if (type.isPrimitive() || !isOdbcClient) {
137+
// skip the nested, object and unsupported types for JDBC and ODBC
138+
if (type.isPrimitive() || false == Mode.isDriver(mode)) {
139139
if (columnMatcher == null || columnMatcher.matcher(name).matches()) {
140140
rows.add(asList(clusterName,
141141
// schema is not supported
@@ -175,7 +175,7 @@ static void fillInRows(String clusterName, String indexName, Map<String, EsField
175175
}
176176
}
177177
if (field.getProperties() != null) {
178-
fillInRows(clusterName, indexName, field.getProperties(), name, rows, columnMatcher, isOdbcClient);
178+
fillInRows(clusterName, indexName, field.getProperties(), name, rows, columnMatcher, mode);
179179
}
180180
}
181181
}

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/type/DataType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public boolean isString() {
212212
}
213213

214214
public boolean isPrimitive() {
215-
return this != OBJECT && this != NESTED;
215+
return this != OBJECT && this != NESTED && this != UNSUPPORTED;
216216
}
217217

218218
public boolean isDateBased() {

0 commit comments

Comments
 (0)