Repository: calcite
Updated Branches:
  refs/heads/master a9ac3e486 -> fb760a6f4


[CALCITE-2001] JDBC driver should return "SYSTEM TABLE" rather than 
"SYSTEM_TABLE"


Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/7546ef2d
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/7546ef2d
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/7546ef2d

Branch: refs/heads/master
Commit: 7546ef2d7f041d61fdeaee73266b710dd37c0914
Parents: a9ac3e4
Author: Julian Hyde <[email protected]>
Authored: Thu Oct 5 09:05:12 2017 -0700
Committer: Julian Hyde <[email protected]>
Committed: Thu Oct 5 14:56:58 2017 -0700

----------------------------------------------------------------------
 .../apache/calcite/jdbc/CalciteMetaImpl.java    |  2 +-
 .../java/org/apache/calcite/schema/Schema.java  | 10 +++++++-
 .../calcite/test/JdbcFrontJdbcBackTest.java     | 24 ++++++++++++--------
 .../java/org/apache/calcite/test/JdbcTest.java  | 15 ++++++++++--
 core/src/test/resources/sql/sequence.iq         |  4 ++--
 5 files changed, 40 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/7546ef2d/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java 
b/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
index 96950a0..c17b6bf 100644
--- a/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
+++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
@@ -777,7 +777,7 @@ public class CalciteMetaImpl extends MetaImpl {
     CalciteMetaTable(Table calciteTable, String tableCat,
         String tableSchem, String tableName) {
       super(tableCat, tableSchem, tableName,
-          calciteTable.getJdbcTableType().name());
+          calciteTable.getJdbcTableType().jdbcName);
       this.calciteTable = Preconditions.checkNotNull(calciteTable);
     }
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/7546ef2d/core/src/main/java/org/apache/calcite/schema/Schema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/schema/Schema.java 
b/core/src/main/java/org/apache/calcite/schema/Schema.java
index a2d53a0..312ab58 100644
--- a/core/src/main/java/org/apache/calcite/schema/Schema.java
+++ b/core/src/main/java/org/apache/calcite/schema/Schema.java
@@ -310,7 +310,15 @@ public interface Schema {
      *
      * <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('_', ' ');
+    }
   }
 }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/7546ef2d/core/src/test/java/org/apache/calcite/test/JdbcFrontJdbcBackTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/calcite/test/JdbcFrontJdbcBackTest.java 
b/core/src/test/java/org/apache/calcite/test/JdbcFrontJdbcBackTest.java
index 5cea310..377c23b 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcFrontJdbcBackTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcFrontJdbcBackTest.java
@@ -20,6 +20,7 @@ import org.apache.calcite.jdbc.CalciteConnection;
 
 import com.google.common.base.Function;
 
+import org.hamcrest.Matcher;
 import org.junit.Ignore;
 import org.junit.Test;
 
@@ -28,8 +29,10 @@ import java.sql.SQLException;
 
 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.
@@ -76,27 +79,30 @@ public class JdbcFrontJdbcBackTest {
   }
 
   @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;
               }
             });
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/7546ef2d/core/src/test/java/org/apache/calcite/test/JdbcTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/JdbcTest.java 
b/core/src/test/java/org/apache/calcite/test/JdbcTest.java
index 7d722cb..4c0975c 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcTest.java
@@ -4732,7 +4732,7 @@ public class JdbcTest {
         .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)
@@ -5232,6 +5232,17 @@ public class JdbcTest {
                   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",
@@ -5239,7 +5250,7 @@ public class JdbcTest {
                       metaData.getTables(
                           null, "adhoc", null,
                           new String[]{
-                              Schema.TableType.VIEW.name()
+                              Schema.TableType.VIEW.jdbcName
                           })));
 
               // columns

http://git-wip-us.apache.org/repos/asf/calcite/blob/7546ef2d/core/src/test/resources/sql/sequence.iq
----------------------------------------------------------------------
diff --git a/core/src/test/resources/sql/sequence.iq 
b/core/src/test/resources/sql/sequence.iq
index be79eaa..163d92c 100644
--- a/core/src/test/resources/sql/sequence.iq
+++ b/core/src/test/resources/sql/sequence.iq
@@ -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)

Reply via email to