Java Code Examples for org.apache.calcite.rel.logical.LogicalTableScan#create()

The following examples show how to use org.apache.calcite.rel.logical.LogicalTableScan#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MockCatalogReader.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public RelNode toRel(ToRelContext context) {
  RelNode rel = LogicalTableScan.create(context.getCluster(), fromTable,
      context.getTableHints());
  final RexBuilder rexBuilder = context.getCluster().getRexBuilder();
  rel = LogicalFilter.create(
      rel, getConstraint(rexBuilder, rel.getRowType()));
  final List<RelDataTypeField> fieldList =
      rel.getRowType().getFieldList();
  final List<Pair<RexNode, String>> projects =
      new AbstractList<Pair<RexNode, String>>() {
        @Override public Pair<RexNode, String> get(int index) {
          return RexInputRef.of2(mapping.get(index), fieldList);
        }

        @Override public int size() {
          return mapping.size();
        }
      };
  return LogicalProject.create(rel,
      ImmutableList.of(),
      Pair.left(projects),
      Pair.right(projects));
}
 
Example 2
Source File: StreamRules.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public void onMatch(RelOptRuleCall call) {
  final Delta delta = call.rel(0);
  final TableScan scan = call.rel(1);
  final RelOptCluster cluster = delta.getCluster();
  final RelOptTable relOptTable = scan.getTable();
  final StreamableTable streamableTable =
      relOptTable.unwrap(StreamableTable.class);
  if (streamableTable != null) {
    final Table table1 = streamableTable.stream();
    final RelOptTable relOptTable2 =
        RelOptTableImpl.create(relOptTable.getRelOptSchema(),
            relOptTable.getRowType(), table1,
            ImmutableList.<String>builder()
                .addAll(relOptTable.getQualifiedName())
                .add("(STREAM)").build());
    final LogicalTableScan newScan =
        LogicalTableScan.create(cluster, relOptTable2, scan.getHints());
    call.transformTo(newScan);
  }
}
 
Example 3
Source File: QueryOperationConverter.java    From flink with Apache License 2.0 6 votes vote down vote up
private RelNode convertToDataStreamScan(DataStreamQueryOperation<?> operation) {
	DataStreamTable<?> dataStreamTable = new DataStreamTable<>(
			operation.getDataStream(),
			operation.isProducesUpdates(),
			operation.isAccRetract(),
			operation.getFieldIndices(),
			operation.getTableSchema().getFieldNames(),
			operation.getStatistic(),
			scala.Option.apply(operation.getFieldNullables()));

	List<String> names;
	if (operation.getQualifiedName() != null) {
		names = operation.getQualifiedName();
	} else {
		String refId = String.format("Unregistered_DataStream_%s", operation.getDataStream().getId());
		names = Collections.singletonList(refId);
	}

	FlinkRelOptTable table = FlinkRelOptTable.create(
			relBuilder.getRelOptSchema(),
			dataStreamTable.getRowType(relBuilder.getTypeFactory()),
			names,
			dataStreamTable);
	return LogicalTableScan.create(relBuilder.getCluster(), table);
}
 
Example 4
Source File: QueryOperationConverter.java    From flink with Apache License 2.0 6 votes vote down vote up
private RelNode convertToDataStreamScan(DataStream<?> dataStream, int[] fieldIndices, TableSchema tableSchema) {
	DataStreamTable<?> dataStreamTable = new DataStreamTable<>(
		dataStream,
		false,
		false,
		fieldIndices,
		tableSchema.getFieldNames(),
		FlinkStatistic.UNKNOWN(),
		scala.Option.empty());

	String refId = String.format("Unregistered_DataStream_%s", dataStream.getId());
	FlinkRelOptTable table = FlinkRelOptTable.create(
		relBuilder.getRelOptSchema(),
		dataStreamTable.getRowType(relBuilder.getTypeFactory()),
		Collections.singletonList(refId),
		dataStreamTable);
	return LogicalTableScan.create(relBuilder.getCluster(), table);
}
 
Example 5
Source File: PushDownLogicTableRule.java    From Mycat2 with GNU General Public License v3.0 6 votes vote down vote up
@NotNull
private RelNode global(RelOptCluster cluster,
                       Bindables.BindableTableScan bindableTableScan,
                       RelOptSchema relOptSchema,
                       MycatLogicTable logicTable) {
    final HashSet<String> context = new HashSet<>();
    RelNode logicalTableScan;
    MycatPhysicalTable mycatPhysicalTable = logicTable.getMycatGlobalPhysicalTable(context);
    RelOptTable dataNode = RelOptTableImpl.create(
            relOptSchema,
            logicTable.getRowType(cluster.getTypeFactory()),//这里使用logicTable,避免类型不一致
            mycatPhysicalTable,
            ImmutableList.of(mycatPhysicalTable.getBackendTableInfo().getUniqueName()));
    logicalTableScan = LogicalTableScan.create(cluster, dataNode, ImmutableList.of());
    return RelOptUtil.createProject(RelOptUtil.createFilter(logicalTableScan, bindableTableScan.filters), bindableTableScan.projects);
}
 
