繁体   English   中英

我们可以在具有Apache Beam管道的单个C​​loudSQL连接中的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。 根据我的要求,我必须在两个不同的表中写入相同的数据。
实际上,我正在创建两个不同的JDBCIO连接以将数据写入cloudSQL表中。
有没有办法在单个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连接中编写两个不同的插入查询来执行上述代码,但是数据仅插入一个表(即Table2)中。

那么,我们可以在单个连接中执行多个查询吗? 如果是,还有其他方法吗?

提前致谢。

不,您不能一次连接。 您能做的最好的事情是:

JdbcIO<String> configuredWrite = JdbcIO.<String>.withDataSourceConfiguration(...);

outputStringPcollection.apply(configuredWrite.withStatement(s1)...);

outputStringPcollection.apply(configuredWrite.withStatement(s2)...);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM