SQL: Describe aliases as views (#37496)

When reporting metadata, several clients have issues with the 'ALIAS'
type. To improve compatibility and be consistent with the ANSI SQL
expectations and because they are similar, aliases targets are now
reported as views.

Close #37422
This commit is contained in:
Costin Leau 2019-01-16 17:26:00 +02:00 committed by GitHub
parent 3d8c04659c
commit 1f76b5fc31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 33 deletions

View File

@ -84,7 +84,7 @@ SHOW TABLES LIKE 'test\_alias' ESCAPE '\';
name:s | type:s
test_alias | ALIAS
test_alias | VIEW
;
showPattern
@ -92,8 +92,8 @@ SHOW TABLES LIKE 'test_%';
name:s | type:s
test_alias | ALIAS
test_alias_emp | ALIAS
test_alias | VIEW
test_alias_emp | VIEW
test_emp | BASE TABLE
test_emp_copy | BASE TABLE
;

View File

@ -7,5 +7,5 @@ SYS TABLE TYPES;
TABLE_TYPE:s
BASE TABLE
ALIAS
VIEW
;

View File

@ -178,8 +178,8 @@ SHOW TABLES;
name | type
logs |BASE TABLE
test_alias |ALIAS
test_alias_emp |ALIAS
test_alias |VIEW
test_alias_emp |VIEW
test_emp |BASE TABLE
test_emp_copy |BASE TABLE
;
@ -217,8 +217,8 @@ showTablesIdentifierPatternOnAliases
SHOW TABLES "test*,-test_emp*";
name:s | type:s
test_alias |ALIAS
test_alias_emp |ALIAS
test_alias |VIEW
test_alias_emp |VIEW
;
// DESCRIBE

View File

@ -96,7 +96,7 @@ SHOW TABLES;
name | type
---------------+---------------
emp |BASE TABLE
employees |ALIAS
employees |VIEW
library |BASE TABLE
// end::showTables
@ -120,7 +120,7 @@ SHOW TABLES LIKE 'emp%';
name | type
---------------+---------------
emp |BASE TABLE
employees |ALIAS
employees |VIEW
// end::showTablesLikeWildcard
;
@ -167,7 +167,7 @@ SHOW TABLES "*,-l*";
name | type
---------------+---------------
emp |BASE TABLE
employees |ALIAS
employees |VIEW
// end::showTablesEsMultiIndex
;

View File

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

View File

@ -61,7 +61,7 @@ public class IndexResolver {
public enum IndexType {
INDEX("BASE TABLE"),
ALIAS("ALIAS"),
ALIAS("VIEW"),
// value for user types unrecognized
UNKNOWN("UNKNOWN");

View File

@ -61,9 +61,9 @@ public class SysTablesTests extends ESTestCase {
public void testSysTablesEnumerateTypes() throws Exception {
executeCommand("SYS TABLES TYPE '%'", r -> {
assertEquals(2, r.size());
assertEquals("ALIAS", r.column(3));
assertTrue(r.advanceRow());
assertEquals("BASE TABLE", r.column(3));
assertTrue(r.advanceRow());
assertEquals("VIEW", r.column(3));
});
}
@ -77,28 +77,28 @@ public class SysTablesTests extends ESTestCase {
public void testSysTablesNoTypes() throws Exception {
executeCommand("SYS TABLES", r -> {
assertEquals(2, r.size());
assertEquals("ALIAS", r.column(3));
assertTrue(r.advanceRow());
assertEquals("BASE TABLE", r.column(3));
assertTrue(r.advanceRow());
assertEquals("VIEW", r.column(3));
}, index, alias);
}
public void testSysTablesPattern() throws Exception {
executeCommand("SYS TABLES LIKE '%'", r -> {
assertEquals("alias", r.column(2));
assertEquals("test", r.column(2));
assertTrue(r.advanceRow());
assertEquals(2, r.size());
assertEquals("test", r.column(2));
assertEquals("alias", r.column(2));
}, index, alias);
}
public void testSysTablesPatternParameterized() throws Exception {
List<SqlTypedParamValue> params = asList(param("%"));
executeCommand("SYS TABLES LIKE ?", params, r -> {
assertEquals("alias", r.column(2));
assertEquals("test", r.column(2));
assertTrue(r.advanceRow());
assertEquals(2, r.size());
assertEquals("test", r.column(2));
assertEquals("alias", r.column(2));
}, alias, index);
}
@ -149,38 +149,38 @@ public class SysTablesTests extends ESTestCase {
}
public void testSysTablesOnlyIndicesAndAliases() throws Exception {
executeCommand("SYS TABLES LIKE 'test' TYPE 'ALIAS', 'BASE TABLE'", r -> {
assertEquals("alias", r.column(2));
assertTrue(r.advanceRow());
executeCommand("SYS TABLES LIKE 'test' TYPE 'VIEW', 'BASE TABLE'", r -> {
assertEquals(2, r.size());
assertEquals("test", r.column(2));
assertTrue(r.advanceRow());
assertEquals("alias", r.column(2));
}, index, alias);
}
public void testSysTablesOnlyIndicesAndAliasesParameterized() throws Exception {
List<SqlTypedParamValue> params = asList(param("ALIAS"), param("BASE TABLE"));
List<SqlTypedParamValue> params = asList(param("VIEW"), param("BASE TABLE"));
executeCommand("SYS TABLES LIKE 'test' TYPE ?, ?", params, r -> {
assertEquals("alias", r.column(2));
assertTrue(r.advanceRow());
assertEquals(2, r.size());
assertEquals("test", r.column(2));
assertTrue(r.advanceRow());
assertEquals("alias", r.column(2));
}, index, alias);
}
public void testSysTablesOnlyIndicesLegacyAndAliasesParameterized() throws Exception {
List<SqlTypedParamValue> params = asList(param("ALIAS"), param("TABLE"));
List<SqlTypedParamValue> params = asList(param("VIEW"), param("TABLE"));
executeCommand("SYS TABLES LIKE 'test' TYPE ?, ?", params, r -> {
assertEquals("alias", r.column(2));
assertEquals("ALIAS", r.column(3));
assertTrue(r.advanceRow());
assertEquals(2, r.size());
assertEquals("test", r.column(2));
assertEquals("TABLE", r.column(3));
assertTrue(r.advanceRow());
assertEquals("alias", r.column(2));
assertEquals("VIEW", r.column(3));
}, index, alias);
}
public void testSysTablesWithCatalogOnlyAliases() throws Exception {
executeCommand("SYS TABLES CATALOG LIKE '%' LIKE 'test' TYPE 'ALIAS'", r -> {
executeCommand("SYS TABLES CATALOG LIKE '%' LIKE 'test' TYPE 'VIEW'", r -> {
assertEquals(1, r.size());
assertEquals("alias", r.column(2));
}, alias);