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 70241b52697ac2cf71004040042123c1ec050299)
This commit is contained in:
Bogdan Pintea 2020-04-08 16:02:12 +02:00 committed by GitHub
parent 6853d73e88
commit 8d6d7b88d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 124 additions and 157 deletions

View File

@ -76,19 +76,14 @@ import static org.elasticsearch.xpack.ql.type.DataTypes.UNSUPPORTED;
public class IndexResolver {
public enum IndexType {
STANDARD_INDEX("BASE TABLE", "INDEX"),
ALIAS("VIEW", "ALIAS"),
FROZEN_INDEX("BASE TABLE", "FROZEN INDEX"),
STANDARD_INDEX(SQL_TABLE, "INDEX"),
ALIAS(SQL_VIEW, "ALIAS"),
FROZEN_INDEX(SQL_TABLE, "FROZEN INDEX"),
// value for user types unrecognized
UNKNOWN("UNKNOWN", "UNKNOWN");
public static final String SQL_BASE_TABLE = "BASE TABLE";
public static final String SQL_TABLE = "TABLE";
public static final String SQL_VIEW = "VIEW";
public static final EnumSet<IndexType> VALID_INCLUDE_FROZEN = EnumSet.of(STANDARD_INDEX, ALIAS, FROZEN_INDEX);
public static final EnumSet<IndexType> VALID_REGULAR = EnumSet.of(STANDARD_INDEX, ALIAS);
public static final EnumSet<IndexType> INDICES_ONLY = EnumSet.of(STANDARD_INDEX, FROZEN_INDEX);
private final String toSql;
private final String toNative;
@ -150,6 +145,9 @@ public class IndexResolver {
}
}
public static final String SQL_TABLE = "TABLE";
public static final String SQL_VIEW = "VIEW";
private static final IndicesOptions INDICES_ONLY_OPTIONS = new IndicesOptions(
EnumSet.of(Option.ALLOW_NO_INDICES, Option.IGNORE_UNAVAILABLE, Option.IGNORE_ALIASES, Option.IGNORE_THROTTLED),
EnumSet.of(WildcardStates.OPEN));

View File

@ -133,7 +133,7 @@ public class RestSqlSecurityIT extends SqlSecurityTestCase {
for (String table : tables) {
List<String> fields = new ArrayList<>();
fields.add(table);
fields.add("BASE TABLE");
fields.add("TABLE");
fields.add("INDEX");
rows.add(fields);
}

View File

@ -98,11 +98,11 @@ public class DatabaseMetaDataTestCase extends JdbcIntegrationTestCase {
CheckedSupplier<ResultSet, SQLException> all = () -> h2.createStatement()
.executeQuery("SELECT '" + clusterName() + "' AS TABLE_CAT, * FROM mock");
assertResultSets(all.get(), es.getMetaData().getTables("%", "%", "%", new String[] { "BASE TABLE" }));
assertResultSets(all.get(), es.getMetaData().getTables("%", "%", "%", new String[] { "TABLE" }));
assertResultSets(
h2.createStatement()
.executeQuery("SELECT '" + clusterName() + "' AS TABLE_CAT, * FROM mock WHERE TABLE_NAME = 'test1'"),
es.getMetaData().getTables("%", "%", "test1", new String[] { "BASE TABLE" }));
es.getMetaData().getTables("%", "%", "test1", new String[] { "TABLE" }));
}
}

View File

