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:
parent
3d8c04659c
commit
1f76b5fc31
|
@ -84,7 +84,7 @@ SHOW TABLES LIKE 'test\_alias' ESCAPE '\';
|
||||||
|
|
||||||
name:s | type:s
|
name:s | type:s
|
||||||
|
|
||||||
test_alias | ALIAS
|
test_alias | VIEW
|
||||||
;
|
;
|
||||||
|
|
||||||
showPattern
|
showPattern
|
||||||
|
@ -92,8 +92,8 @@ SHOW TABLES LIKE 'test_%';
|
||||||
|
|
||||||
name:s | type:s
|
name:s | type:s
|
||||||
|
|
||||||
test_alias | ALIAS
|
test_alias | VIEW
|
||||||
test_alias_emp | ALIAS
|
test_alias_emp | VIEW
|
||||||
test_emp | BASE TABLE
|
test_emp | BASE TABLE
|
||||||
test_emp_copy | BASE TABLE
|
test_emp_copy | BASE TABLE
|
||||||
;
|
;
|
||||||
|
|
|
@ -7,5 +7,5 @@ SYS TABLE TYPES;
|
||||||
|
|
||||||
TABLE_TYPE:s
|
TABLE_TYPE:s
|
||||||
BASE TABLE
|
BASE TABLE
|
||||||
ALIAS
|
VIEW
|
||||||
;
|
;
|
||||||
|
|
|
@ -178,8 +178,8 @@ SHOW TABLES;
|
||||||
|
|
||||||
name | type
|
name | type
|
||||||
logs |BASE TABLE
|
logs |BASE TABLE
|
||||||
test_alias |ALIAS
|
test_alias |VIEW
|
||||||
test_alias_emp |ALIAS
|
test_alias_emp |VIEW
|
||||||
test_emp |BASE TABLE
|
test_emp |BASE TABLE
|
||||||
test_emp_copy |BASE TABLE
|
test_emp_copy |BASE TABLE
|
||||||
;
|
;
|
||||||
|
@ -217,8 +217,8 @@ showTablesIdentifierPatternOnAliases
|
||||||
SHOW TABLES "test*,-test_emp*";
|
SHOW TABLES "test*,-test_emp*";
|
||||||
|
|
||||||
name:s | type:s
|
name:s | type:s
|
||||||
test_alias |ALIAS
|
test_alias |VIEW
|
||||||
test_alias_emp |ALIAS
|
test_alias_emp |VIEW
|
||||||
;
|
;
|
||||||
|
|
||||||
// DESCRIBE
|
// DESCRIBE
|
||||||
|
|
|
@ -96,7 +96,7 @@ SHOW TABLES;
|
||||||
name | type
|
name | type
|
||||||
---------------+---------------
|
---------------+---------------
|
||||||
emp |BASE TABLE
|
emp |BASE TABLE
|
||||||
employees |ALIAS
|
employees |VIEW
|
||||||
library |BASE TABLE
|
library |BASE TABLE
|
||||||
|
|
||||||
// end::showTables
|
// end::showTables
|
||||||
|
@ -120,7 +120,7 @@ SHOW TABLES LIKE 'emp%';
|
||||||
name | type
|
name | type
|
||||||
---------------+---------------
|
---------------+---------------
|
||||||
emp |BASE TABLE
|
emp |BASE TABLE
|
||||||
employees |ALIAS
|
employees |VIEW
|
||||||
|
|
||||||
// end::showTablesLikeWildcard
|
// end::showTablesLikeWildcard
|
||||||
;
|
;
|
||||||
|
@ -167,7 +167,7 @@ SHOW TABLES "*,-l*";
|
||||||
name | type
|
name | type
|
||||||
---------------+---------------
|
---------------+---------------
|
||||||
emp |BASE TABLE
|
emp |BASE TABLE
|
||||||
employees |ALIAS
|
employees |VIEW
|
||||||
|
|
||||||
// end::showTablesEsMultiIndex
|
// end::showTablesEsMultiIndex
|
||||||
;
|
;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
CREATE TABLE mock (
|
CREATE TABLE mock (
|
||||||
TABLE_TYPE VARCHAR,
|
TABLE_TYPE VARCHAR,
|
||||||
) AS
|
) AS
|
||||||
SELECT 'ALIAS' FROM DUAL
|
|
||||||
UNION ALL
|
|
||||||
SELECT 'BASE TABLE' FROM DUAL
|
SELECT 'BASE TABLE' FROM DUAL
|
||||||
|
UNION ALL
|
||||||
|
SELECT 'VIEW' FROM DUAL
|
||||||
;
|
;
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class IndexResolver {
|
||||||
public enum IndexType {
|
public enum IndexType {
|
||||||
|
|
||||||
INDEX("BASE TABLE"),
|
INDEX("BASE TABLE"),
|
||||||
ALIAS("ALIAS"),
|
ALIAS("VIEW"),
|
||||||
// value for user types unrecognized
|
// value for user types unrecognized
|
||||||
UNKNOWN("UNKNOWN");
|
UNKNOWN("UNKNOWN");
|
||||||
|
|
||||||
|
|
|
@ -61,9 +61,9 @@ public class SysTablesTests extends ESTestCase {
|
||||||
public void testSysTablesEnumerateTypes() throws Exception {
|
public void testSysTablesEnumerateTypes() throws Exception {
|
||||||
executeCommand("SYS TABLES TYPE '%'", r -> {
|
executeCommand("SYS TABLES TYPE '%'", r -> {
|
||||||
assertEquals(2, r.size());
|
assertEquals(2, r.size());
|
||||||
assertEquals("ALIAS", r.column(3));
|
|
||||||
assertTrue(r.advanceRow());
|
|
||||||
assertEquals("BASE TABLE", r.column(3));
|
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 {
|
public void testSysTablesNoTypes() throws Exception {
|
||||||
executeCommand("SYS TABLES", r -> {
|
executeCommand("SYS TABLES", r -> {
|
||||||
assertEquals(2, r.size());
|
assertEquals(2, r.size());
|
||||||
assertEquals("ALIAS", r.column(3));
|
|
||||||
assertTrue(r.advanceRow());
|
|
||||||
assertEquals("BASE TABLE", r.column(3));
|
assertEquals("BASE TABLE", r.column(3));
|
||||||
|
assertTrue(r.advanceRow());
|
||||||
|
assertEquals("VIEW", r.column(3));
|
||||||
}, index, alias);
|
}, index, alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSysTablesPattern() throws Exception {
|
public void testSysTablesPattern() throws Exception {
|
||||||
executeCommand("SYS TABLES LIKE '%'", r -> {
|
executeCommand("SYS TABLES LIKE '%'", r -> {
|
||||||
assertEquals("alias", r.column(2));
|
assertEquals("test", r.column(2));
|
||||||
assertTrue(r.advanceRow());
|
assertTrue(r.advanceRow());
|
||||||
assertEquals(2, r.size());
|
assertEquals(2, r.size());
|
||||||
assertEquals("test", r.column(2));
|
assertEquals("alias", r.column(2));
|
||||||
}, index, alias);
|
}, index, alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSysTablesPatternParameterized() throws Exception {
|
public void testSysTablesPatternParameterized() throws Exception {
|
||||||
List<SqlTypedParamValue> params = asList(param("%"));
|
List<SqlTypedParamValue> params = asList(param("%"));
|
||||||
executeCommand("SYS TABLES LIKE ?", params, r -> {
|
executeCommand("SYS TABLES LIKE ?", params, r -> {
|
||||||
assertEquals("alias", r.column(2));
|
assertEquals("test", r.column(2));
|
||||||
assertTrue(r.advanceRow());
|
assertTrue(r.advanceRow());
|
||||||
assertEquals(2, r.size());
|
assertEquals(2, r.size());
|
||||||
assertEquals("test", r.column(2));
|
assertEquals("alias", r.column(2));
|
||||||
}, alias, index);
|
}, alias, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,38 +149,38 @@ public class SysTablesTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSysTablesOnlyIndicesAndAliases() throws Exception {
|
public void testSysTablesOnlyIndicesAndAliases() throws Exception {
|
||||||
executeCommand("SYS TABLES LIKE 'test' TYPE 'ALIAS', 'BASE TABLE'", r -> {
|
executeCommand("SYS TABLES LIKE 'test' TYPE 'VIEW', 'BASE TABLE'", r -> {
|
||||||
assertEquals("alias", r.column(2));
|
|
||||||
assertTrue(r.advanceRow());
|
|
||||||
assertEquals(2, r.size());
|
assertEquals(2, r.size());
|
||||||
assertEquals("test", r.column(2));
|
assertEquals("test", r.column(2));
|
||||||
|
assertTrue(r.advanceRow());
|
||||||
|
assertEquals("alias", r.column(2));
|
||||||
}, index, alias);
|
}, index, alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSysTablesOnlyIndicesAndAliasesParameterized() throws Exception {
|
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 -> {
|
executeCommand("SYS TABLES LIKE 'test' TYPE ?, ?", params, r -> {
|
||||||
assertEquals("alias", r.column(2));
|
|
||||||
assertTrue(r.advanceRow());
|
|
||||||
assertEquals(2, r.size());
|
assertEquals(2, r.size());
|
||||||
assertEquals("test", r.column(2));
|
assertEquals("test", r.column(2));
|
||||||
|
assertTrue(r.advanceRow());
|
||||||
|
assertEquals("alias", r.column(2));
|
||||||
}, index, alias);
|
}, index, alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSysTablesOnlyIndicesLegacyAndAliasesParameterized() throws Exception {
|
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 -> {
|
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(2, r.size());
|
||||||
assertEquals("test", r.column(2));
|
assertEquals("test", r.column(2));
|
||||||
assertEquals("TABLE", r.column(3));
|
assertEquals("TABLE", r.column(3));
|
||||||
|
assertTrue(r.advanceRow());
|
||||||
|
assertEquals("alias", r.column(2));
|
||||||
|
assertEquals("VIEW", r.column(3));
|
||||||
}, index, alias);
|
}, index, alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSysTablesWithCatalogOnlyAliases() throws Exception {
|
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(1, r.size());
|
||||||
assertEquals("alias", r.column(2));
|
assertEquals("alias", r.column(2));
|
||||||
}, alias);
|
}, alias);
|
||||||
|
|
Loading…
Reference in New Issue