Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ApacheBeam中将动态SQL语句传递给JDBCIO连接器?_Jdbc_Google Cloud Platform_Google Cloud Sql_Apache Beam - Fatal编程技术网

如何在ApacheBeam中将动态SQL语句传递给JDBCIO连接器?

如何在ApacheBeam中将动态SQL语句传递给JDBCIO连接器?,jdbc,google-cloud-platform,google-cloud-sql,apache-beam,Jdbc,Google Cloud Platform,Google Cloud Sql,Apache Beam,ApacheBeam提供JDBCIO连接器以连接到CloudSql postgreSQL。我的作业从发布/订阅中读取事件。事件正文如下所示: tableName, list<value> 不能基于输入元素对JdbcIO进行动态查询。 ParDo必须根据需要重置,您可以重写ParDo,在其中手动调用JDBC驱动程序 如果找到其他解决方法,可以将输入PCollection拆分为多个输出。如果您的用例仅限于一些预定义的查询集,您可以根据输入从中进行选择,那么这将起作用。通过这种方式,您可

ApacheBeam提供JDBCIO连接器以连接到CloudSql postgreSQL。我的作业从发布/订阅中读取事件。事件正文如下所示:

tableName,
list<value>

不能基于输入元素对JdbcIO进行动态查询。 ParDo必须根据需要重置,您可以重写ParDo,在其中手动调用JDBC驱动程序

如果找到其他解决方法,可以将输入PCollection拆分为多个输出。如果您的用例仅限于一些预定义的查询集,您可以根据输入从中进行选择,那么这将起作用。通过这种方式,您可以将输入拆分为多个PCollection,然后将不同配置的IO连接到每个PCollection


您可以尝试读取带有属性的pubsub消息,在属性中,您可以以键值对的形式传递表名和值

PCollection<PubsubMessage> pubsubMessage = pipeline
      .apply(PubsubIO.readMessagesWithAttributes().fromSubscription("")
PCollection pubsubMessage=管道
.apply(publisubio.readMessagesWithAttributes().fromSubscription(“”)

您的意思是,我应该在setup函数中启动jdbc连接,在process元素函数中构造并执行语句吗?
@Setup
public void doAnyRequiredSetup() throws SQLException
{
    LoggingContextUtil.installContext(loggingContext);


    connection=DriverManager.getConnection(JdbcUrl,user,password);
    statement=connection.createStatement();

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("In doAnyRequiredSetup logging Context is now set and JDBC connection is .");
    }



}

@SuppressWarnings("unchecked")
@ProcessElement
public void processElement(ProcessContext context)
{
    JsonNode element=context.element();

    try {
        String query=formatQuery(baseQuery);

        boolean result=statement.execute(query);

        if(LOGGER.isDebugEnabled()) {
            LOGGER.debug("Executed query : "+query+" and the result is "+ result);
        }

    } catch (IllegalArgumentException | SQLException e) {

        ErrorMessage em = new ErrorMessage(element.toString(), "Insert Query Failed", e.getMessage());

        context.output(ValidateTagHelper.FAILURE_TAG,em);
    }



}
PCollection<PubsubMessage> pubsubMessage = pipeline
      .apply(PubsubIO.readMessagesWithAttributes().fromSubscription("")