Skip to content

Commit

Permalink
[CALCITE-2001] JDBC driver should return "SYSTEM TABLE" rather than "…
Browse files Browse the repository at this point in the history
…SYSTEM_TABLE"
  • Loading branch information
julianhyde committed Oct 5, 2017
1 parent a9ac3e4 commit 7546ef2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ private static class CalciteMetaTable extends MetaTable {
CalciteMetaTable(Table calciteTable, String tableCat,
String tableSchem, String tableName) {
super(tableCat, tableSchem, tableName,
calciteTable.getJdbcTableType().name());
calciteTable.getJdbcTableType().jdbcName);
this.calciteTable = Preconditions.checkNotNull(calciteTable);
}
}
Expand Down
10 changes: 9 additions & 1 deletion core/src/main/java/org/apache/calcite/schema/Schema.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,15 @@ enum TableType {
*
* <p>If you get one of these, please fix the problem by adding an enum
* value. */
OTHER,
OTHER;

/** The name used in JDBC. For example "SYSTEM TABLE" rather than
* "SYSTEM_TABLE". */
public final String jdbcName;

TableType() {
this.jdbcName = name().replace('_', ' ');
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.google.common.base.Function;

import org.hamcrest.Matcher;
import org.junit.Ignore;
import org.junit.Test;

Expand All @@ -28,8 +29,10 @@

import static org.apache.calcite.test.CalciteAssert.that;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;

/**
* Tests for a JDBC front-end and JDBC back-end.
Expand Down Expand Up @@ -76,27 +79,30 @@ public Object apply(CalciteConnection a0) {
}

@Test public void testTablesByType() throws Exception {
// check with the form recommended by JDBC
checkTablesByType("SYSTEM TABLE", is("COLUMNS;TABLES;"));
// the form we used until 1.14 no longer generates results
checkTablesByType("SYSTEM_TABLE", is(""));
}

private void checkTablesByType(final String tableType,
final Matcher<String> matcher) throws Exception {
that()
.with(CalciteAssert.Config.REGULAR_PLUS_METADATA)
.doWithConnection(
new Function<CalciteConnection, Object>() {
public Object apply(CalciteConnection a0) {
try {
ResultSet rset =
a0.getMetaData().getTables(
null, null, null,
new String[] {"SYSTEM_TABLE"});
try (ResultSet rset = a0.getMetaData().getTables(null, null,
null, new String[] {tableType})) {
StringBuilder buf = new StringBuilder();
while (rset.next()) {
buf.append(rset.getString(3)).append(';');
}
assertEquals(
"COLUMNS;TABLES;",
buf.toString());
assertThat(buf.toString(), matcher);
return null;
} catch (SQLException e) {
throw new RuntimeException(e);
}
return null;
}
});
}
Expand Down
15 changes: 13 additions & 2 deletions core/src/test/java/org/apache/calcite/test/JdbcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4732,7 +4732,7 @@ private CalciteAssert.AssertQuery withEmpDept(String sql) {
.query("select * from \"metadata\".TABLES")
.returns(
CalciteAssert.checkResultContains(
"tableSchem=metadata; tableName=COLUMNS; tableType=SYSTEM_TABLE; "));
"tableSchem=metadata; tableName=COLUMNS; tableType=SYSTEM TABLE; "));

CalciteAssert.that()
.with(CalciteAssert.Config.REGULAR_PLUS_METADATA)
Expand Down Expand Up @@ -5232,14 +5232,25 @@ public Void apply(CalciteConnection a0) {
CalciteAssert.toString(
metaData.getTables(null, "adhoc", null, null)));

// including system tables; note that table type is "SYSTEM TABLE"
// not "SYSTEM_TABLE"
assertEquals(
"TABLE_CAT=null; TABLE_SCHEM=adhoc; TABLE_NAME=EMPLOYEES; TABLE_TYPE=TABLE; REMARKS=null; TYPE_CAT=null; TYPE_SCHEM=null; TYPE_NAME=null; SELF_REFERENCING_COL_NAME=null; REF_GENERATION=null\n"
+ "TABLE_CAT=null; TABLE_SCHEM=adhoc; TABLE_NAME=MUTABLE_EMPLOYEES; TABLE_TYPE=TABLE; REMARKS=null; TYPE_CAT=null; TYPE_SCHEM=null; TYPE_NAME=null; SELF_REFERENCING_COL_NAME=null; REF_GENERATION=null\n"
+ "TABLE_CAT=null; TABLE_SCHEM=adhoc; TABLE_NAME=V; TABLE_TYPE=VIEW; REMARKS=null; TYPE_CAT=null; TYPE_SCHEM=null; TYPE_NAME=null; SELF_REFERENCING_COL_NAME=null; REF_GENERATION=null\n"
+ "TABLE_CAT=null; TABLE_SCHEM=metadata; TABLE_NAME=COLUMNS; TABLE_TYPE=SYSTEM TABLE; REMARKS=null; TYPE_CAT=null; TYPE_SCHEM=null; TYPE_NAME=null; SELF_REFERENCING_COL_NAME=null; REF_GENERATION=null\n"
+ "TABLE_CAT=null; TABLE_SCHEM=metadata; TABLE_NAME=TABLES; TABLE_TYPE=SYSTEM TABLE; REMARKS=null; TYPE_CAT=null; TYPE_SCHEM=null; TYPE_NAME=null; SELF_REFERENCING_COL_NAME=null; REF_GENERATION=null\n",
CalciteAssert.toString(
metaData.getTables(null, null, null, null)));

// views only
assertEquals(
"TABLE_CAT=null; TABLE_SCHEM=adhoc; TABLE_NAME=V; TABLE_TYPE=VIEW; REMARKS=null; TYPE_CAT=null; TYPE_SCHEM=null; TYPE_NAME=null; SELF_REFERENCING_COL_NAME=null; REF_GENERATION=null\n",
CalciteAssert.toString(
metaData.getTables(
null, "adhoc", null,
new String[]{
Schema.TableType.VIEW.name()
Schema.TableType.VIEW.jdbcName
})));

// columns
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/resources/sql/sequence.iq
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ select * from "metadata".tables;
+----------+------------+-----------+--------------+---------+---------+-----------+----------+------------------------+---------------+
| tableCat | tableSchem | tableName | tableType | remarks | typeCat | typeSchem | typeName | selfReferencingColName | refGeneration |
+----------+------------+-----------+--------------+---------+---------+-----------+----------+------------------------+---------------+
| | metadata | COLUMNS | SYSTEM_TABLE | | | | | | |
| | metadata | TABLES | SYSTEM_TABLE | | | | | | |
| | metadata | COLUMNS | SYSTEM TABLE | | | | | | |
| | metadata | TABLES | SYSTEM TABLE | | | | | | |
| | s | my_seq | SEQUENCE | | | | | | |
+----------+------------+-----------+--------------+---------+---------+-----------+----------+------------------------+---------------+
(3 rows)
Expand Down

0 comments on commit 7546ef2

Please sign in to comment.