You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by ma...@apache.org on 2017/01/12 00:53:13 UTC
calcite git commit: [CALCITE-1571] Could not resolve VIEW with
SimpleCalciteSchema
Repository: calcite
Updated Branches:
refs/heads/master 5184aa7ba -> 2c2b88391
[CALCITE-1571] Could not resolve VIEW with SimpleCalciteSchema
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/2c2b8839
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/2c2b8839
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/2c2b8839
Branch: refs/heads/master
Commit: 2c2b883910147b429ed38030cc6cf6543ace6e98
Parents: 5184aa7
Author: maryannxue <ma...@gmail.com>
Authored: Wed Jan 11 16:43:23 2017 -0800
Committer: maryannxue <ma...@gmail.com>
Committed: Wed Jan 11 16:45:32 2017 -0800
----------------------------------------------------------------------
.../calcite/jdbc/CachingCalciteSchema.java | 3 +-
.../org/apache/calcite/jdbc/CalciteSchema.java | 5 ++-
.../calcite/jdbc/SimpleCalciteSchema.java | 15 +++++---
.../java/org/apache/calcite/test/JdbcTest.java | 39 ++++++++++++++++++++
4 files changed, 54 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/2c2b8839/core/src/main/java/org/apache/calcite/jdbc/CachingCalciteSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/jdbc/CachingCalciteSchema.java b/core/src/main/java/org/apache/calcite/jdbc/CachingCalciteSchema.java
index 7985bf2..9414996 100644
--- a/core/src/main/java/org/apache/calcite/jdbc/CachingCalciteSchema.java
+++ b/core/src/main/java/org/apache/calcite/jdbc/CachingCalciteSchema.java
@@ -142,7 +142,8 @@ class CachingCalciteSchema extends CalciteSchema {
}
protected void addImplicitFunctionsToBuilder(
- ImmutableList.Builder<Function> builder, boolean caseSensitive) {
+ ImmutableList.Builder<Function> builder,
+ String name, boolean caseSensitive) {
// Add implicit functions, case-insensitive.
final long now = System.currentTimeMillis();
final NameSet set = implicitFunctionCache.get(now);
http://git-wip-us.apache.org/repos/asf/calcite/blob/2c2b8839/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java b/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java
index f1614fd..89e377d 100644
--- a/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java
+++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java
@@ -100,7 +100,8 @@ public abstract class CalciteSchema {
/** Adds implicit functions to a builder. */
protected abstract void addImplicitFunctionsToBuilder(
- ImmutableList.Builder<Function> builder, boolean caseSensitive);
+ ImmutableList.Builder<Function> builder,
+ String name, boolean caseSensitive);
/** Adds implicit function names to a builder. */
protected abstract void addImplicitFuncNamesToBuilder(
@@ -290,7 +291,7 @@ public abstract class CalciteSchema {
builder.add(functionEntry.getFunction());
}
// Add implicit functions.
- addImplicitFunctionsToBuilder(builder, caseSensitive);
+ addImplicitFunctionsToBuilder(builder, name, caseSensitive);
return builder.build();
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/2c2b8839/core/src/main/java/org/apache/calcite/jdbc/SimpleCalciteSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/jdbc/SimpleCalciteSchema.java b/core/src/main/java/org/apache/calcite/jdbc/SimpleCalciteSchema.java
index db97b14..d235ba6 100644
--- a/core/src/main/java/org/apache/calcite/jdbc/SimpleCalciteSchema.java
+++ b/core/src/main/java/org/apache/calcite/jdbc/SimpleCalciteSchema.java
@@ -25,6 +25,8 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.ImmutableSortedSet;
+import java.util.Collection;
+
/**
* A concrete implementation of {@link org.apache.calcite.jdbc.CalciteSchema}
* that maintains minimal state.
@@ -90,9 +92,11 @@ class SimpleCalciteSchema extends CalciteSchema {
}
protected void addImplicitFunctionsToBuilder(
- ImmutableList.Builder<Function> builder, boolean caseSensitive) {
- for (String functionName : schema.getFunctionNames()) {
- builder.addAll(schema.getFunctions(functionName));
+ ImmutableList.Builder<Function> builder,
+ String name, boolean caseSensitive) {
+ Collection<Function> functions = schema.getFunctions(name);
+ if (functions != null) {
+ builder.addAll(functions);
}
}
@@ -121,8 +125,9 @@ class SimpleCalciteSchema extends CalciteSchema {
protected TableEntry getImplicitTableBasedOnNullaryFunction(String tableName,
boolean caseSensitive) {
- for (String s : schema.getFunctionNames()) {
- for (Function function : schema.getFunctions(s)) {
+ Collection<Function> functions = schema.getFunctions(tableName);
+ if (functions != null) {
+ for (Function function : functions) {
if (function instanceof TableMacro
&& function.getParameters().isEmpty()) {
final Table table = ((TableMacro) function).apply(ImmutableList.of());
http://git-wip-us.apache.org/repos/asf/calcite/blob/2c2b8839/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 a3659c0..126df14 100644
--- a/core/src/test/java/org/apache/calcite/test/JdbcTest.java
+++ b/core/src/test/java/org/apache/calcite/test/JdbcTest.java
@@ -100,6 +100,8 @@ import org.apache.calcite.util.Util;
import com.google.common.base.Function;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.LinkedListMultimap;
+import com.google.common.collect.Multimap;
import org.hsqldb.jdbcDriver;
@@ -144,6 +146,7 @@ import static org.apache.calcite.util.Static.RESOURCE;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
@@ -6272,6 +6275,42 @@ public class JdbcTest {
assertThat(aSchema.getSubSchemaNames().size(), is(2));
}
+ @Test public void testSimpleCalciteSchemaWithView() throws Exception {
+ final SchemaPlus rootSchema = CalciteSchema.createRootSchema(false, false).plus();
+
+ final Multimap<String, org.apache.calcite.schema.Function> functionMap =
+ LinkedListMultimap.create();
+ // create schema "/a"
+ final SchemaPlus aSchema = rootSchema.add("a",
+ new AbstractSchema() {
+ @Override protected Multimap<String, org.apache.calcite.schema.Function>
+ getFunctionMultimap() {
+ return functionMap;
+ }
+ });
+ // add view definition
+ final String viewName = "V";
+ final org.apache.calcite.schema.Function view =
+ ViewTable.viewMacro(rootSchema.getSubSchema("a"),
+ "values('1', '2')", null, null, false);
+ functionMap.put(viewName, view);
+
+ final CalciteSchema calciteSchema = CalciteSchema.from(aSchema);
+ assertThat(
+ calciteSchema.getTableBasedOnNullaryFunction(viewName, true), notNullValue());
+ assertThat(
+ calciteSchema.getTableBasedOnNullaryFunction(viewName, false), notNullValue());
+ assertThat(
+ calciteSchema.getTableBasedOnNullaryFunction("V1", true), nullValue());
+ assertThat(
+ calciteSchema.getTableBasedOnNullaryFunction("V1", false), nullValue());
+
+ assertThat(calciteSchema.getFunctions(viewName, true), hasItem(view));
+ assertThat(calciteSchema.getFunctions(viewName, false), hasItem(view));
+ assertThat(calciteSchema.getFunctions("V1", true), not(hasItem(view)));
+ assertThat(calciteSchema.getFunctions("V1", false), not(hasItem(view)));
+ }
+
@Test public void testSchemaCaching() throws Exception {
final Connection connection =
CalciteAssert.that(CalciteAssert.Config.JDBC_FOODMART).connect();