use of org.apache.calcite.schema.FilterableTable in project calcite by apache.
the class TableScanNode method create.
/**
* Creates a TableScanNode.
*
* <p>Tries various table SPIs, and negotiates with the table which filters
* and projects it can implement. Adds to the Enumerable implementations of
* any filters and projects that cannot be implemented by the table.
*/
static TableScanNode create(Compiler compiler, TableScan rel, ImmutableList<RexNode> filters, ImmutableIntList projects) {
final RelOptTable relOptTable = rel.getTable();
final ProjectableFilterableTable pfTable = relOptTable.unwrap(ProjectableFilterableTable.class);
if (pfTable != null) {
return createProjectableFilterable(compiler, rel, filters, projects, pfTable);
}
final FilterableTable filterableTable = relOptTable.unwrap(FilterableTable.class);
if (filterableTable != null) {
return createFilterable(compiler, rel, filters, projects, filterableTable);
}
final ScannableTable scannableTable = relOptTable.unwrap(ScannableTable.class);
if (scannableTable != null) {
return createScannable(compiler, rel, filters, projects, scannableTable);
}
// noinspection unchecked
final Enumerable<Row> enumerable = relOptTable.unwrap(Enumerable.class);
if (enumerable != null) {
return createEnumerable(compiler, rel, enumerable, null, filters, projects);
}
final QueryableTable queryableTable = relOptTable.unwrap(QueryableTable.class);
if (queryableTable != null) {
return createQueryable(compiler, rel, filters, projects, queryableTable);
}
throw new AssertionError("cannot convert table " + relOptTable + " to enumerable");
}
use of org.apache.calcite.schema.FilterableTable in project calcite by apache.
the class EnumerableTableScan method deduceElementType.
public static Class deduceElementType(Table table) {
if (table instanceof QueryableTable) {
final QueryableTable queryableTable = (QueryableTable) table;
final Type type = queryableTable.getElementType();
if (type instanceof Class) {
return (Class) type;
} else {
return Object[].class;
}
} else if (table instanceof ScannableTable || table instanceof FilterableTable || table instanceof ProjectableFilterableTable || table instanceof StreamableTable) {
return Object[].class;
} else {
return Object.class;
}
}
use of org.apache.calcite.schema.FilterableTable in project calcite by apache.
the class RelOptTableImpl method toRel.
public RelNode toRel(ToRelContext context) {
// RelOptTable by replacing with immutable RelRecordType using the same field list.
if (this.getRowType().isDynamicStruct()) {
final RelDataType staticRowType = new RelRecordType(getRowType().getFieldList());
final RelOptTable relOptTable = this.copy(staticRowType);
return relOptTable.toRel(context);
}
// If there are any virtual columns, create a copy of this table without
// those virtual columns.
final List<ColumnStrategy> strategies = getColumnStrategies();
if (strategies.contains(ColumnStrategy.VIRTUAL)) {
final RelDataTypeFactory.Builder b = context.getCluster().getTypeFactory().builder();
for (RelDataTypeField field : rowType.getFieldList()) {
if (strategies.get(field.getIndex()) != ColumnStrategy.VIRTUAL) {
b.add(field.getName(), field.getType());
}
}
final RelOptTable relOptTable = new RelOptTableImpl(this.schema, b.build(), this.names, this.table, this.expressionFunction, this.rowCount) {
@Override
public <T> T unwrap(Class<T> clazz) {
if (clazz.isAssignableFrom(InitializerExpressionFactory.class)) {
return clazz.cast(NullInitializerExpressionFactory.INSTANCE);
}
return super.unwrap(clazz);
}
};
return relOptTable.toRel(context);
}
if (table instanceof TranslatableTable) {
return ((TranslatableTable) table).toRel(context, this);
}
final RelOptCluster cluster = context.getCluster();
if (Hook.ENABLE_BINDABLE.get(false)) {
return LogicalTableScan.create(cluster, this);
}
if (CalcitePrepareImpl.ENABLE_ENUMERABLE && table instanceof QueryableTable) {
return EnumerableTableScan.create(cluster, this);
}
if (table instanceof ScannableTable || table instanceof FilterableTable || table instanceof ProjectableFilterableTable) {
return LogicalTableScan.create(cluster, this);
}
if (CalcitePrepareImpl.ENABLE_ENUMERABLE) {
return EnumerableTableScan.create(cluster, this);
}
throw new AssertionError();
}
use of org.apache.calcite.schema.FilterableTable 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.FilterableTable in project calcite by apache.
the class ScannableTableTest method testFilterableTableNonCooperative.
/**
* A filter on a {@link FilterableTable} with two columns (noncooperative).
*/
@Test
public void testFilterableTableNonCooperative() throws Exception {
final StringBuilder buf = new StringBuilder();
final Table table = new BeatlesFilterableTable(buf, false);
final String explain = "PLAN=" + "EnumerableInterpreter\n" + " BindableTableScan(table=[[s, beatles2]], filters=[[=($0, 4)]])";
CalciteAssert.that().with(newSchema("s", "beatles2", table)).query("select * from \"s\".\"beatles2\" where \"i\" = 4").explainContains(explain).returnsUnordered("i=4; j=John; k=1940", "i=4; j=Paul; k=1942");
assertThat(buf.toString(), is("returnCount=4"));
}
Aggregations