use of org.apache.calcite.schema.Table in project calcite by apache.
the class RelOptTableImpl method create.
public static RelOptTableImpl create(RelOptSchema schema, RelDataType rowType, final CalciteSchema.TableEntry tableEntry, Double rowCount) {
final Table table = tableEntry.getTable();
Function<Class, Expression> expressionFunction = getClassExpressionFunction(tableEntry, table);
return new RelOptTableImpl(schema, rowType, tableEntry.path(), table, expressionFunction, rowCount);
}
use of org.apache.calcite.schema.Table in project calcite by apache.
the class EmptyScope method resolve_.
private void resolve_(final CalciteSchema rootSchema, List<String> names, List<String> schemaNames, SqlNameMatcher nameMatcher, Path path, Resolved resolved) {
final List<String> concat = ImmutableList.<String>builder().addAll(schemaNames).addAll(names).build();
CalciteSchema schema = rootSchema;
SqlValidatorNamespace namespace = null;
List<String> remainingNames = concat;
for (String schemaName : concat) {
if (schema == rootSchema && nameMatcher.matches(schemaName, schema.name)) {
remainingNames = Util.skip(remainingNames);
continue;
}
final CalciteSchema subSchema = schema.getSubSchema(schemaName, nameMatcher.isCaseSensitive());
if (subSchema != null) {
path = path.plus(null, -1, subSchema.name, StructKind.NONE);
remainingNames = Util.skip(remainingNames);
schema = subSchema;
namespace = new SchemaNamespace(validator, ImmutableList.copyOf(path.stepNames()));
continue;
}
CalciteSchema.TableEntry entry = schema.getTable(schemaName, nameMatcher.isCaseSensitive());
if (entry == null) {
entry = schema.getTableBasedOnNullaryFunction(schemaName, nameMatcher.isCaseSensitive());
}
if (entry != null) {
path = path.plus(null, -1, entry.name, StructKind.NONE);
remainingNames = Util.skip(remainingNames);
final Table table = entry.getTable();
SqlValidatorTable table2 = null;
if (table instanceof Wrapper) {
table2 = ((Wrapper) table).unwrap(Prepare.PreparingTable.class);
}
if (table2 == null) {
final RelOptSchema relOptSchema = validator.catalogReader.unwrap(RelOptSchema.class);
final RelDataType rowType = table.getRowType(validator.typeFactory);
table2 = RelOptTableImpl.create(relOptSchema, rowType, entry, null);
}
namespace = new TableNamespace(validator, table2);
resolved.found(namespace, false, this, path, remainingNames);
return;
}
// neither sub-schema nor table
if (namespace != null && !remainingNames.equals(names)) {
resolved.found(namespace, false, this, path, remainingNames);
}
return;
}
}
use of org.apache.calcite.schema.Table in project calcite by apache.
the class ScannableTableTest method testPFPushDownProjectFilterAggregateNested.
@Test
public void testPFPushDownProjectFilterAggregateNested() {
final StringBuilder buf = new StringBuilder();
final String sql = "select \"k\", count(*) as c\n" + "from (\n" + " select \"k\", \"i\" from \"s\".\"beatles\" group by \"k\", \"i\") t\n" + "where \"k\" = 1940\n" + "group by \"k\"";
final Table table = new BeatlesProjectableFilterableTable(buf, false);
final String explain = "PLAN=" + "EnumerableAggregate(group=[{0}], C=[COUNT()])\n" + " EnumerableAggregate(group=[{0, 1}])\n" + " EnumerableInterpreter\n" + " BindableTableScan(table=[[s, beatles]], " + "filters=[[=($2, 1940)]], projects=[[2, 0]])";
CalciteAssert.that().with(newSchema("s", "beatles", table)).query(sql).explainContains(explain).returnsUnordered("k=1940; C=2");
}
use of org.apache.calcite.schema.Table in project calcite by apache.
the class ScannableTableTest method testFilterableTableCooperative.
/**
* A filter on a {@link FilterableTable} with two columns (cooperative).
*/
@Test
public void testFilterableTableCooperative() throws Exception {
final StringBuilder buf = new StringBuilder();
final Table table = new BeatlesFilterableTable(buf, true);
final String explain = "PLAN=" + "EnumerableInterpreter\n" + " BindableTableScan(table=[[s, beatles]], filters=[[=($0, 4)]])";
CalciteAssert.that().with(newSchema("s", "beatles", table)).query("select * from \"s\".\"beatles\" where \"i\" = 4").explainContains(explain).returnsUnordered("i=4; j=John; k=1940", "i=4; j=Paul; k=1942");
// Only 2 rows came out of the table. If the value is 4, it means that the
// planner did not pass the filter down.
assertThat(buf.toString(), is("returnCount=2, filter=4"));
}
use of org.apache.calcite.schema.Table in project calcite by apache.
the class ScannableTableTest method testCannotPushProject.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-2039">[CALCITE-2039]
* AssertionError when pushing project to ProjectableFilterableTable</a>.
* Cannot push down a project if it is not a permutation of columns; in this
* case, it contains a literal.
*/
@Test
public void testCannotPushProject() throws Exception {
final StringBuilder buf = new StringBuilder();
final Table table = new BeatlesProjectableFilterableTable(buf, true);
final String explain = "PLAN=" + "EnumerableCalc(expr#0..2=[{inputs}], expr#3=[3], k=[$t2], j=[$t1], " + "i=[$t0], EXPR$3=[$t3])\n" + " EnumerableInterpreter\n" + " BindableTableScan(table=[[s, beatles]])";
CalciteAssert.that().with(newSchema("s", "beatles", table)).query("select \"k\",\"j\",\"i\",3 from \"s\".\"beatles\"").explainContains(explain).returnsUnordered("k=1940; j=John; i=4; EXPR$3=3", "k=1940; j=Ringo; i=5; EXPR$3=3", "k=1942; j=Paul; i=4; EXPR$3=3", "k=1943; j=George; i=6; EXPR$3=3");
assertThat(buf.toString(), is("returnCount=4"));
}
Aggregations