shunping commented on code in PR #36034:
URL: https://github.com/apache/beam/pull/36034#discussion_r2323807534
##########
sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/providers/ReadFromPostgresSchemaTransformProvider.java:
##########
@@ -43,4 +53,41 @@ public String description() {
protected String jdbcType() {
return POSTGRES;
}
+
+ @Override
+ public @UnknownKeyFor @NonNull @Initialized SchemaTransform from(
+ JdbcReadSchemaTransformConfiguration configuration) {
+ String jdbcType = configuration.getJdbcType();
+ if (jdbcType != null && !jdbcType.equals(jdbcType())) {
+ throw new IllegalArgumentException(
+ String.format("Wrong JDBC type. Expected '%s' but got '%s'",
jdbcType(), jdbcType));
+ }
+
+ List<@org.checkerframework.checker.nullness.qual.Nullable String>
connectionInitSql =
+ configuration.getConnectionInitSql();
+ if (connectionInitSql != null && !connectionInitSql.isEmpty()) {
+ LOG.warn("Postgres does not support connectionInitSql, ignoring.");
+ }
+
+ Boolean disableAutoCommit = configuration.getDisableAutoCommit();
+ if (disableAutoCommit != null && !disableAutoCommit) {
+ LOG.warn("Postgres reads require disableAutoCommit to be true,
overriding to true.");
+ }
+
+ // Override "connectionInitSql" and "disableAutoCommit" for postgres
+ configuration =
+ configuration
+ .toBuilder()
+ .setConnectionInitSql(Collections.emptyList())
+ .setDisableAutoCommit(true)
+ .build();
+ return new PostgresReadSchemaTransform(configuration);
+ }
+
+ public static class PostgresReadSchemaTransform extends
JdbcReadSchemaTransform {
+ public PostgresReadSchemaTransform(JdbcReadSchemaTransformConfiguration
config) {
+ super(config, POSTGRES);
+ config.validate(POSTGRES);
Review Comment:
Nice catch. I verified that `config.validate(str)` will be called during the
expand() function of the schema transform, so we can simply remove it here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]