是否可以使用 Apache Beam JdbcIO.Write 获取生成的密钥?

Is it possible to get the generated key using Apache Beam JdbcIO.Write?

如果我使用 JdbcIO.Write 调用存储过程 如果存储过程 returns 此数据是否可以捕获 ID(主键)?

public JdbcIO.Write<MyObject> writeMyObject() {
      final String UPSERT_MY_OBJECT = "EXEC [MySchema].[UspertMyObject] ?,?,?";
        
      // If my stored procedure returns the generated or existing ID
      // is it possible to update the object I'm writing with the ID?
      return JdbcIO.<MyObject>write()
            .withDataSourceConfiguration(myDataSourceConfig)
            .withStatement(UPSERT_MY_OBJECT)
            .withPreparedStatementSetter((JdbcIO.PreparedStatementSetter<MyObject>) (myObject, ps) -> {
                  ps.setInt(1, myObject.getFieldOne());
                  ps.setString(2, myObject.getFieldTwo());
                  ps.setString(3, myObject.getFieldThree());
      });
}

我不认为这是可能的,但作为一种解决方法,您可以等待写入完成(使用 Wait 转换,参见 an example there),然后从数据库中读取它们。