use of org.apache.calcite.rel.hint.RelHint in project flink by apache.
the class CatalogSourceTable method toRel.
@Override
public RelNode toRel(ToRelContext toRelContext) {
final RelOptCluster cluster = toRelContext.getCluster();
final List<RelHint> hints = toRelContext.getTableHints();
final FlinkContext context = ShortcutUtils.unwrapContext(cluster);
final FlinkRelBuilder relBuilder = FlinkRelBuilder.of(cluster, relOptSchema);
// finalize catalog table with option hints
final Map<String, String> hintedOptions = FlinkHints.getHintedOptions(hints);
final ContextResolvedTable catalogTable = computeContextResolvedTable(context, hintedOptions);
// create table source
final DynamicTableSource tableSource = createDynamicTableSource(context, catalogTable.getResolvedTable());
// prepare table source and convert to RelNode
return DynamicSourceUtils.convertSourceToRel(!schemaTable.isStreamingMode(), context.getTableConfig().getConfiguration(), relBuilder, schemaTable.getContextResolvedTable(), schemaTable.getStatistic(), hints, tableSource);
}
use of org.apache.calcite.rel.hint.RelHint in project flink by apache.
the class SqlToOperationConverter method convertSqlInsert.
/**
* Convert insert into statement.
*/
private Operation convertSqlInsert(RichSqlInsert insert) {
// Get sink table name.
List<String> targetTablePath = ((SqlIdentifier) insert.getTargetTableID()).names;
// Get sink table hints.
HintStrategyTable hintStrategyTable = flinkPlanner.config().getSqlToRelConverterConfig().getHintStrategyTable();
List<RelHint> tableHints = SqlUtil.getRelHint(hintStrategyTable, insert.getTableHints());
Map<String, String> dynamicOptions = FlinkHints.getHintedOptions(tableHints);
UnresolvedIdentifier unresolvedIdentifier = UnresolvedIdentifier.of(targetTablePath);
ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
ContextResolvedTable contextResolvedTable = catalogManager.getTableOrError(identifier);
PlannerQueryOperation query = (PlannerQueryOperation) convertValidatedSqlNodeOrFail(flinkPlanner, catalogManager, insert.getSource());
return new SinkModifyOperation(contextResolvedTable, query, insert.getStaticPartitionKVs(), insert.isOverwrite(), dynamicOptions);
}
use of org.apache.calcite.rel.hint.RelHint in project flink by apache.
the class DynamicSinkUtils method convertSinkToRel.
private static RelNode convertSinkToRel(FlinkRelBuilder relBuilder, RelNode input, Map<String, String> dynamicOptions, ContextResolvedTable contextResolvedTable, Map<String, String> staticPartitions, boolean isOverwrite, DynamicTableSink sink) {
final DataTypeFactory dataTypeFactory = unwrapContext(relBuilder).getCatalogManager().getDataTypeFactory();
final FlinkTypeFactory typeFactory = unwrapTypeFactory(relBuilder);
final ResolvedSchema schema = contextResolvedTable.getResolvedSchema();
final String tableDebugName = contextResolvedTable.getIdentifier().asSummaryString();
List<SinkAbilitySpec> sinkAbilitySpecs = new ArrayList<>();
// 1. prepare table sink
prepareDynamicSink(tableDebugName, staticPartitions, isOverwrite, sink, contextResolvedTable.getResolvedTable(), sinkAbilitySpecs);
sinkAbilitySpecs.forEach(spec -> spec.apply(sink));
// 2. validate the query schema to the sink's table schema and apply cast if possible
final RelNode query = validateSchemaAndApplyImplicitCast(input, schema, tableDebugName, dataTypeFactory, typeFactory);
relBuilder.push(query);
// 3. convert the sink's table schema to the consumed data type of the sink
final List<Integer> metadataColumns = extractPersistedMetadataColumns(schema);
if (!metadataColumns.isEmpty()) {
pushMetadataProjection(relBuilder, typeFactory, schema, sink);
}
List<RelHint> hints = new ArrayList<>();
if (!dynamicOptions.isEmpty()) {
hints.add(RelHint.builder("OPTIONS").hintOptions(dynamicOptions).build());
}
final RelNode finalQuery = relBuilder.build();
return LogicalSink.create(finalQuery, hints, contextResolvedTable, sink, staticPartitions, sinkAbilitySpecs.toArray(new SinkAbilitySpec[0]));
}
Aggregations