@ -30,7 +30,7 @@ public class ShowTablesTestCase extends JdbcIntegrationTestCase {
for (int i = 0; i < indices; i++) {
String index = String.format(Locale.ROOT, "test%02d", i);
index(index, builder -> builder.field("name", "bob"));
h2.createStatement().executeUpdate("INSERT INTO mock VALUES ('" + index + "', 'BASE TABLE', 'INDEX');");
h2.createStatement().executeUpdate("INSERT INTO mock VALUES ('" + index + "', 'TABLE', 'INDEX');");
}
ResultSet expected = h2.createStatement().executeQuery("SELECT * FROM mock ORDER BY name");
@ -44,8 +44,8 @@ public class ShowTablesTestCase extends JdbcIntegrationTestCase {
try (Connection h2 = LocalH2.anonymousDb(); Connection es = esJdbc()) {
h2.createStatement().executeUpdate("RUNSCRIPT FROM 'classpath:/setup_mock_show_tables.sql'");
h2.createStatement().executeUpdate("INSERT INTO mock VALUES ('test_empty', 'BASE TABLE', 'INDEX');");
h2.createStatement().executeUpdate("INSERT INTO mock VALUES ('test_empty_again', 'BASE TABLE', 'INDEX');");
h2.createStatement().executeUpdate("INSERT INTO mock VALUES ('test_empty', 'TABLE', 'INDEX');");
h2.createStatement().executeUpdate("INSERT INTO mock VALUES ('test_empty_again', 'TABLE', 'INDEX');");
ResultSet expected = h2.createStatement().executeQuery("SELECT * FROM mock");
assertResultSets(expected, es.createStatement().executeQuery("SHOW TABLES"));

View File

@ -94,12 +94,12 @@ test_alias | VIEW | ALIAS
showPattern
SHOW TABLES LIKE 'test_%';
name:s | type:s | kind :s
name:s | type:s | kind :s
test_alias | VIEW | ALIAS
test_alias_emp | VIEW | ALIAS
test_emp | BASE TABLE | INDEX
test_emp_copy | BASE TABLE | INDEX
test_alias | VIEW | ALIAS
test_alias_emp | VIEW | ALIAS
test_emp | TABLE | INDEX
test_emp_copy | TABLE | INDEX
;
groupByOnAlias

View File

@ -214,41 +214,41 @@ TODAY |SCALAR
showTables
SHOW TABLES;
name | type | kind
logs |BASE TABLE |INDEX
test_alias |VIEW |ALIAS
test_alias_emp |VIEW |ALIAS
test_emp |BASE TABLE |INDEX
test_emp_copy |BASE TABLE |INDEX
name | type | kind
logs |TABLE |INDEX
test_alias |VIEW |ALIAS
test_alias_emp |VIEW |ALIAS
test_emp |TABLE |INDEX
test_emp_copy |TABLE |INDEX
;
showTablesSimpleLike
SHOW TABLES LIKE 'test_emp';
name:s | type:s | kind:s
test_emp |BASE TABLE |INDEX
name:s | type:s| kind:s
test_emp |TABLE |INDEX
;
showTablesMultiLike
SHOW TABLES LIKE 'test_emp%';
name:s | type:s |kind:s
test_emp |BASE TABLE |INDEX
test_emp_copy |BASE TABLE |INDEX
name:s |type:s |kind:s
test_emp |TABLE |INDEX
test_emp_copy |TABLE |INDEX
;
showTablesIdentifier
SHOW TABLES "test_emp";
name:s | type:s |kind:s
test_emp |BASE TABLE |INDEX
name:s |type:s |kind:s
test_emp |TABLE |INDEX
;
showTablesIdentifierPattern
SHOW TABLES "test_e*,-test_emp";
name:s | type:s |kind:s
test_emp_copy |BASE TABLE |INDEX
name:s |type:s |kind:s
test_emp_copy |TABLE |INDEX
;
showTablesIdentifierPatternOnAliases

View File

@ -95,11 +95,11 @@ showTables
// tag::showTables
SHOW TABLES;
name | type | kind
---------------+---------------+---------------
emp |BASE TABLE |INDEX
employees |VIEW |ALIAS
library |BASE TABLE |INDEX
name | type | kind
---------------+----------+---------------
emp |TABLE |INDEX
employees |VIEW |ALIAS
library |TABLE |INDEX
// end::showTables
;
@ -108,9 +108,9 @@ showTablesLikeExact
// tag::showTablesLikeExact
SHOW TABLES LIKE 'emp';
name | type | kind
---------------+---------------+---------------
emp |BASE TABLE |INDEX
name | type | kind
---------------+----------+---------------
emp |TABLE |INDEX
// end::showTablesLikeExact
;
@ -119,10 +119,10 @@ showTablesLikeWildcard
// tag::showTablesLikeWildcard
SHOW TABLES LIKE 'emp%';
name | type | kind
---------------+---------------+---------------
emp |BASE TABLE |INDEX
employees |VIEW |ALIAS
name | type | kind
---------------+----------+---------------
emp |TABLE |INDEX
employees |VIEW |ALIAS
// end::showTablesLikeWildcard
;
@ -132,9 +132,9 @@ showTablesLikeOneChar
// tag::showTablesLikeOneChar
SHOW TABLES LIKE 'em_';
name | type | kind
---------------+---------------+---------------
emp |BASE TABLE |INDEX
name | type | kind
---------------+----------+---------------
emp |TABLE |INDEX
// end::showTablesLikeOneChar
;
@ -143,9 +143,9 @@ showTablesLikeMixed
// tag::showTablesLikeMixed
SHOW TABLES LIKE '%em_';
name | type | kind
---------------+---------------+---------------
emp |BASE TABLE |INDEX
name | type | kind
---------------+----------+---------------
emp |TABLE |INDEX
// end::showTablesLikeMixed
;
@ -166,10 +166,10 @@ showTablesEsMultiIndex
// tag::showTablesEsMultiIndex
SHOW TABLES "*,-l*";
name | type | kind
---------------+---------------+---------------
emp |BASE TABLE |INDEX
employees |VIEW |ALIAS
name | type | kind
---------------+----------+---------------
emp |TABLE |INDEX
employees |VIEW |ALIAS
// end::showTablesEsMultiIndex
;
@ -182,12 +182,12 @@ showTablesIncludeFrozen
// tag::showTablesIncludeFrozen
SHOW TABLES INCLUDE FROZEN;
name | type | kind
---------------+---------------+---------------
archive |BASE TABLE |FROZEN INDEX
emp |BASE TABLE |INDEX
employees |VIEW |ALIAS
library |BASE TABLE |INDEX
name | type | kind
---------------+----------+---------------
archive |TABLE |FROZEN INDEX
emp |TABLE |INDEX
employees |VIEW |ALIAS
library |TABLE |INDEX
// end::showTablesIncludeFrozen
;

View File

@ -7,8 +7,8 @@
showTables
SHOW TABLES "geo";
name:s | type:s | kind:s
geo |BASE TABLE |INDEX
name:s | type:s| kind:s
geo |TABLE |INDEX
;
// DESCRIBE

View File

@ -7,8 +7,8 @@
showTables
SHOW TABLES "ogc";
name:s | type:s | kind:s
ogc |BASE TABLE |INDEX
name:s | type:s | kind:s
ogc |TABLE |INDEX
;
// DESCRIBE

View File

@ -1,7 +1,7 @@
CREATE TABLE mock (
TABLE_TYPE VARCHAR,
) AS
SELECT 'BASE TABLE' FROM DUAL
SELECT 'TABLE' FROM DUAL
UNION ALL
SELECT 'VIEW' FROM DUAL
;

View File

@ -9,7 +9,7 @@ CREATE TABLE mock (
SELF_REFERENCING_COL_NAME VARCHAR,
REF_GENERATION VARCHAR
) AS
SELECT null, 'test1', 'BASE TABLE', '', null, null, null, null, null FROM DUAL
SELECT null, 'test1', 'TABLE', '', null, null, null, null, null FROM DUAL
UNION ALL
SELECT null, 'test2', 'BASE TABLE', '', null, null, null, null, null FROM DUAL
SELECT null, 'test2', 'TABLE', '', null, null, null, null, null FROM DUAL
;

View File

@ -9,7 +9,7 @@ CREATE TABLE mock (
SELF_REFERENCING_COL_NAME VARCHAR,
REF_GENERATION VARCHAR
) AS
SELECT null, 'test_empty', 'BASE TABLE', '', null, null, null, null, null FROM DUAL
SELECT null, 'test_empty', 'TABLE', '', null, null, null, null, null FROM DUAL
UNION ALL
SELECT null, 'test_empty_again', 'BASE TABLE', '', null, null, null, null, null FROM DUAL
SELECT null, 'test_empty_again', 'TABLE', '', null, null, null, null, null FROM DUAL
;

View File

@ -9,7 +9,7 @@ CREATE TABLE mock (
SELF_REFERENCING_COL_NAME VARCHAR,
REF_GENERATION VARCHAR
) AS
SELECT null, 'test1', 'BASE TABLE', '', null, null, null, null, null FROM DUAL
SELECT null, 'test1', 'TABLE', '', null, null, null, null, null FROM DUAL
UNION ALL
SELECT null, 'test2', 'BASE TABLE', '', null, null, null, null, null FROM DUAL
SELECT null, 'test2', 'TABLE', '', null, null, null, null, null FROM DUAL
;

View File

@ -7,13 +7,13 @@
showTables
SHOW TABLES INCLUDE FROZEN;
name | type | kind
frozen_emp |BASE TABLE |FROZEN INDEX
logs |BASE TABLE |INDEX
test_alias |VIEW |ALIAS
test_alias_emp |VIEW |ALIAS
test_emp |BASE TABLE |INDEX
test_emp_copy |BASE TABLE |INDEX
name | type | kind
frozen_emp |TABLE |FROZEN INDEX
logs |TABLE |INDEX
test_alias |VIEW |ALIAS
test_alias_emp |VIEW |ALIAS
test_emp |TABLE |INDEX
test_emp_copy |TABLE |INDEX
;
columnFromFrozen

View File

@ -7,7 +7,9 @@ package org.elasticsearch.xpack.sql.parser;
import org.antlr.v4.runtime.Token;
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.Strings;
import org.elasticsearch.xpack.ql.expression.Literal;
import org.elasticsearch.xpack.ql.index.IndexResolver;
import org.elasticsearch.xpack.ql.index.IndexResolver.IndexType;
import org.elasticsearch.xpack.ql.plan.TableIdentifier;
import org.elasticsearch.xpack.ql.tree.Source;
@ -143,27 +145,19 @@ abstract class CommandBuilder extends LogicalPlanBuilder {
@Override
public SysTables visitSysTables(SysTablesContext ctx) {
List<IndexType> types = new ArrayList<>();
boolean legacyTableType = false;
for (StringContext string : ctx.string()) {
String value = string(string);
if (value != null && value.isEmpty() == false) {
if (Strings.isEmpty(value) == false) {
// check special ODBC wildcard case
if (value.equals(StringUtils.SQL_WILDCARD) && ctx.string().size() == 1) {
// treat % as null
// https://docs.microsoft.com/en-us/sql/odbc/reference/develop-app/value-list-arguments
}
// special case for legacy apps (like msquery) that always asks for 'TABLE'
// which we manually map to all concrete tables supported
else {
} else {
switch (value.toUpperCase(Locale.ROOT)) {
case IndexType.SQL_TABLE:
legacyTableType = true;
case IndexResolver.SQL_TABLE:
types.add(IndexType.STANDARD_INDEX);
break;
case IndexType.SQL_BASE_TABLE:
types.add(IndexType.STANDARD_INDEX);
break;
case IndexType.SQL_VIEW:
case IndexResolver.SQL_VIEW:
types.add(IndexType.ALIAS);
break;
default:
@ -177,7 +171,7 @@ abstract class CommandBuilder extends LogicalPlanBuilder {
EnumSet<IndexType> set = types.isEmpty() ? null : EnumSet.copyOf(types);
TableIdentifier ti = visitTableIdentifier(ctx.tableIdent);
String index = ti != null ? ti.qualifiedIndex() : null;
return new SysTables(source(ctx), visitLikePattern(ctx.clusterLike), index, visitLikePattern(ctx.tableLike), set, legacyTableType);
return new SysTables(source(ctx), visitLikePattern(ctx.clusterLike), index, visitLikePattern(ctx.tableLike), set);
}
@Override
@ -198,4 +192,4 @@ abstract class CommandBuilder extends LogicalPlanBuilder {
return new SysTypes(source(ctx), Integer.valueOf(type));
}
}
}

View File

@ -36,22 +36,18 @@ public class SysTables extends Command {
private final LikePattern pattern;
private final LikePattern clusterPattern;
private final EnumSet<IndexType> types;
// flag indicating whether tables are reported as `TABLE` or `BASE TABLE`
private final boolean legacyTableTypes;
public SysTables(Source source, LikePattern clusterPattern, String index, LikePattern pattern, EnumSet<IndexType> types,
boolean legacyTableTypes) {
public SysTables(Source source, LikePattern clusterPattern, String index, LikePattern pattern, EnumSet<IndexType> types) {
super(source);
this.clusterPattern = clusterPattern;
this.index = index;
this.pattern = pattern;
this.types = types;
this.legacyTableTypes = legacyTableTypes;
}
@Override
protected NodeInfo<SysTables> info() {
return NodeInfo.create(this, SysTables::new, clusterPattern, index, pattern, types, legacyTableTypes);
return NodeInfo.create(this, SysTables::new, clusterPattern, index, pattern, types);
}
@Override
@ -89,7 +85,7 @@ public class SysTables extends Command {
return;
}
}
boolean includeFrozen = session.configuration().includeFrozen();
// enumerate types
@ -102,7 +98,7 @@ public class SysTables extends Command {
List<List<?>> values = new ArrayList<>();
// send only the types, everything else is made of empty strings
// NB: since the types are sent in SQL, frozen doesn't have to be taken into account since
// it's just another BASE TABLE
// it's just another TABLE
Set<IndexType> typeSet = IndexType.VALID_REGULAR;
for (IndexType type : typeSet) {
Object[] enumeration = new Object[10];
@ -142,13 +138,13 @@ public class SysTables extends Command {
session.indexResolver().resolveNames(idx, regex, tableTypes, ActionListener.wrap(result -> listener.onResponse(
of(session, result.stream()
// sort by type (which might be legacy), then by name
.sorted(Comparator.<IndexInfo, String> comparing(i -> legacyName(i.type()))
// sort by type, then by name
.sorted(Comparator.<IndexInfo, String> comparing(i -> i.type().toSql())
.thenComparing(Comparator.comparing(i -> i.name())))
.map(t -> asList(cluster,
null,
t.name(),
legacyName(t.type()),
t.type().toSql(),
EMPTY,
null,
null,
@ -159,10 +155,6 @@ public class SysTables extends Command {
, listener::onFailure));
}
private String legacyName(IndexType indexType) {
return legacyTableTypes && IndexType.INDICES_ONLY.contains(indexType) ? IndexType.SQL_TABLE : indexType.toSql();
}
@Override
public int hashCode() {
return Objects.hash(clusterPattern, index, pattern, types);
@ -184,4 +176,4 @@ public class SysTables extends Command {
&& Objects.equals(pattern, other.pattern)
&& Objects.equals(types, other.types);
}
}
}

View File

@ -41,6 +41,8 @@ import java.util.function.Consumer;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.elasticsearch.action.ActionListener.wrap;
import static org.elasticsearch.xpack.ql.index.IndexResolver.SQL_TABLE;
import static org.elasticsearch.xpack.ql.index.IndexResolver.SQL_VIEW;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
@ -105,9 +107,9 @@ public class SysTablesTests extends ESTestCase {
public void testSysTablesTypesEnumerationWoString() throws Exception {
executeCommand("SYS TABLES CATALOG LIKE '' LIKE '' ", r -> {
assertEquals(2, r.size());
assertEquals("BASE TABLE", r.column(3));
assertEquals(SQL_TABLE, r.column(3));
assertTrue(r.advanceRow());
assertEquals("VIEW", r.column(3));
assertEquals(SQL_VIEW, r.column(3));
}, alias, index);
}
@ -150,10 +152,10 @@ public class SysTablesTests extends ESTestCase {
executeCommand("SYS TABLES", r -> {
assertEquals(2, r.size());
assertEquals("test", r.column(2));
assertEquals("BASE TABLE", r.column(3));
assertEquals(SQL_TABLE, r.column(3));
assertTrue(r.advanceRow());
assertEquals("alias", r.column(2));
assertEquals("VIEW", r.column(3));
assertEquals(SQL_VIEW, r.column(3));
}, index, alias);
}
@ -161,49 +163,38 @@ public class SysTablesTests extends ESTestCase {
executeCommand("SYS TABLES", r -> {
assertEquals(3, r.size());
assertEquals("frozen", r.column(2));
assertEquals("BASE TABLE", r.column(3));
assertEquals(SQL_TABLE, r.column(3));
assertTrue(r.advanceRow());
assertEquals("test", r.column(2));
assertEquals("BASE TABLE", r.column(3));
assertEquals(SQL_TABLE, r.column(3));
assertTrue(r.advanceRow());
assertEquals("alias", r.column(2));
assertEquals("VIEW", r.column(3));
assertEquals(SQL_VIEW, r.column(3));
}, FROZEN_CFG, index, alias, frozen);
}
public void testSysTablesWithLegacyTypes() throws Exception {
public void testSysTablesWithTypes() throws Exception {
executeCommand("SYS TABLES TYPE 'TABLE', 'ALIAS'", r -> {
assertEquals(2, r.size());
assertEquals("test", r.column(2));
assertEquals("TABLE", r.column(3));
assertEquals(SQL_TABLE, r.column(3));
assertTrue(r.advanceRow());
assertEquals("alias", r.column(2));
assertEquals("VIEW", r.column(3));
assertEquals(SQL_VIEW, r.column(3));
}, index, alias);
}
public void testSysTablesWithProperTypes() throws Exception {
executeCommand("SYS TABLES TYPE 'BASE TABLE', 'ALIAS'", r -> {
assertEquals(2, r.size());
assertEquals("test", r.column(2));
assertEquals("BASE TABLE", r.column(3));
assertTrue(r.advanceRow());
assertEquals("alias", r.column(2));
assertEquals("VIEW", r.column(3));
}, index, alias);
}
public void testSysTablesWithProperTypesAndFrozen() throws Exception {
executeCommand("SYS TABLES TYPE 'BASE TABLE', 'ALIAS'", r -> {
public void testSysTablesWithTypesAndFrozen() throws Exception {
executeCommand("SYS TABLES TYPE 'TABLE', 'ALIAS'", r -> {
assertEquals(3, r.size());
assertEquals("frozen", r.column(2));
assertEquals("BASE TABLE", r.column(3));
assertEquals(SQL_TABLE, r.column(3));
assertTrue(r.advanceRow());
assertEquals("test", r.column(2));
assertEquals("BASE TABLE", r.column(3));
assertEquals(SQL_TABLE, r.column(3));
assertTrue(r.advanceRow());
assertEquals("alias", r.column(2));
assertEquals("VIEW", r.column(3));
assertEquals(SQL_VIEW, r.column(3));
}, index, frozen, alias);
}
@ -211,7 +202,7 @@ public class SysTablesTests extends ESTestCase {
executeCommand("SYS TABLES LIKE '%'", r -> {
assertEquals(2, r.size());
assertEquals("test", r.column(2));
assertEquals("BASE TABLE", r.column(3));
assertEquals(SQL_TABLE, r.column(3));
assertTrue(r.advanceRow());
assertEquals("alias", r.column(2));
}, index, alias);
@ -243,14 +234,14 @@ public class SysTablesTests extends ESTestCase {
}
public void testSysTablesOnlyIndices() throws Exception {
executeCommand("SYS TABLES LIKE 'test' TYPE 'BASE TABLE'", r -> {
executeCommand("SYS TABLES LIKE 'test' TYPE 'TABLE'", r -> {
assertEquals(1, r.size());
assertEquals("test", r.column(2));
}, index);
}
public void testSysTablesOnlyIndicesWithFrozen() throws Exception {
executeCommand("SYS TABLES LIKE 'test' TYPE 'BASE TABLE'", r -> {
executeCommand("SYS TABLES LIKE 'test' TYPE 'TABLE'", r -> {
assertEquals(2, r.size());
assertEquals("frozen", r.column(2));
assertTrue(r.advanceRow());
@ -258,35 +249,27 @@ public class SysTablesTests extends ESTestCase {
}, index, frozen);
}
public void testSysTablesOnlyIndicesInLegacyMode() throws Exception {
executeCommand("SYS TABLES LIKE 'test' TYPE 'TABLE'", r -> {
assertEquals(1, r.size());
assertEquals("test", r.column(2));
assertEquals("TABLE", r.column(3));
}, index);
}
public void testSysTablesNoPatternWithTypesSpecifiedInLegacyMode() throws Exception {
public void testSysTablesNoPatternWithTypesSpecified() throws Exception {
executeCommand("SYS TABLES TYPE 'TABLE','VIEW'", r -> {
assertEquals(2, r.size());
assertEquals("test", r.column(2));
assertEquals("TABLE", r.column(3));
assertEquals(SQL_TABLE, r.column(3));
assertTrue(r.advanceRow());
assertEquals("alias", r.column(2));
assertEquals("VIEW", r.column(3));
assertEquals(SQL_VIEW, r.column(3));
}, index, alias);
}
public void testSysTablesOnlyIndicesLegacyModeParameterized() throws Exception {
public void testSysTablesOnlyIndicesParameterizedTable() throws Exception {
executeCommand("SYS TABLES LIKE 'test' TYPE ?", asList(param("TABLE")), r -> {
assertEquals(1, r.size());
assertEquals("test", r.column(2));
assertEquals("TABLE", r.column(3));
assertEquals(SQL_TABLE, r.column(3));
}, index);
}
public void testSysTablesOnlyIndicesParameterized() throws Exception {
public void testSysTablesOnlyIndicesParameterizedAlias() throws Exception {
executeCommand("SYS TABLES LIKE 'test' TYPE ?", asList(param("ALIAS")), r -> {
assertEquals(1, r.size());
assertEquals("test", r.column(2));
@ -294,7 +277,7 @@ public class SysTablesTests extends ESTestCase {
}
public void testSysTablesOnlyIndicesAndAliases() throws Exception {
executeCommand("SYS TABLES LIKE 'test' TYPE 'VIEW', 'BASE TABLE'", r -> {
executeCommand("SYS TABLES LIKE 'test' TYPE 'VIEW', 'TABLE'", r -> {
assertEquals(2, r.size());
assertEquals("test", r.column(2));
assertTrue(r.advanceRow());
@ -303,7 +286,7 @@ public class SysTablesTests extends ESTestCase {
}
public void testSysTablesOnlyIndicesAndAliasesParameterized() throws Exception {
List<SqlTypedParamValue> params = asList(param("VIEW"), param("BASE TABLE"));
List<SqlTypedParamValue> params = asList(param("VIEW"), param("TABLE"));
executeCommand("SYS TABLES LIKE 'test' TYPE ?, ?", params, r -> {
assertEquals(2, r.size());
assertEquals("test", r.column(2));
@ -317,10 +300,10 @@ public class SysTablesTests extends ESTestCase {
executeCommand("SYS TABLES LIKE 'test' TYPE ?, ?", params, r -> {
assertEquals(2, r.size());
assertEquals("test", r.column(2));
assertEquals("TABLE", r.column(3));
assertEquals(SQL_TABLE, r.column(3));
assertTrue(r.advanceRow());
assertEquals("alias", r.column(2));
assertEquals("VIEW", r.column(3));
assertEquals(SQL_VIEW, r.column(3));
}, index, alias);
}