Skip to content

Commit 8d6d7b8

Browse files
authored
SQL: drop BASE TABLE type in favour for just TABLE (#54836) (#54951)
* Drop BASE TABLE type in favour for just TABLE This commit drops the table type 'BASE TABLE' and replaces all occurences with just 'TABLE', since his type is wider-used and friendlier to the client applications that query for certain table types in their discovery mode. The 'TABLE' type is also explicitely mentioned by the JDBC and ODBC standards and although other data source-specific types are permitted, older apps will not work well with them. * Refactor table type constants out of IndexType Move SQL_TABLE/_ALIAS out of IndexType, so that they can also be used in that Enum definition. (cherry picked from commit 70241b5)
1 parent 6853d73 commit 8d6d7b8

File tree

17 files changed

+124
-157
lines changed

17 files changed

+124
-157
lines changed

x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/index/IndexResolver.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,14 @@
7676
public class IndexResolver {
7777

7878
public enum IndexType {
79-
STANDARD_INDEX("BASE TABLE", "INDEX"),
80-
ALIAS("VIEW", "ALIAS"),
81-
FROZEN_INDEX("BASE TABLE", "FROZEN INDEX"),
79+
STANDARD_INDEX(SQL_TABLE, "INDEX"),
80+
ALIAS(SQL_VIEW, "ALIAS"),
81+
FROZEN_INDEX(SQL_TABLE, "FROZEN INDEX"),
8282
// value for user types unrecognized
8383
UNKNOWN("UNKNOWN", "UNKNOWN");
8484

85-
public static final String SQL_BASE_TABLE = "BASE TABLE";
86-
public static final String SQL_TABLE = "TABLE";
87-
public static final String SQL_VIEW = "VIEW";
88-
8985
public static final EnumSet<IndexType> VALID_INCLUDE_FROZEN = EnumSet.of(STANDARD_INDEX, ALIAS, FROZEN_INDEX);
9086
public static final EnumSet<IndexType> VALID_REGULAR = EnumSet.of(STANDARD_INDEX, ALIAS);
91-
public static final EnumSet<IndexType> INDICES_ONLY = EnumSet.of(STANDARD_INDEX, FROZEN_INDEX);
9287

9388
private final String toSql;
9489
private final String toNative;
@@ -150,6 +145,9 @@ public boolean equals(Object obj) {
150145
}
151146
}
152147

148+
public static final String SQL_TABLE = "TABLE";
149+
public static final String SQL_VIEW = "VIEW";
150+
153151
private static final IndicesOptions INDICES_ONLY_OPTIONS = new IndicesOptions(
154152
EnumSet.of(Option.ALLOW_NO_INDICES, Option.IGNORE_UNAVAILABLE, Option.IGNORE_ALIASES, Option.IGNORE_THROTTLED),
155153
EnumSet.of(WildcardStates.OPEN));

x-pack/plugin/sql/qa/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/RestSqlSecurityIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void expectShowTables(List<String> tables, String user) throws Exception
133133
for (String table : tables) {
134134
List<String> fields = new ArrayList<>();
135135
fields.add(table);
136-
fields.add("BASE TABLE");
136+
fields.add("TABLE");
137137
fields.add("INDEX");
138138
rows.add(fields);
139139
}

x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/DatabaseMetaDataTestCase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ public void testGetTypeOfTables() throws Exception {
9898

9999
CheckedSupplier<ResultSet, SQLException> all = () -> h2.createStatement()
100100
.executeQuery("SELECT '" + clusterName() + "' AS TABLE_CAT, * FROM mock");
101-
assertResultSets(all.get(), es.getMetaData().getTables("%", "%", "%", new String[] { "BASE TABLE" }));
101+
assertResultSets(all.get(), es.getMetaData().getTables("%", "%", "%", new String[] { "TABLE" }));
102102
assertResultSets(
103103
h2.createStatement()
104104
.executeQuery("SELECT '" + clusterName() + "' AS TABLE_CAT, * FROM mock WHERE TABLE_NAME = 'test1'"),
105-
es.getMetaData().getTables("%", "%", "test1", new String[] { "BASE TABLE" }));
105+
es.getMetaData().getTables("%", "%", "test1", new String[] { "TABLE" }));
106106
}
107107
}
108108

