You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/03/19 00:30:26 UTC

[GitHub] [beam] lostluck commented on a change in pull request #17088: [BEAM-14098] wrapper for postgres on JDBC IO GO SDK

lostluck commented on a change in pull request #17088:
URL: https://github.com/apache/beam/pull/17088#discussion_r830414462



##########
File path: sdks/go/pkg/beam/io/xlang/jdbcio/jdbc.go
##########
@@ -279,3 +299,29 @@ func ExpansionAddrRead(expansionAddr string) readOption {
 		jc.expansionAddr = expansionAddr
 	}
 }
+
+// ReadFromPostgres is a cross-language PTransform which read Rows from the postgres via JDBC.
+// tableName is a required paramater, and by default, the readQuery is generated from it.
+// The generated readQuery can be overridden by passing in a readQuery.If an expansion service
+// address is not provided, an appropriate expansion service will be automatically started;
+// however this is slower than having a persistent expansion service running.
+//
+// The default read query is "SELECT * FROM tableName;"
+//
+// Read also accepts optional parameters as readOptions. All optional parameters
+// are predefined in this package as functions that return readOption. To set
+// an optional parameter, call the function within Read's function signature.
+// NOTE: This transform uses "org.postgresql.Driver" as the default driver. If you want to use read transform
+// with custom postgres driver then use the conventional jdbcio.Read() transform.
+//
+// Example:
+//   tableName := "roles"
+//   username := "root"
+//   password := "root123"
+//   jdbcUrl := "jdbc:postgresql://localhost:5432/dbname"
+//   outT := reflect.TypeOf((*JdbcTestRow)(nil)).Elem()
+//   jdbcio.Read(s, tableName, jdbcurl, username, password, outT, jdbcio.ExpansionAddrRead("localhost:9000"))

Review comment:
       ```suggestion
   // ReadFromPostgres is a cross-language PTransform which read Rows from the postgres via JDBC.
   // tableName is a required parameter, and by default, a read query is generated from it.
   // The generated read query can be overridden by passing in a ReadQuery. If an expansion service
   // address is not provided, an appropriate expansion service will be automatically started;
   // however this is slower than having a persistent expansion service running.
   //
   // The default read query is "SELECT * FROM tableName;"
   //
   // Read also accepts optional parameters as readOptions. All optional parameters
   // are predefined in this package as functions that return readOption. To set
   // an optional parameter, call the function within Read's function signature.
   // NOTE: This transform uses "org.postgresql.Driver" as the default driver. If you want to use read transform
   // with custom postgres driver then use the conventional jdbcio.Read() transform.
   //
   // Example:
   //   tableName := "roles"
   //   username := "root"
   //   password := "root123"
   //   jdbcUrl := "jdbc:postgresql://localhost:5432/dbname"
   //   outT := reflect.TypeOf((*JdbcTestRow)(nil)).Elem()
   //   jdbcio.Read(s, tableName, jdbcurl, username, password, outT, jdbcio.ExpansionAddrRead("localhost:9000"))
   ```

##########
File path: sdks/go/pkg/beam/io/xlang/jdbcio/jdbc.go
##########
@@ -184,8 +184,28 @@ func ExpansionAddrWrite(expansionAddr string) writeOption {
 	}
 }
 
+// WriteToPostgres is a cross-language PTransform which writes Rows to the postgres database via JDBC.
+// tableName is a required paramater, and by default, the writeStatement is generated from it.
+// The generated write_statement can be overridden by passing in a write_statment.
+// If an expansion service address is not provided,
+// an appropriate expansion service will be automatically started; however
+// this is slower than having a persistent expansion service running.
+// NOTE: This transform uses "org.postgresql.Driver" as the default driver. If you want to use write transform
+// with custom postgres driver then use the conventional jdbcio.Write() transform.
+//
+// The default write statement is: "INSERT INTO tableName(column1, ...) INTO VALUES(value1, ...)"
+// Example:
+//   tableName := "roles"
+// 	 username := "root"
+// 	 password := "root123"
+// 	 jdbcUrl := "jdbc:postgresql://localhost:5432/dbname"
+//	 jdbcio.WriteToPostgres(s, tableName, jdbcurl, username, password, jdbcio.ExpansionAddrWrite("localhost:9000"))

Review comment:
       ```suggestion
   // WriteToPostgres is a cross-language PTransform which writes Rows to the postgres database via JDBC.
   // tableName is a required parameter, and by default, a write statement is generated from it.
   // The generated write statement can be overridden by passing in a WriteStatement option.
   // If an expansion service address is not provided,
   // an appropriate expansion service will be automatically started; however
   // this is slower than having a persistent expansion service running.
   // NOTE: This transform uses "org.postgresql.Driver" as the default driver. If you want to use write transform
   // with custom postgres driver then use the conventional jdbcio.Write() transform.
   //
   // The default write statement is: "INSERT INTO tableName(column1, ...) INTO VALUES(value1, ...)"
   // Example:
   //   tableName := "roles"
   // 	 username := "root"
   // 	 password := "root123"
   // 	 jdbcUrl := "jdbc:postgresql://localhost:5432/dbname"
   //	 jdbcio.WriteToPostgres(s, tableName, jdbcurl, username, password, jdbcio.ExpansionAddrWrite("localhost:9000"))
   ```

##########
File path: sdks/go/pkg/beam/io/xlang/jdbcio/jdbc.go
##########
@@ -111,10 +111,10 @@ func toRow(pl interface{}) []byte {
 }
 
 // Write is a cross-language PTransform which writes Rows to the specified database via JDBC.
-// Write requires the address for an expansion service. tableName is a required paramater,
-// and by default, the writeStatement is generated from it. The generated write_statement
-// can be overridden by passing in a write_statment. If an expansion service address is not
-// provided, an appropriate expansion service will be automatically started; however
+// tableName is a required paramater, and by default, the writeStatement is generated from it.
+// The generated write_statement can be overridden by passing in a write_statment.

Review comment:
       ```suggestion
   // tableName is a required parameter, and by default, the write statement is generated from it.
   // The generated write statement can be overridden by passing in a WriteStatement option.
   ```




-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org