我们可以在带有 apache beam 管道的单个 CloudSQL 连接中的 JDBCIO.write 函数中执行多个插入查询吗?
Can we execute multiple insert queries in JDBCIO.write function in single CloudSQL connection with an apache beam pipeline?
我正在使用 apache beam 的 JDBCIO.write()
功能将流数据写入 cloudSQL。根据我的要求,我必须在两个不同的 tables.
中写入相同的数据
实际上我正在创建两个不同的 JDBCIO 连接以在 cloudSQL tables.
中写入数据
有没有办法在单个 JDBCIO.write()
函数中编写两个插入查询?
outputStringPcollection
.apply("Write to CloudSQL table",
JdbcIO.<String> write()
.withDataSourceConfiguration(JdbcIO.DataSourceConfiguration
.create(DRIVER_CLASS_NAME,
URL)
.withUsername(USERNAME)
.withPassword(PASSWORD)
.withStatement(insertQueryTable1)
.withPreparedStatementSetter(new SetQueryParameter())
.withStatement(insertQueryTable2)
.withPreparedStatementSetter(new SetQueryParameter()));
我试图通过在单个 JDBC 连接中编写两个不同的插入查询来执行上述代码,但数据仅插入一个 table(即 Table2)。
那么,我们可以在单个连接中执行多个查询吗?如果是,还有其他方法吗?
提前致谢。
不,您不能在单个连接中完成。你能做的最好的是:
JdbcIO<String> configuredWrite = JdbcIO.<String>.withDataSourceConfiguration(...);
outputStringPcollection.apply(configuredWrite.withStatement(s1)...);
outputStringPcollection.apply(configuredWrite.withStatement(s2)...);
我正在使用 apache beam 的 JDBCIO.write()
功能将流数据写入 cloudSQL。根据我的要求,我必须在两个不同的 tables.
中写入相同的数据
实际上我正在创建两个不同的 JDBCIO 连接以在 cloudSQL tables.
中写入数据
有没有办法在单个 JDBCIO.write()
函数中编写两个插入查询?
outputStringPcollection
.apply("Write to CloudSQL table",
JdbcIO.<String> write()
.withDataSourceConfiguration(JdbcIO.DataSourceConfiguration
.create(DRIVER_CLASS_NAME,
URL)
.withUsername(USERNAME)
.withPassword(PASSWORD)
.withStatement(insertQueryTable1)
.withPreparedStatementSetter(new SetQueryParameter())
.withStatement(insertQueryTable2)
.withPreparedStatementSetter(new SetQueryParameter()));
我试图通过在单个 JDBC 连接中编写两个不同的插入查询来执行上述代码,但数据仅插入一个 table(即 Table2)。
那么,我们可以在单个连接中执行多个查询吗?如果是,还有其他方法吗?
提前致谢。
不,您不能在单个连接中完成。你能做的最好的是:
JdbcIO<String> configuredWrite = JdbcIO.<String>.withDataSourceConfiguration(...);
outputStringPcollection.apply(configuredWrite.withStatement(s1)...);
outputStringPcollection.apply(configuredWrite.withStatement(s2)...);