从Google Cloud SQL读取数据,使用Cloud Dataflow 将数据传输至BigQuery。

huangapple go评论64阅读模式
英文:

Read the data from Google Cloud Sql to BigQuery using Clud Dataflow

问题

我们实际上计划使用CloudDataflow从CloudSql读取数据并导入BigQuery。当我尝试运行下面提到的代码时,出现了错误,提示"未提供驱动程序类名"。

链接:https://github.com/GoogleCloudPlatform/DataflowTemplates/blob/master/src/main/java/com/google/cloud/teleport/templates/JdbcToBigQuery.java

有人知道如何为这行代码"options.getDriverClassName()"传递值吗?

英文:

We are actually planning to read the data from CloudSql into BigQuery using CloudDataflow. When i tried to run the below mentioned code, i got the error saying "Driver class name is not provided".

https://github.com/GoogleCloudPlatform/DataflowTemplates/blob/master/src/main/java/com/google/cloud/teleport/templates/JdbcToBigQuery.java

Does anybody know on how to pass the value for this line of code "options.getDriverClassName()"?

答案1

得分: 1

@Panciz, @guillaume blaquiere

我自己找到了解决方案。如果您查看下面的谷歌链接

https://cloud.google.com/dataflow/docs/guides/templates/provided-batch#java-database-connectivity-jdbc-to-bigquery

我们需要传递上述链接中提到的参数。由于我是从IntelliJ运行“JdbcToBigQuery” Dataflow模板的,我将这些参数作为程序参数传递,如下所示,并且它起作用了。

--project=<谷歌云项目名称>
--stagingLocation=gs://<位置>
--gcpTempLocation=gs://<位置>
--serviceAccount=<用于dataflow的服务账号>
--runner=DirectRunner
--driverJars=gs://<位置>/postgres-socket-factory-1.0.15-jar-with-dependencies.jar
--bigQueryLoadingTemporaryDirectory=gs://<位置>
--driverClassName=org.postgresql.Driver
--connectionURL=jdbc:postgresql://google/<您的谷歌云Postgres数据库名称>?cloudSqlInstance=<您的谷歌云项目名称>:europe-west1:<您的谷歌云Postgres实例名称>&socketFactory=com.google.cloud.sql.postgres.SocketFactory&useSSL=false
--username=<您的用户名>
--password=<您的密码>
--query="<您的SQL查询>"
--outputTable=<您的谷歌云项目名称>:<您的谷歌云数据集名称>.<您的谷歌云表名称>
--connectionProperties=unicode=true&characterEncoding=UTF-8
英文:

@Panciz, @guillaume blaquiere

I myself found out the solution for this. if you check the below link from Google

https://cloud.google.com/dataflow/docs/guides/templates/provided-batch#java-database-connectivity-jdbc-to-bigquery

We need to pass the parameters that are mentioned in the above link. Since, i was running the "JdbcToBigQuery" Dataflow template from IntelliJ, I passed these parameters as Program Arguments as mentioned below, and it worked.

--project=&lt;google cloud project name&gt;
--stagingLocation=gs://&lt;location&gt;
--gcpTempLocation=gs://&lt;location&gt;
--serviceAccount=&lt;service account for dataflow&gt;
--runner=DirectRunner
--driverJars=gs://&lt;location&gt;/postgres-socket-factory-1.0.15-jar-with-dependencies.jar
--bigQueryLoadingTemporaryDirectory=gs://&lt;location&gt;
--driverClassName=org.postgresql.Driver
--connectionURL=jdbc:postgresql://google/&lt;your google cloud  postgres db name&gt;?cloudSqlInstance=&lt;your google cloud project name&gt;:europe-west1:&lt;your google cloud  postgres instance name&gt;&amp;socketFactory=com.google.cloud.sql.postgres.SocketFactory&amp;useSSL=false
--username=&lt;your username&gt;
--password=&lt;your passsowrd&gt;
--query=&quot;&lt;your sql query&gt;&quot;
--outputTable=&lt;your google cloud  project name&gt;:&lt;your google cloud dataset name&gt;.&lt;your google cloud table name&gt;
--connectionProperties=unicode=true&amp;characterEncoding=UTF-8

huangapple
  • 本文由 发表于 2020年9月17日 18:21:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/63936004.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定