Example 6
Source File: QueryableRelBuilder.java    From calcite with Apache License 2.0 6 votes vote down vote up
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.toRelContext(),
          relOptTable);
    } else {
      return LogicalTableScan.create(translator.cluster, relOptTable, ImmutableList.of());
    }
  }
  return translator.translate(queryable.getExpression());
}
 
Example 7
Source File: StreamRules.java    From Bats with Apache License 2.0 6 votes vote down vote up
@Override public void onMatch(RelOptRuleCall call) {
  final Delta delta = call.rel(0);
  final TableScan scan = call.rel(1);
  final RelOptCluster cluster = delta.getCluster();
  final RelOptTable relOptTable = scan.getTable();
  final StreamableTable streamableTable =
      relOptTable.unwrap(StreamableTable.class);
  if (streamableTable != null) {
    final Table table1 = streamableTable.stream();
    final RelOptTable relOptTable2 =
        RelOptTableImpl.create(relOptTable.getRelOptSchema(),
            relOptTable.getRowType(), table1,
            ImmutableList.<String>builder()
                .addAll(relOptTable.getQualifiedName())
                .add("(STREAM)").build());
    final LogicalTableScan newScan =
        LogicalTableScan.create(cluster, relOptTable2);
    call.transformTo(newScan);
  }
}
 
Example 8
Source File: CrelUniqifier.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public RelNode visit(RelNode other) {
  if(!data.add(other)) {
    if (other instanceof LogicalTableScan) {
      // LogicalTableScan does not have implementation of a deep copy. Create a new instance.
      other = LogicalTableScan.create(other.getCluster(), other.getTable());
    } else {
      other = other.copy(other.getTraitSet(), other.getInputs());
    }
  }

  return super.visit(other);
}
 
Example 9
Source File: DruidTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
public RelNode toRel(RelOptTable.ToRelContext context,
    RelOptTable relOptTable) {
  final RelOptCluster cluster = context.getCluster();
  final TableScan scan = LogicalTableScan.create(cluster, relOptTable, ImmutableList.of());
  return DruidQuery.create(cluster,
      cluster.traitSetOf(BindableConvention.INSTANCE), relOptTable, this,
      ImmutableList.of(scan));
}
 
Example 10
Source File: QueryOperationConverter.java    From flink with Apache License 2.0 5 votes vote down vote up
private RelNode convertToDataStreamScan(
		DataStream<?> dataStream,
		int[] fieldIndices,
		TableSchema tableSchema,
		Optional<ObjectIdentifier> identifier) {
	List<String> names;
	if (identifier.isPresent()) {
		names = Arrays.asList(
			identifier.get().getCatalogName(),
			identifier.get().getDatabaseName(),
			identifier.get().getObjectName());
	} else {
		String refId = String.format("Unregistered_DataStream_%s", dataStream.getId());
		names = Collections.singletonList(refId);
	}
		final RelDataType rowType = DataStreamTable$.MODULE$
			.getRowType(relBuilder.getTypeFactory(),
				dataStream,
				tableSchema.getFieldNames(),
				fieldIndices,
				scala.Option.empty());
	DataStreamTable<?> dataStreamTable = new DataStreamTable<>(
		relBuilder.getRelOptSchema(),
		names,
		rowType,
		dataStream,
		fieldIndices,
		tableSchema.getFieldNames(),
		FlinkStatistic.UNKNOWN(),
		scala.Option.empty());
	return LogicalTableScan.create(relBuilder.getCluster(), dataStreamTable);
}
 
Example 11
Source File: QueryOperationConverter.java    From flink with Apache License 2.0 5 votes vote down vote up
private RelNode convertToDataStreamScan(DataStreamQueryOperation<?> operation) {
	List<String> names;
	ObjectIdentifier identifier = operation.getIdentifier();
	if (identifier != null) {
		names = Arrays.asList(
			identifier.getCatalogName(),
			identifier.getDatabaseName(),
			identifier.getObjectName());
	} else {
		String refId = String.format("Unregistered_DataStream_%s", operation.getDataStream().getId());
		names = Collections.singletonList(refId);
	}

	final RelDataType rowType = DataStreamTable$.MODULE$
		.getRowType(relBuilder.getTypeFactory(),
			operation.getDataStream(),
			operation.getTableSchema().getFieldNames(),
			operation.getFieldIndices(),
			scala.Option.apply(operation.getFieldNullables()));
	DataStreamTable<?> dataStreamTable = new DataStreamTable<>(
		relBuilder.getRelOptSchema(),
		names,
		rowType,
		operation.getDataStream(),
		operation.getFieldIndices(),
		operation.getTableSchema().getFieldNames(),
		operation.getStatistic(),
		scala.Option.apply(operation.getFieldNullables()));
	return LogicalTableScan.create(relBuilder.getCluster(), dataStreamTable);
}
 
