Search in sources :

Example 1 with JdbcOutputFormat

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

the class JdbcOutputFormatBuilder method build.

public JdbcOutputFormat<RowData, ?, ?> build() {
    checkNotNull(jdbcOptions, "jdbc options can not be null");
    checkNotNull(dmlOptions, "jdbc dml options can not be null");
    checkNotNull(executionOptions, "jdbc execution options can not be null");
    final LogicalType[] logicalTypes = Arrays.stream(fieldDataTypes).map(DataType::getLogicalType).toArray(LogicalType[]::new);
    if (dmlOptions.getKeyFields().isPresent() && dmlOptions.getKeyFields().get().length > 0) {
        // upsert query
        return new JdbcOutputFormat<>(new SimpleJdbcConnectionProvider(jdbcOptions), executionOptions, ctx -> createBufferReduceExecutor(dmlOptions, ctx, rowDataTypeInformation, logicalTypes), JdbcOutputFormat.RecordExtractor.identity());
    } else {
        // append only query
        final String sql = dmlOptions.getDialect().getInsertIntoStatement(dmlOptions.getTableName(), dmlOptions.getFieldNames());
        return new JdbcOutputFormat<>(new SimpleJdbcConnectionProvider(jdbcOptions), executionOptions, ctx -> createSimpleBufferedExecutor(ctx, dmlOptions.getDialect(), dmlOptions.getFieldNames(), logicalTypes, sql, rowDataTypeInformation), JdbcOutputFormat.RecordExtractor.identity());
    }
}
Also used : JdbcOutputFormat(org.apache.flink.connector.jdbc.internal.JdbcOutputFormat) SimpleJdbcConnectionProvider(org.apache.flink.connector.jdbc.internal.connection.SimpleJdbcConnectionProvider) LogicalType(org.apache.flink.table.types.logical.LogicalType)

Aggregations

JdbcOutputFormat (org.apache.flink.connector.jdbc.internal.JdbcOutputFormat)1 SimpleJdbcConnectionProvider (org.apache.flink.connector.jdbc.internal.connection.SimpleJdbcConnectionProvider)1 LogicalType (org.apache.flink.table.types.logical.LogicalType)1