x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/ShowTablesTestCase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void testShowTablesWithManyIndices() throws Exception {
3030
for (int i = 0; i < indices; i++) {
3131
String index = String.format(Locale.ROOT, "test%02d", i);
3232
index(index, builder -> builder.field("name", "bob"));
33-
h2.createStatement().executeUpdate("INSERT INTO mock VALUES ('" + index + "', 'BASE TABLE', 'INDEX');");
33+
h2.createStatement().executeUpdate("INSERT INTO mock VALUES ('" + index + "', 'TABLE', 'INDEX');");
3434
}
3535

3636
ResultSet expected = h2.createStatement().executeQuery("SELECT * FROM mock ORDER BY name");
@@ -44,8 +44,8 @@ public void testEmptyIndex() throws Exception {
4444

4545
try (Connection h2 = LocalH2.anonymousDb(); Connection es = esJdbc()) {
4646
h2.createStatement().executeUpdate("RUNSCRIPT FROM 'classpath:/setup_mock_show_tables.sql'");
47-
h2.createStatement().executeUpdate("INSERT INTO mock VALUES ('test_empty', 'BASE TABLE', 'INDEX');");
48-
h2.createStatement().executeUpdate("INSERT INTO mock VALUES ('test_empty_again', 'BASE TABLE', 'INDEX');");
47+
h2.createStatement().executeUpdate("INSERT INTO mock VALUES ('test_empty', 'TABLE', 'INDEX');");
48+
h2.createStatement().executeUpdate("INSERT INTO mock VALUES ('test_empty_again', 'TABLE', 'INDEX');");
4949

5050
ResultSet expected = h2.createStatement().executeQuery("SELECT * FROM mock");
5151
assertResultSets(expected, es.createStatement().executeQuery("SHOW TABLES"));

x-pack/plugin/sql/qa/src/main/resources/alias.csv-spec

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ test_alias | VIEW | ALIAS
9494
showPattern
9595
SHOW TABLES LIKE 'test_%';
9696

97-
name:s | type:s | kind :s
97+
name:s | type:s | kind :s
9898

99-
test_alias | VIEW | ALIAS
100-
test_alias_emp | VIEW | ALIAS
101-
test_emp | BASE TABLE | INDEX
102-
test_emp_copy | BASE TABLE | INDEX
99+
test_alias | VIEW | ALIAS
100+
test_alias_emp | VIEW | ALIAS
101+
test_emp | TABLE | INDEX
102+
test_emp_copy | TABLE | INDEX
103103
;
104104

105105
groupByOnAlias

x-pack/plugin/sql/qa/src/main/resources/command.csv-spec

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -214,41 +214,41 @@ TODAY |SCALAR
214214
showTables
215215
SHOW TABLES;
216216

217-
name | type | kind
218-
logs |BASE TABLE |INDEX
219-
test_alias |VIEW |ALIAS
220-
test_alias_emp |VIEW |ALIAS
221-
test_emp |BASE TABLE |INDEX
222-
test_emp_copy |BASE TABLE |INDEX
217+
name | type | kind
218+
logs |TABLE |INDEX
219+
test_alias |VIEW |ALIAS
220+
test_alias_emp |VIEW |ALIAS
221+
test_emp |TABLE |INDEX
222+
test_emp_copy |TABLE |INDEX
223223
;
224224

225225
showTablesSimpleLike
226226
SHOW TABLES LIKE 'test_emp';
227227

228-
name:s | type:s | kind:s
229-
test_emp |BASE TABLE |INDEX
228+
name:s | type:s| kind:s
229+
test_emp |TABLE |INDEX
230230
;
231231

232232
showTablesMultiLike
233233
SHOW TABLES LIKE 'test_emp%';
234234

235-
name:s | type:s |kind:s
236-
test_emp |BASE TABLE |INDEX
237-
test_emp_copy |BASE TABLE |INDEX
235+
name:s |type:s |kind:s
236+
test_emp |TABLE |INDEX
237+
test_emp_copy |TABLE |INDEX
238238
;
239239

240240
showTablesIdentifier
241241
SHOW TABLES "test_emp";
242242

243-
name:s | type:s |kind:s
244-
test_emp |BASE TABLE |INDEX
243+
name:s |type:s |kind:s
244+
test_emp |TABLE |INDEX
245245
;
246246

247247
showTablesIdentifierPattern
248248
SHOW TABLES "test_e*,-test_emp";
249249

250-
name:s | type:s |kind:s
251-
test_emp_copy |BASE TABLE |INDEX
250+
name:s |type:s |kind:s
251+
test_emp_copy |TABLE |INDEX
252252
;
253253

254254
showTablesIdentifierPatternOnAliases

x-pack/plugin/sql/qa/src/main/resources/docs/docs.csv-spec

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ showTables
9595
// tag::showTables
9696
SHOW TABLES;
9797

98-
name | type | kind
99-
---------------+---------------+---------------
100-
emp |BASE TABLE |INDEX
101-
employees |VIEW |ALIAS
102-
library |BASE TABLE |INDEX
98+
name | type | kind
99+
---------------+----------+---------------
100+
emp |TABLE |INDEX
101+
employees |VIEW |ALIAS
102+
library |TABLE |INDEX
103103

104104
// end::showTables
105105
;
@@ -108,9 +108,9 @@ showTablesLikeExact
108108
// tag::showTablesLikeExact
109109
SHOW TABLES LIKE 'emp';
110110

111-
name | type | kind
112-
---------------+---------------+---------------
113-
emp |BASE TABLE |INDEX
111+
name | type | kind
112+
---------------+----------+---------------
113+
emp |TABLE |INDEX
114114

115115
// end::showTablesLikeExact
116116
;
@@ -119,10 +119,10 @@ showTablesLikeWildcard
119119
// tag::showTablesLikeWildcard
120120
SHOW TABLES LIKE 'emp%';
121121

122-
name | type | kind
123-
---------------+---------------+---------------
124-
emp |BASE TABLE |INDEX
125-
employees |VIEW |ALIAS
122+
name | type | kind
123+
---------------+----------+---------------
124+
emp |TABLE |INDEX
125+
employees |VIEW |ALIAS
126126

127127
// end::showTablesLikeWildcard
128128
;
@@ -132,9 +132,9 @@ showTablesLikeOneChar
132132
// tag::showTablesLikeOneChar
133133
SHOW TABLES LIKE 'em_';
134134

135-
name | type | kind
136-
---------------+---------------+---------------
137-
emp |BASE TABLE |INDEX
135+
name | type | kind
136+
---------------+----------+---------------
137+
emp |TABLE |INDEX
138138

139139
// end::showTablesLikeOneChar
140140
;
@@ -143,9 +143,9 @@ showTablesLikeMixed
143143
// tag::showTablesLikeMixed
144144
SHOW TABLES LIKE '%em_';
145145

146-
name | type | kind
147-
---------------+---------------+---------------
148-
emp |BASE TABLE |INDEX
146+
name | type | kind
147+
---------------+----------+---------------
148+
emp |TABLE |INDEX
149149

150150
// end::showTablesLikeMixed
151151
;
@@ -166,10 +166,10 @@ showTablesEsMultiIndex
166166
// tag::showTablesEsMultiIndex
167167
SHOW TABLES "*,-l*";
168168

169-
name | type | kind
170-
---------------+---------------+---------------
171-
emp |BASE TABLE |INDEX
172-
employees |VIEW |ALIAS
169+
name | type | kind
170+
---------------+----------+---------------
171+
emp |TABLE |INDEX
172+
employees |VIEW |ALIAS
173173

174174
// end::showTablesEsMultiIndex
175175
;
@@ -182,12 +182,12 @@ showTablesIncludeFrozen
182182
// tag::showTablesIncludeFrozen
183183
SHOW TABLES INCLUDE FROZEN;
184184

185-
name | type | kind
186-
---------------+---------------+---------------
187-
archive |BASE TABLE |FROZEN INDEX
188-
emp |BASE TABLE |INDEX
189-
employees |VIEW |ALIAS
190-
library |BASE TABLE |INDEX
185+
name | type | kind
186+
---------------+----------+---------------
187+
archive |TABLE |FROZEN INDEX
188+
emp |TABLE |INDEX
189+
employees |VIEW |ALIAS
190+
library |TABLE |INDEX
191191

192192
// end::showTablesIncludeFrozen
193193
;

x-pack/plugin/sql/qa/src/main/resources/geo/geosql.csv-spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
showTables
88
SHOW TABLES "geo";
99

10-
name:s | type:s | kind:s
11-
geo |BASE TABLE |INDEX
10+
name:s | type:s| kind:s
11+
geo |TABLE |INDEX
1212
;
1313

1414
// DESCRIBE

x-pack/plugin/sql/qa/src/main/resources/ogc/ogc.csv-spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
showTables
88
SHOW TABLES "ogc";
99

10-
name:s | type:s | kind:s
11-
ogc |BASE TABLE |INDEX
10+
name:s | type:s | kind:s
11+
ogc |TABLE |INDEX
1212
;
1313

1414
// DESCRIBE
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CREATE TABLE mock (
22
TABLE_TYPE VARCHAR,
33
) AS
4-
SELECT 'BASE TABLE' FROM DUAL
4+
SELECT 'TABLE' FROM DUAL
55
UNION ALL
66
SELECT 'VIEW' FROM DUAL
77
;

x-pack/plugin/sql/qa/src/main/resources/setup_mock_metadata_get_tables.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ CREATE TABLE mock (
99
SELF_REFERENCING_COL_NAME VARCHAR,
1010
REF_GENERATION VARCHAR
1111
) AS
12-
SELECT null, 'test1', 'BASE TABLE', '', null, null, null, null, null FROM DUAL
12+
SELECT null, 'test1', 'TABLE', '', null, null, null, null, null FROM DUAL
1313
UNION ALL
14-
SELECT null, 'test2', 'BASE TABLE', '', null, null, null, null, null FROM DUAL
14+
SELECT null, 'test2', 'TABLE', '', null, null, null, null, null FROM DUAL
1515
;

x-pack/plugin/sql/qa/src/main/resources/setup_mock_metadata_get_tables_empty.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ CREATE TABLE mock (
99
SELF_REFERENCING_COL_NAME VARCHAR,
1010
REF_GENERATION VARCHAR
1111
) AS
12-
SELECT null, 'test_empty', 'BASE TABLE', '', null, null, null, null, null FROM DUAL
12+
SELECT null, 'test_empty', 'TABLE', '', null, null, null, null, null FROM DUAL
1313
UNION ALL
14-
SELECT null, 'test_empty_again', 'BASE TABLE', '', null, null, null, null, null FROM DUAL
14+
SELECT null, 'test_empty_again', 'TABLE', '', null, null, null, null, null FROM DUAL
1515
;

x-pack/plugin/sql/qa/src/main/resources/setup_mock_metadata_get_types_of_table.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ CREATE TABLE mock (
99
SELF_REFERENCING_COL_NAME VARCHAR,
1010
REF_GENERATION VARCHAR
1111
) AS
12-
SELECT null, 'test1', 'BASE TABLE', '', null, null, null, null, null FROM DUAL
12+
SELECT null, 'test1', 'TABLE', '', null, null, null, null, null FROM DUAL
1313
UNION ALL
14-
SELECT null, 'test2', 'BASE TABLE', '', null, null, null, null, null FROM DUAL
14+
SELECT null, 'test2', 'TABLE', '', null, null, null, null, null FROM DUAL
1515
;

x-pack/plugin/sql/qa/src/main/resources/slow/frozen.csv-spec

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
showTables
88
SHOW TABLES INCLUDE FROZEN;
99

10-
name | type | kind
11-
frozen_emp |BASE TABLE |FROZEN INDEX
12-
logs |BASE TABLE |INDEX
13-
test_alias |VIEW |ALIAS
14-
test_alias_emp |VIEW |ALIAS
15-
test_emp |BASE TABLE |INDEX
16-
test_emp_copy |BASE TABLE |INDEX
10+
name | type | kind
11+
frozen_emp |TABLE |FROZEN INDEX
12+
logs |TABLE |INDEX
13+
test_alias |VIEW |ALIAS
14+
test_alias_emp |VIEW |ALIAS
15+
test_emp |TABLE |INDEX
16+
test_emp_copy |TABLE |INDEX
1717
;
1818

1919
columnFromFrozen

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/parser/CommandBuilder.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
import org.antlr.v4.runtime.Token;
99
import org.elasticsearch.common.Booleans;
10+
import org.elasticsearch.common.Strings;
1011
import org.elasticsearch.xpack.ql.expression.Literal;
12+
import org.elasticsearch.xpack.ql.index.IndexResolver;
1113
import org.elasticsearch.xpack.ql.index.IndexResolver.IndexType;
1214
import org.elasticsearch.xpack.ql.plan.TableIdentifier;
1315
import org.elasticsearch.xpack.ql.tree.Source;
@@ -143,27 +145,19 @@ public Object visitShowColumns(ShowColumnsContext ctx) {
143145
@Override
144146
public SysTables visitSysTables(SysTablesContext ctx) {
145147
List<IndexType> types = new ArrayList<>();
146-
boolean legacyTableType = false;
147148
for (StringContext string : ctx.string()) {
148149
String value = string(string);
149-
if (value != null && value.isEmpty() == false) {
150+
if (Strings.isEmpty(value) == false) {
150151
// check special ODBC wildcard case
151152
if (value.equals(StringUtils.SQL_WILDCARD) && ctx.string().size() == 1) {
152153
// treat % as null
153154
// https://docs.microsoft.com/en-us/sql/odbc/reference/develop-app/value-list-arguments
154-
}
155-
// special case for legacy apps (like msquery) that always asks for 'TABLE'
156-
// which we manually map to all concrete tables supported
157-
else {
155+
} else {
158156
switch (value.toUpperCase(Locale.ROOT)) {
159-
case IndexType.SQL_TABLE:
160-
legacyTableType = true;
161-
types.add(IndexType.STANDARD_INDEX);
162-
break;
163-
case IndexType.SQL_BASE_TABLE:
157+
case IndexResolver.SQL_TABLE:
164158
types.add(IndexType.STANDARD_INDEX);
165159
break;
166-
case IndexType.SQL_VIEW:
160+
case IndexResolver.SQL_VIEW:
167161
types.add(IndexType.ALIAS);
168162
break;
169163
default:
@@ -177,7 +171,7 @@ public SysTables visitSysTables(SysTablesContext ctx) {
177171
EnumSet<IndexType> set = types.isEmpty() ? null : EnumSet.copyOf(types);
178172
TableIdentifier ti = visitTableIdentifier(ctx.tableIdent);
179173
String index = ti != null ? ti.qualifiedIndex() : null;
180-
return new SysTables(source(ctx), visitLikePattern(ctx.clusterLike), index, visitLikePattern(ctx.tableLike), set, legacyTableType);
174+
return new SysTables(source(ctx), visitLikePattern(ctx.clusterLike), index, visitLikePattern(ctx.tableLike), set);
181175
}
182176

183177
@Override
@@ -198,4 +192,4 @@ public SysTypes visitSysTypes(SysTypesContext ctx) {
198192

199193
return new SysTypes(source(ctx), Integer.valueOf(type));
200194
}
201-
}
195+
}

0 commit comments

Comments
 (0)