You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2016/08/24 22:45:30 UTC

calcite git commit: [CALCITE-1360] Custom schema in file in current directory

Repository: calcite
Updated Branches:
  refs/heads/master 92e6494b1 -> 0eaf0e2d2


[CALCITE-1360] Custom schema in file in current directory


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

Branch: refs/heads/master
Commit: 0eaf0e2d2e7397a6e3519330e702f802336257d4
Parents: 92e6494
Author: Julian Hyde <jh...@apache.org>
Authored: Wed Aug 24 12:01:42 2016 -0700
Committer: Julian Hyde <jh...@apache.org>
Committed: Wed Aug 24 12:01:42 2016 -0700

----------------------------------------------------------------------
 .../org/apache/calcite/model/ModelHandler.java  |  5 +-
 .../java/org/apache/calcite/test/JdbcTest.java  | 48 ++++++++++++++++++++
 2 files changed, 52 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/0eaf0e2d/core/src/main/java/org/apache/calcite/model/ModelHandler.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/model/ModelHandler.java b/core/src/main/java/org/apache/calcite/model/ModelHandler.java
index 408cf02..bd8bcac 100644
--- a/core/src/main/java/org/apache/calcite/model/ModelHandler.java
+++ b/core/src/main/java/org/apache/calcite/model/ModelHandler.java
@@ -238,7 +238,10 @@ public class ModelHandler {
         case BASE_DIRECTORY:
           if (!modelUri.startsWith("inline:")) {
             final File file = new File(modelUri);
-            builder.put(extraOperand.camelName, file.getParentFile());
+            final File parentFile = file.getParentFile();
+            if (parentFile != null) {
+              builder.put(extraOperand.camelName, parentFile);
+            }
           }
           break;
         case TABLES:

http://git-wip-us.apache.org/repos/asf/calcite/blob/0eaf0e2d/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 94586d2..0c36aaa 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcTest.java
@@ -104,7 +104,10 @@ import org.hsqldb.jdbcDriver;
 import org.junit.Ignore;
 import org.junit.Test;
 
+import java.io.File;
+import java.io.FileWriter;
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.io.Reader;
 import java.math.BigDecimal;
 import java.sql.Array;
@@ -5127,6 +5130,51 @@ public class JdbcTest {
         .throws_("Table 'adhoc.EMPLOYEES' not found");
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-1360">[CALCITE-1360]
+   * Custom schema in file in current directory</a>. */
+  @Test public void testCustomSchemaInFileInPwd() throws SQLException {
+    checkCustomSchemaInFileInPwd("custom-schema-model.json");
+    checkCustomSchemaInFileInPwd("./custom-schema-model2.json");
+  }
+
+  private void checkCustomSchemaInFileInPwd(String fileName)
+      throws SQLException {
+    final File file = new File(fileName);
+    try (final FileWriter fw = new FileWriter(file);
+         final PrintWriter pw = new PrintWriter(fw)) {
+      file.deleteOnExit();
+      pw.println("{\n"
+          + "  version: '1.0',\n"
+          + "  defaultSchema: 'adhoc',\n"
+          + "  schemas: [\n"
+          + "    {\n"
+          + "      name: 'empty'\n"
+          + "    },\n"
+          + "    {\n"
+          + "      name: 'adhoc',\n"
+          + "      type: 'custom',\n"
+          + "      factory: '"
+          + MySchemaFactory.class.getName()
+          + "',\n"
+          + "      operand: {'tableName': 'ELVIS'}\n"
+          + "    }\n"
+          + "  ]\n"
+          + "}");
+      pw.flush();
+      final String url = "jdbc:calcite:model=" + file;
+      try (Connection c = DriverManager.getConnection(url);
+           Statement s = c.createStatement();
+           ResultSet r = s.executeQuery("values 1")) {
+        assertThat(r.next(), is(true));
+      }
+      assertThat(file.delete(), is(true));
+    } catch (IOException e) {
+      // current directory is not writable; an environment issue, not
+      // necessarily a bug
+    }
+  }
+
   /** Connects to a custom schema without writing a model.
    *
    * <p>Test case for