use of org.apache.calcite.rel.logical.LogicalTableScan in project calcite by apache.
the class TableScanRule method onMatch.
// ~ Methods ----------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
final LogicalTableScan oldRel = call.rel(0);
RelNode newRel = oldRel.getTable().toRel(RelOptUtil.getContext(oldRel.getCluster()));
call.transformTo(newRel);
}
use of org.apache.calcite.rel.logical.LogicalTableScan in project calcite by apache.
the class RelWriterTest method testWriter.
/**
* Unit test for {@link org.apache.calcite.rel.externalize.RelJsonWriter} on
* a simple tree of relational expressions, consisting of a table, a filter
* and an aggregate node.
*/
@Test
public void testWriter() {
String s = Frameworks.withPlanner(new Frameworks.PlannerAction<String>() {
public String apply(RelOptCluster cluster, RelOptSchema relOptSchema, SchemaPlus rootSchema) {
rootSchema.add("hr", new ReflectiveSchema(new JdbcTest.HrSchema()));
LogicalTableScan scan = LogicalTableScan.create(cluster, relOptSchema.getTableForMember(Arrays.asList("hr", "emps")));
final RexBuilder rexBuilder = cluster.getRexBuilder();
LogicalFilter filter = LogicalFilter.create(scan, rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, rexBuilder.makeFieldAccess(rexBuilder.makeRangeReference(scan), "deptno", true), rexBuilder.makeExactLiteral(BigDecimal.TEN)));
final RelJsonWriter writer = new RelJsonWriter();
final RelDataType bigIntType = cluster.getTypeFactory().createSqlType(SqlTypeName.BIGINT);
LogicalAggregate aggregate = LogicalAggregate.create(filter, ImmutableBitSet.of(0), null, ImmutableList.of(AggregateCall.create(SqlStdOperatorTable.COUNT, true, false, ImmutableList.of(1), -1, bigIntType, "c"), AggregateCall.create(SqlStdOperatorTable.COUNT, false, false, ImmutableList.<Integer>of(), -1, bigIntType, "d")));
aggregate.explain(writer);
return writer.asString();
}
});
assertThat(s, is(XX));
}
use of org.apache.calcite.rel.logical.LogicalTableScan in project druid by druid-io.
the class DruidTableScanRule method onMatch.
@Override
public void onMatch(final RelOptRuleCall call) {
final LogicalTableScan scan = call.rel(0);
final RelOptTable table = scan.getTable();
final DruidTable druidTable = table.unwrap(DruidTable.class);
if (druidTable != null) {
call.transformTo(DruidQueryRel.scanTable(scan, table, druidTable, plannerContext));
}
}
use of org.apache.calcite.rel.logical.LogicalTableScan in project flink by apache.
the class PushProjectIntoTableSourceScanRule method getPrimaryKeyProjections.
private List<RexNode> getPrimaryKeyProjections(LogicalTableScan scan) {
final TableSourceTable source = scan.getTable().unwrap(TableSourceTable.class);
final ResolvedSchema schema = source.contextResolvedTable().getResolvedSchema();
if (!schema.getPrimaryKey().isPresent()) {
return Collections.emptyList();
}
final FlinkTypeFactory typeFactory = unwrapTypeFactory(scan);
final UniqueConstraint primaryKey = schema.getPrimaryKey().get();
return primaryKey.getColumns().stream().map(columnName -> {
final int idx = scan.getRowType().getFieldNames().indexOf(columnName);
final Column column = schema.getColumn(idx).orElseThrow(() -> new TableException(String.format("Column at index %d not found.", idx)));
return new RexInputRef(idx, typeFactory.createFieldTypeFromLogicalType(column.getDataType().getLogicalType()));
}).collect(Collectors.toList());
}
use of org.apache.calcite.rel.logical.LogicalTableScan in project flink by apache.
the class DynamicSourceUtils method pushTableScan.
private static void pushTableScan(boolean isBatchMode, FlinkRelBuilder relBuilder, ContextResolvedTable contextResolvedTable, FlinkStatistic statistic, List<RelHint> hints, DynamicTableSource tableSource) {
final RowType producedType = createProducedType(contextResolvedTable.getResolvedSchema(), tableSource);
final RelDataType producedRelDataType = relBuilder.getTypeFactory().buildRelNodeRowType(producedType);
final TableSourceTable tableSourceTable = new TableSourceTable(relBuilder.getRelOptSchema(), producedRelDataType, statistic, tableSource, !isBatchMode, contextResolvedTable, ShortcutUtils.unwrapContext(relBuilder), new SourceAbilitySpec[0]);
final LogicalTableScan scan = LogicalTableScan.create(relBuilder.getCluster(), tableSourceTable, hints);
relBuilder.push(scan);
}
Aggregations