Search in sources :

Example 1 with TableBufferReducedStatementExecutor

use of org.apache.flink.connector.jdbc.internal.executor.TableBufferReducedStatementExecutor in project flink by apache.

the class JdbcOutputFormatBuilder method createBufferReduceExecutor.

private static JdbcBatchStatementExecutor<RowData> createBufferReduceExecutor(JdbcDmlOptions opt, RuntimeContext ctx, TypeInformation<RowData> rowDataTypeInfo, LogicalType[] fieldTypes) {
    checkArgument(opt.getKeyFields().isPresent());
    JdbcDialect dialect = opt.getDialect();
    String tableName = opt.getTableName();
    String[] pkNames = opt.getKeyFields().get();
    int[] pkFields = Arrays.stream(pkNames).mapToInt(Arrays.asList(opt.getFieldNames())::indexOf).toArray();
    LogicalType[] pkTypes = Arrays.stream(pkFields).mapToObj(f -> fieldTypes[f]).toArray(LogicalType[]::new);
    final TypeSerializer<RowData> typeSerializer = rowDataTypeInfo.createSerializer(ctx.getExecutionConfig());
    final Function<RowData, RowData> valueTransform = ctx.getExecutionConfig().isObjectReuseEnabled() ? typeSerializer::copy : Function.identity();
    return new TableBufferReducedStatementExecutor(createUpsertRowExecutor(dialect, tableName, opt.getFieldNames(), fieldTypes, pkFields, pkNames, pkTypes), createDeleteExecutor(dialect, tableName, pkNames, pkTypes), createRowKeyExtractor(fieldTypes, pkFields), valueTransform);
}
Also used : DataType(org.apache.flink.table.types.DataType) Arrays(java.util.Arrays) RuntimeContext(org.apache.flink.api.common.functions.RuntimeContext) JdbcExecutionOptions(org.apache.flink.connector.jdbc.JdbcExecutionOptions) JdbcDmlOptions(org.apache.flink.connector.jdbc.internal.options.JdbcDmlOptions) JdbcRowConverter(org.apache.flink.connector.jdbc.converter.JdbcRowConverter) RowType(org.apache.flink.table.types.logical.RowType) Function(java.util.function.Function) FieldNamedPreparedStatement(org.apache.flink.connector.jdbc.statement.FieldNamedPreparedStatement) RowData.createFieldGetter(org.apache.flink.table.data.RowData.createFieldGetter) TableSimpleStatementExecutor(org.apache.flink.connector.jdbc.internal.executor.TableSimpleStatementExecutor) GenericRowData(org.apache.flink.table.data.GenericRowData) JdbcBatchStatementExecutor(org.apache.flink.connector.jdbc.internal.executor.JdbcBatchStatementExecutor) TableBufferReducedStatementExecutor(org.apache.flink.connector.jdbc.internal.executor.TableBufferReducedStatementExecutor) TableBufferedStatementExecutor(org.apache.flink.connector.jdbc.internal.executor.TableBufferedStatementExecutor) SimpleJdbcConnectionProvider(org.apache.flink.connector.jdbc.internal.connection.SimpleJdbcConnectionProvider) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) TypeInformation(org.apache.flink.api.common.typeinfo.TypeInformation) TypeSerializer(org.apache.flink.api.common.typeutils.TypeSerializer) RowData(org.apache.flink.table.data.RowData) JdbcOutputFormat(org.apache.flink.connector.jdbc.internal.JdbcOutputFormat) JdbcConnectorOptions(org.apache.flink.connector.jdbc.internal.options.JdbcConnectorOptions) Serializable(java.io.Serializable) LogicalType(org.apache.flink.table.types.logical.LogicalType) Preconditions.checkArgument(org.apache.flink.util.Preconditions.checkArgument) TableInsertOrUpdateStatementExecutor(org.apache.flink.connector.jdbc.internal.executor.TableInsertOrUpdateStatementExecutor) JdbcDialect(org.apache.flink.connector.jdbc.dialect.JdbcDialect) GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) LogicalType(org.apache.flink.table.types.logical.LogicalType) JdbcDialect(org.apache.flink.connector.jdbc.dialect.JdbcDialect) TableBufferReducedStatementExecutor(org.apache.flink.connector.jdbc.internal.executor.TableBufferReducedStatementExecutor)

Aggregations

Serializable (java.io.Serializable)1 Arrays (java.util.Arrays)1 Function (java.util.function.Function)1 RuntimeContext (org.apache.flink.api.common.functions.RuntimeContext)1 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)1 TypeSerializer (org.apache.flink.api.common.typeutils.TypeSerializer)1 JdbcExecutionOptions (org.apache.flink.connector.jdbc.JdbcExecutionOptions)1 JdbcRowConverter (org.apache.flink.connector.jdbc.converter.JdbcRowConverter)1 JdbcDialect (org.apache.flink.connector.jdbc.dialect.JdbcDialect)1 JdbcOutputFormat (org.apache.flink.connector.jdbc.internal.JdbcOutputFormat)1 SimpleJdbcConnectionProvider (org.apache.flink.connector.jdbc.internal.connection.SimpleJdbcConnectionProvider)1 JdbcBatchStatementExecutor (org.apache.flink.connector.jdbc.internal.executor.JdbcBatchStatementExecutor)1 TableBufferReducedStatementExecutor (org.apache.flink.connector.jdbc.internal.executor.TableBufferReducedStatementExecutor)1 TableBufferedStatementExecutor (org.apache.flink.connector.jdbc.internal.executor.TableBufferedStatementExecutor)1 TableInsertOrUpdateStatementExecutor (org.apache.flink.connector.jdbc.internal.executor.TableInsertOrUpdateStatementExecutor)1 TableSimpleStatementExecutor (org.apache.flink.connector.jdbc.internal.executor.TableSimpleStatementExecutor)1 JdbcConnectorOptions (org.apache.flink.connector.jdbc.internal.options.JdbcConnectorOptions)1 JdbcDmlOptions (org.apache.flink.connector.jdbc.internal.options.JdbcDmlOptions)1 FieldNamedPreparedStatement (org.apache.flink.connector.jdbc.statement.FieldNamedPreparedStatement)1 GenericRowData (org.apache.flink.table.data.GenericRowData)1