use of org.apache.flink.configuration.ReadableConfig in project flink by apache.
the class CommonExecSink method applyUpsertMaterialize.
private Transformation<RowData> applyUpsertMaterialize(Transformation<RowData> inputTransform, int[] primaryKeys, int sinkParallelism, ReadableConfig config, RowType physicalRowType) {
GeneratedRecordEqualiser equaliser = new EqualiserCodeGenerator(physicalRowType).generateRecordEqualiser("SinkMaterializeEqualiser");
SinkUpsertMaterializer operator = new SinkUpsertMaterializer(StateConfigUtil.createTtlConfig(config.get(ExecutionConfigOptions.IDLE_STATE_RETENTION).toMillis()), InternalSerializers.create(physicalRowType), equaliser);
final String[] fieldNames = physicalRowType.getFieldNames().toArray(new String[0]);
final List<String> pkFieldNames = Arrays.stream(primaryKeys).mapToObj(idx -> fieldNames[idx]).collect(Collectors.toList());
OneInputTransformation<RowData, RowData> materializeTransform = ExecNodeUtil.createOneInputTransformation(inputTransform, createTransformationMeta(UPSERT_MATERIALIZE_TRANSFORMATION, String.format("SinkMaterializer(pk=[%s])", String.join(", ", pkFieldNames)), "SinkMaterializer", config), operator, inputTransform.getOutputType(), sinkParallelism);
RowDataKeySelector keySelector = KeySelectorUtil.getRowDataSelector(primaryKeys, InternalTypeInfo.of(physicalRowType));
materializeTransform.setStateKeySelector(keySelector);
materializeTransform.setStateKeyType(keySelector.getProducedType());
return materializeTransform;
}
use of org.apache.flink.configuration.ReadableConfig in project flink by apache.
the class CatalogSourceTable method createDynamicTableSource.
private DynamicTableSource createDynamicTableSource(FlinkContext context, ResolvedCatalogTable catalogTable) {
final ReadableConfig config = context.getTableConfig().getConfiguration();
final Optional<DynamicTableSourceFactory> factoryFromCatalog = schemaTable.getContextResolvedTable().getCatalog().flatMap(Catalog::getFactory).map(f -> f instanceof DynamicTableSourceFactory ? (DynamicTableSourceFactory) f : null);
final Optional<DynamicTableSourceFactory> factoryFromModule = context.getModuleManager().getFactory(Module::getTableSourceFactory);
// Since the catalog is more specific, we give it precedence over a factory provided by any
// modules.
final DynamicTableSourceFactory factory = firstPresent(factoryFromCatalog, factoryFromModule).orElse(null);
return FactoryUtil.createDynamicTableSource(factory, schemaTable.getContextResolvedTable().getIdentifier(), catalogTable, config, Thread.currentThread().getContextClassLoader(), schemaTable.isTemporary());
}
use of org.apache.flink.configuration.ReadableConfig in project flink by apache.
the class CatalogSchemaTable method findAndCreateTableSource.
private Optional<TableSource<?>> findAndCreateTableSource() {
Optional<TableSource<?>> tableSource = Optional.empty();
try {
if (contextResolvedTable.getTable() instanceof CatalogTable) {
// Use an empty config for TableSourceFactoryContextImpl since we can't fetch the
// actual TableConfig here. And currently the empty config do not affect the logic.
ReadableConfig config = new Configuration();
TableSourceFactory.Context context = new TableSourceFactoryContextImpl(contextResolvedTable.getIdentifier(), contextResolvedTable.getTable(), config, contextResolvedTable.isTemporary());
TableSource<?> source = TableFactoryUtil.findAndCreateTableSource(context);
if (source instanceof StreamTableSource) {
if (!isStreamingMode && !((StreamTableSource<?>) source).isBounded()) {
throw new ValidationException("Cannot query on an unbounded source in batch mode, but " + contextResolvedTable.getIdentifier().asSummaryString() + " is unbounded.");
}
tableSource = Optional.of(source);
} else {
throw new ValidationException("Catalog tables only support " + "StreamTableSource and InputFormatTableSource.");
}
}
} catch (Exception e) {
tableSource = Optional.empty();
}
return tableSource;
}
Aggregations