Polber commented on code in PR #33124:
URL: https://github.com/apache/beam/pull/33124#discussion_r1851021375
##########
sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcWriteSchemaTransformProvider.java:
##########
@@ -54,33 +55,177 @@ public class JdbcWriteSchemaTransformProvider
extends TypedSchemaTransformProvider<
JdbcWriteSchemaTransformProvider.JdbcWriteSchemaTransformConfiguration> {
+ @Override
+ public @UnknownKeyFor @NonNull @Initialized String identifier() {
+ return "beam:schematransform:org.apache.beam:jdbc_write:v1";
+ }
+
+ @Override
+ public String description() {
+ return baseDescription("JDBC")
+ + "\n"
+ + "This transform can be used to write to a JDBC sink using either a
given JDBC driver jar "
+ + "and class name, or by using one of the default packaged drivers
given a `jdbc_type`.\n"
+ + "\n"
+ + "#### Using a default driver\n"
+ + "\n"
+ + "This transform comes packaged with drivers for several popular JDBC
distributions. The following "
+ + "distributions can be declared as the `jdbc_type`: "
+ + JDBC_DRIVER_MAP.keySet().toString().replaceAll("[\\[\\]]", "")
+ + ".\n"
+ + "\n"
+ + "For example, writing to a MySQL sink using a SQL query: ::"
+ + "\n"
+ + " - type: WriteToJdbc\n"
+ + " config:\n"
+ + " jdbc_type: mysql\n"
+ + " url: \"jdbc:mysql://my-host:3306/database\"\n"
+ + " query: \"INSERT INTO table VALUES(?, ?)\"\n"
+ + "\n"
+ + "\n"
+ + "**Note**: See the following transforms which are built on top of
this transform and simplify "
+ + "this logic for several popular JDBC distributions:\n\n"
+ + " - WriteToMySql\n"
+ + " - WriteToPostgres\n"
+ + " - WriteToOracle\n"
+ + " - WriteToSqlServer\n"
+ + "\n"
+ + "#### Declaring custom JDBC drivers\n"
+ + "\n"
+ + "If writing to a JDBC sink not listed above, or if it is necessary
to use a custom driver not "
+ + "packaged with Beam, one must define a JDBC driver and class name.\n"
+ + "\n"
+ + "For example, writing to a MySQL table: ::"
+ + "\n"
+ + " - type: WriteToJdbc\n"
+ + " config:\n"
+ + " driver_jars: \"path/to/some/jdbc.jar\"\n"
+ + " driver_class_name: \"com.mysql.jdbc.Driver\"\n"
+ + " url: \"jdbc:mysql://my-host:3306/database\"\n"
+ + " table: \"my-table\"\n"
+ + "\n"
+ + "#### Connection Properties\n"
+ + "\n"
+ + "Connection properties are properties sent to the Driver used to
connect to the JDBC source. For example, "
+ + "to set the character encoding to UTF-8, one could write: ::\n"
+ + "\n"
+ + " - type: WriteToJdbc\n"
+ + " config:\n"
+ + " connectionProperties: \"characterEncoding=UTF-8;\"\n"
+ + " ...\n"
+ + "All properties should be semi-colon-delimited (e.g.
\"key1=value1;key2=value2;\")\n";
+ }
+
+ protected String baseDescription(String jdbcType) {
+ return String.format(
+ "Write to a %s sink using a SQL query or by directly accessing " + "a
single table.\n",
+ jdbcType);
+ }
+
+ protected String inheritedDescription(
+ String prettyName, String transformName, String prefix, int port) {
+ return String.format(
+ "\n"
+ + "This is a special case of WriteToJdbc that includes the "
+ + "necessary %s Driver and classes.\n"
+ + "\n"
+ + "An example of using %s with SQL query: ::\n"
+ + "\n"
+ + " - type: %s\n"
+ + " config:\n"
+ + " url: \"jdbc:%s://my-host:%d/database\"\n"
+ + " query: \"INSERT INTO table VALUES(?, ?)\"\n"
+ + "\n"
+ + "It is also possible to read a table by specifying a table name.
For example, the "
+ + "following configuration will perform a read on an entire table:
::\n"
+ + "\n"
+ + " - type: %s\n"
+ + " config:\n"
+ + " url: \"jdbc:%s://my-host:%d/database\"\n"
+ + " table: \"my-table\"\n"
+ + "\n"
+ + "#### Advanced Usage\n"
+ + "\n"
+ + "It might be necessary to use a custom JDBC driver that is not
packaged with this "
+ + "transform. If that is the case, see WriteToJdbc which "
+ + "allows for more custom configuration.",
+ prettyName, transformName, transformName, prefix, port, transformName,
prefix, port);
+ }
+
@Override
protected @UnknownKeyFor @NonNull @Initialized
Class<JdbcWriteSchemaTransformConfiguration>
configurationClass() {
return JdbcWriteSchemaTransformConfiguration.class;
}
+ protected static void validateConfig(
Review Comment:
I reorganized the code to avoid needing a static method, as well as remove
need to override the `from()` method entirely in case there are changes to the
parent method. I think it should overall be more organized now
--
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]