use of org.apache.calcite.schema.QueryableTable in project calcite by apache.
the class CloneSchema method getTableMap.
@Override
protected Map<String, Table> getTableMap() {
final Map<String, Table> map = new LinkedHashMap<>();
for (String name : sourceSchema.getTableNames()) {
final Table table = sourceSchema.getTable(name);
if (table instanceof QueryableTable) {
final QueryableTable sourceTable = (QueryableTable) table;
map.put(name, createCloneTable(MATERIALIZATION_CONNECTION, sourceTable, name));
}
}
return map;
}
use of org.apache.calcite.schema.QueryableTable 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.QueryableTable 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.QueryableTable in project calcite by apache.
the class CloneSchema method createCloneTable.
public static <T> Table createCloneTable(final JavaTypeFactory typeFactory, final RelProtoDataType protoRowType, final List<RelCollation> collations, final List<ColumnMetaData.Rep> repList, final Enumerable<T> source) {
final Type elementType;
if (source instanceof QueryableTable) {
elementType = ((QueryableTable) source).getElementType();
} else if (protoRowType.apply(typeFactory).getFieldCount() == 1) {
if (repList != null) {
elementType = repList.get(0).clazz;
} else {
elementType = Object.class;
}
} else {
elementType = Object[].class;
}
return new ArrayTable(elementType, protoRowType, Suppliers.memoize(new Supplier<ArrayTable.Content>() {
public ArrayTable.Content get() {
final ColumnLoader loader = new ColumnLoader<>(typeFactory, source, protoRowType, repList);
final List<RelCollation> collation2 = collations.isEmpty() && loader.sortField >= 0 ? RelCollations.createSingleton(loader.sortField) : collations;
return new ArrayTable.Content(loader.representationValues, loader.size(), collation2);
}
}));
}
use of org.apache.calcite.schema.QueryableTable in project calcite by apache.
the class QueryableRelBuilder method toRel.
RelNode toRel(Queryable<T> queryable) {
if (queryable instanceof QueryableDefaults.Replayable) {
// noinspection unchecked
((QueryableDefaults.Replayable) queryable).replay(this);
return rel;
}
if (queryable instanceof AbstractTableQueryable) {
final AbstractTableQueryable tableQueryable = (AbstractTableQueryable) queryable;
final QueryableTable table = tableQueryable.table;
final CalciteSchema.TableEntry tableEntry = CalciteSchema.from(tableQueryable.schema).add(tableQueryable.tableName, tableQueryable.table);
final RelOptTableImpl relOptTable = RelOptTableImpl.create(null, table.getRowType(translator.typeFactory), tableEntry, null);
if (table instanceof TranslatableTable) {
return ((TranslatableTable) table).toRel(translator, relOptTable);
} else {
return LogicalTableScan.create(translator.cluster, relOptTable);
}
}
return translator.translate(queryable.getExpression());
}
Aggregations