簡體   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