use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable 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.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project flink by apache.
the class CommonExecLookupJoin method translateToPlanInternal.
@Override
@SuppressWarnings("unchecked")
public Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
RelOptTable temporalTable = temporalTableSourceSpec.getTemporalTable(planner.getFlinkContext());
// validate whether the node is valid and supported.
validate(temporalTable);
final ExecEdge inputEdge = getInputEdges().get(0);
RowType inputRowType = (RowType) inputEdge.getOutputType();
RowType tableSourceRowType = FlinkTypeFactory.toLogicalRowType(temporalTable.getRowType());
RowType resultRowType = (RowType) getOutputType();
validateLookupKeyType(lookupKeys, inputRowType, tableSourceRowType);
boolean isAsyncEnabled = false;
UserDefinedFunction userDefinedFunction = LookupJoinUtil.getLookupFunction(temporalTable, lookupKeys.keySet());
UserDefinedFunctionHelper.prepareInstance(config, userDefinedFunction);
if (userDefinedFunction instanceof AsyncTableFunction) {
isAsyncEnabled = true;
}
boolean isLeftOuterJoin = joinType == FlinkJoinType.LEFT;
StreamOperatorFactory<RowData> operatorFactory;
if (isAsyncEnabled) {
operatorFactory = createAsyncLookupJoin(temporalTable, config, lookupKeys, (AsyncTableFunction<Object>) userDefinedFunction, planner.getRelBuilder(), inputRowType, tableSourceRowType, resultRowType, isLeftOuterJoin);
} else {
operatorFactory = createSyncLookupJoin(temporalTable, config, lookupKeys, (TableFunction<Object>) userDefinedFunction, planner.getRelBuilder(), inputRowType, tableSourceRowType, resultRowType, isLeftOuterJoin, planner.getExecEnv().getConfig().isObjectReuseEnabled());
}
Transformation<RowData> inputTransformation = (Transformation<RowData>) inputEdge.translateToPlan(planner);
return ExecNodeUtil.createOneInputTransformation(inputTransformation, createTransformationMeta(LOOKUP_JOIN_TRANSFORMATION, config), operatorFactory, InternalTypeInfo.of(resultRowType), inputTransformation.getParallelism());
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project flink by apache.
the class SqlValidatorImpl method createTargetRowType.
/**
* Derives a row-type for INSERT and UPDATE operations.
*
* @param table Target table for INSERT/UPDATE
* @param targetColumnList List of target columns, or null if not specified
* @param append Whether to append fields to those in <code>
* baseRowType</code>
* @return Rowtype
*/
protected RelDataType createTargetRowType(SqlValidatorTable table, SqlNodeList targetColumnList, boolean append) {
RelDataType baseRowType = table.getRowType();
if (targetColumnList == null) {
return baseRowType;
}
List<RelDataTypeField> targetFields = baseRowType.getFieldList();
final List<Map.Entry<String, RelDataType>> fields = new ArrayList<>();
if (append) {
for (RelDataTypeField targetField : targetFields) {
fields.add(Pair.of(SqlUtil.deriveAliasFromOrdinal(fields.size()), targetField.getType()));
}
}
final Set<Integer> assignedFields = new HashSet<>();
final RelOptTable relOptTable = table instanceof RelOptTable ? ((RelOptTable) table) : null;
for (SqlNode node : targetColumnList) {
SqlIdentifier id = (SqlIdentifier) node;
RelDataTypeField targetField = SqlValidatorUtil.getTargetField(baseRowType, typeFactory, id, catalogReader, relOptTable);
if (targetField == null) {
throw newValidationError(id, RESOURCE.unknownTargetColumn(id.toString()));
}
if (!assignedFields.add(targetField.getIndex())) {
throw newValidationError(id, RESOURCE.duplicateTargetColumn(targetField.getName()));
}
fields.add(targetField);
}
return typeFactory.createStructType(fields);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project flink by apache.
the class LogicalTableScan method create.
// END FLINK MODIFICATION
/**
* Creates a LogicalTableScan.
*
* @param cluster Cluster
* @param relOptTable Table
* @param hints The hints
*/
public static LogicalTableScan create(RelOptCluster cluster, final RelOptTable relOptTable, List<RelHint> hints) {
final Table table = relOptTable.unwrap(Table.class);
final RelTraitSet traitSet = cluster.traitSetOf(Convention.NONE).replaceIfs(RelCollationTraitDef.INSTANCE, () -> {
if (table != null) {
return table.getStatistic().getCollations();
}
return ImmutableList.of();
});
return new LogicalTableScan(cluster, traitSet, hints, relOptTable);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable in project flink by apache.
the class LookupJoinUtil method getLookupFunction.
/**
* Gets LookupFunction from temporal table according to the given lookup keys.
*/
public static UserDefinedFunction getLookupFunction(RelOptTable temporalTable, Collection<Integer> lookupKeys) {
int[] lookupKeyIndicesInOrder = getOrderedLookupKeys(lookupKeys);
if (temporalTable instanceof TableSourceTable) {
// TODO: support nested lookup keys in the future,
// currently we only support top-level lookup keys
int[][] indices = IntStream.of(lookupKeyIndicesInOrder).mapToObj(i -> new int[] { i }).toArray(int[][]::new);
LookupTableSource tableSource = (LookupTableSource) ((TableSourceTable) temporalTable).tableSource();
LookupRuntimeProviderContext providerContext = new LookupRuntimeProviderContext(indices);
LookupTableSource.LookupRuntimeProvider provider = tableSource.getLookupRuntimeProvider(providerContext);
if (provider instanceof TableFunctionProvider) {
return ((TableFunctionProvider<?>) provider).createTableFunction();
} else if (provider instanceof AsyncTableFunctionProvider) {
return ((AsyncTableFunctionProvider<?>) provider).createAsyncTableFunction();
}
}
if (temporalTable instanceof LegacyTableSourceTable) {
String[] lookupFieldNamesInOrder = IntStream.of(lookupKeyIndicesInOrder).mapToObj(temporalTable.getRowType().getFieldNames()::get).toArray(String[]::new);
LegacyTableSourceTable<?> legacyTableSourceTable = (LegacyTableSourceTable<?>) temporalTable;
LookupableTableSource<?> tableSource = (LookupableTableSource<?>) legacyTableSourceTable.tableSource();
if (tableSource.isAsyncEnabled()) {
return tableSource.getAsyncLookupFunction(lookupFieldNamesInOrder);
} else {
return tableSource.getLookupFunction(lookupFieldNamesInOrder);
}
}
throw new TableException(String.format("table %s is neither TableSourceTable not LegacyTableSourceTable", temporalTable.getQualifiedName()));
}
Aggregations