Example 12
Source File: PushDownLogicTableRule.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
@NotNull
private static RelNode getBindableTableScan(Bindables.BindableTableScan bindableTableScan, RelOptCluster cluster, RelOptSchema relOptSchema, DataNode backendTableInfo) {
    String uniqueName = backendTableInfo.getUniqueName();
    MycatLogicTable unwrap = bindableTableScan.getTable().unwrap(MycatLogicTable.class);
    MycatPhysicalTable mycatPhysicalTable = new MycatPhysicalTable(unwrap,backendTableInfo);
    RelOptTable dataNode = RelOptTableImpl.create(
            relOptSchema,
            mycatPhysicalTable.getRowType(cluster.getTypeFactory()),
            mycatPhysicalTable,
            ImmutableList.of(uniqueName));
    RelNode logicalTableScan = LogicalTableScan.create(cluster, dataNode, ImmutableList.of());
    return RelOptUtil.createProject(RelOptUtil.createFilter(logicalTableScan, bindableTableScan.filters), bindableTableScan.projects);
}
 
Example 13
Source File: QueryOperationConverter.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <U> RelNode visit(TableSourceQueryOperation<U> tableSourceOperation) {
	TableSource<?> tableSource = tableSourceOperation.getTableSource();
	boolean isBatch;
	if (tableSource instanceof LookupableTableSource) {
		isBatch = tableSourceOperation.isBatch();
	} else if (tableSource instanceof StreamTableSource) {
		isBatch = ((StreamTableSource<?>) tableSource).isBounded();
	} else {
		throw new TableException(String.format("%s is not supported.", tableSource.getClass().getSimpleName()));
	}

	FlinkStatistic statistic;
	List<String> names;
	if (tableSourceOperation instanceof RichTableSourceQueryOperation &&
		((RichTableSourceQueryOperation<U>) tableSourceOperation).getQualifiedName() != null) {
		statistic = ((RichTableSourceQueryOperation<U>) tableSourceOperation).getStatistic();
		names = ((RichTableSourceQueryOperation<U>) tableSourceOperation).getQualifiedName();
	} else {
		statistic = FlinkStatistic.UNKNOWN();
		// TableSourceScan requires a unique name of a Table for computing a digest.
		// We are using the identity hash of the TableSource object.
		String refId = "Unregistered_TableSource_" + System.identityHashCode(tableSource);
		names = Collections.singletonList(refId);
	}

	TableSourceTable<?> tableSourceTable = new TableSourceTable<>(tableSource, !isBatch, statistic);
	FlinkRelOptTable table = FlinkRelOptTable.create(
		relBuilder.getRelOptSchema(),
		tableSourceTable.getRowType(relBuilder.getTypeFactory()),
		names,
		tableSourceTable);
	return LogicalTableScan.create(relBuilder.getCluster(), table);
}
 
Example 14
Source File: SqlToRelTestBase.java    From calcite with Apache License 2.0 4 votes vote down vote up
public RelNode toRel(ToRelContext context) {
  return LogicalTableScan.create(context.getCluster(), this,
      context.getTableHints());
}
 
Example 15
Source File: MockCatalogReader.java    From calcite with Apache License 2.0 4 votes vote down vote up
public RelNode toRel(ToRelContext context) {
  return LogicalTableScan.create(context.getCluster(), this, context.getTableHints());
}
 
Example 16
Source File: MycatLogicTable.java    From Mycat2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public RelNode toRel(RelOptTable.ToRelContext context, RelOptTable relOptTable) {
    return LogicalTableScan.create(context.getCluster(), relOptTable,ImmutableList.of());
}
 
Example 17
Source File: MycatPhysicalTable.java    From Mycat2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public RelNode toRel(RelOptTable.ToRelContext context, RelOptTable relOptTable) {
    return LogicalTableScan.create(context.getCluster(), relOptTable, ImmutableList.of());
}
 
Example 18
Source File: FlinkPreparingTableBase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public RelNode toRel(RelOptTable.ToRelContext context) {
	return LogicalTableScan.create(context.getCluster(), this);
}
 
Example 19
Source File: RelOptAbstractTable.java    From Bats with Apache License 2.0 4 votes vote down vote up
public RelNode toRel(ToRelContext context) {
  return LogicalTableScan.create(context.getCluster(), this);
}
 
Example 20
Source File: MockCatalogReader.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Override public RelNode toRel(RelOptTable.ToRelContext context, RelOptTable relOptTable) {
  return LogicalTableScan.create(context.getCluster(), relOptTable, context.getTableHints());
}