SQL: Align SYS TABLE for ODBC SQL_ALL_* args (#33364)
Fix a bug in SYS TABLES command that did skipped SQL_ALL_* arguments for catalog and table types Fix #33312
This commit is contained in:
parent
9f96d2ce17
commit
d7965ba681
|
@ -157,9 +157,9 @@ abstract class CommandBuilder extends LogicalPlanBuilder {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
// check special ODBC wildcard case
|
// check special ODBC wildcard case
|
||||||
if (value.equals(StringUtils.SQL_WILDCARD) && ctx.string().size() == 1) {
|
if (value.equals(StringUtils.SQL_WILDCARD) && ctx.string().size() == 1) {
|
||||||
// since % is the same as not specifying a value, choose
|
// convert % to enumeration
|
||||||
// https://docs.microsoft.com/en-us/sql/odbc/reference/develop-app/value-list-arguments?view=ssdt-18vs2017
|
// https://docs.microsoft.com/en-us/sql/odbc/reference/develop-app/value-list-arguments?view=ssdt-18vs2017
|
||||||
// that is skip the value
|
types.addAll(IndexType.VALID);
|
||||||
}
|
}
|
||||||
// special case for legacy apps (like msquery) that always asks for 'TABLE'
|
// special case for legacy apps (like msquery) that always asks for 'TABLE'
|
||||||
// which we manually map to all concrete tables supported
|
// which we manually map to all concrete tables supported
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class SysTables extends Command {
|
||||||
// https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqltables-function?view=ssdt-18vs2017#comments
|
// https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqltables-function?view=ssdt-18vs2017#comments
|
||||||
|
|
||||||
if (clusterPattern != null && clusterPattern.pattern().equals(SQL_WILDCARD)) {
|
if (clusterPattern != null && clusterPattern.pattern().equals(SQL_WILDCARD)) {
|
||||||
if (pattern != null && pattern.pattern().isEmpty() && CollectionUtils.isEmpty(types)) {
|
if ((pattern == null || pattern.pattern().isEmpty()) && CollectionUtils.isEmpty(types)) {
|
||||||
Object[] enumeration = new Object[10];
|
Object[] enumeration = new Object[10];
|
||||||
// send only the cluster, everything else null
|
// send only the cluster, everything else null
|
||||||
enumeration[0] = cluster;
|
enumeration[0] = cluster;
|
||||||
|
@ -88,8 +88,9 @@ public class SysTables extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if no types were specified (the parser takes care of the % case)
|
// if no types were specified (the parser takes care of the % case)
|
||||||
if (CollectionUtils.isEmpty(types)) {
|
if (IndexType.VALID.equals(types)) {
|
||||||
if (clusterPattern != null && clusterPattern.pattern().isEmpty()) {
|
if ((clusterPattern == null || clusterPattern.pattern().isEmpty())
|
||||||
|
&& (pattern == null || pattern.pattern().isEmpty())) {
|
||||||
List<List<?>> values = new ArrayList<>();
|
List<List<?>> values = new ArrayList<>();
|
||||||
// send only the types, everything else null
|
// send only the types, everything else null
|
||||||
for (IndexType type : IndexType.VALID) {
|
for (IndexType type : IndexType.VALID) {
|
||||||
|
|
|
@ -49,6 +49,22 @@ public class SysTablesTests extends ESTestCase {
|
||||||
private final IndexInfo index = new IndexInfo("test", IndexType.INDEX);
|
private final IndexInfo index = new IndexInfo("test", IndexType.INDEX);
|
||||||
private final IndexInfo alias = new IndexInfo("alias", IndexType.ALIAS);
|
private final IndexInfo alias = new IndexInfo("alias", IndexType.ALIAS);
|
||||||
|
|
||||||
|
public void testSysTablesEnumerateCatalog() throws Exception {
|
||||||
|
executeCommand("SYS TABLES CATALOG LIKE '%'", r -> {
|
||||||
|
assertEquals(1, r.size());
|
||||||
|
assertEquals(CLUSTER_NAME, r.column(0));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void testSysTablesDifferentCatalog() throws Exception {
|
public void testSysTablesDifferentCatalog() throws Exception {
|
||||||
executeCommand("SYS TABLES CATALOG LIKE 'foo'", r -> {
|
executeCommand("SYS TABLES CATALOG LIKE 'foo'", r -> {
|
||||||
assertEquals(0, r.size());
|
assertEquals(0, r.size());
|
||||||
|
@ -58,10 +74,10 @@ public class SysTablesTests extends ESTestCase {
|
||||||
|
|
||||||
public void testSysTablesNoTypes() throws Exception {
|
public void testSysTablesNoTypes() throws Exception {
|
||||||
executeCommand("SYS TABLES", r -> {
|
executeCommand("SYS TABLES", r -> {
|
||||||
assertEquals("alias", r.column(2));
|
|
||||||
assertTrue(r.advanceRow());
|
|
||||||
assertEquals(2, r.size());
|
assertEquals(2, r.size());
|
||||||
assertEquals("test", r.column(2));
|
assertEquals("ALIAS", r.column(3));
|
||||||
|
assertTrue(r.advanceRow());
|
||||||
|
assertEquals("BASE TABLE", r.column(3));
|
||||||
}, index, alias);
|
}, index, alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,22 +224,7 @@ public class SysTablesTests extends ESTestCase {
|
||||||
|
|
||||||
public void testSysTablesTypesEnumerationWoString() throws Exception {
|
public void testSysTablesTypesEnumerationWoString() throws Exception {
|
||||||
executeCommand("SYS TABLES CATALOG LIKE '' LIKE '' ", r -> {
|
executeCommand("SYS TABLES CATALOG LIKE '' LIKE '' ", r -> {
|
||||||
assertEquals(2, r.size());
|
assertEquals(0, r.size());
|
||||||
|
|
||||||
Iterator<IndexType> it = IndexType.VALID.stream().sorted(Comparator.comparing(IndexType::toSql)).iterator();
|
|
||||||
|
|
||||||
for (int t = 0; t < r.size(); t++) {
|
|
||||||
assertEquals(it.next().toSql(), r.column(3));
|
|
||||||
|
|
||||||
// everything else should be null
|
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
if (i != 3) {
|
|
||||||
assertNull(r.column(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
r.advanceRow();
|
|
||||||
}
|
|
||||||
}, new IndexInfo[0]);
|
}, new IndexInfo[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue