【问题标题】:Google Cloud Data flow : CloudBigtableScanConfiguration.withScan(), how to pass dynamic filter values?谷歌云数据流:CloudBigtableScanConfiguration.withScan(),如何传递动态过滤值?
【发布时间】:2019-12-16 21:53:27
【问题描述】:

SourceLocation 是我的 Bigtable 的前缀,它是从 application.properties 中获取的。有没有办法在运行数据流模板时动态获取它?

我的管道:

pipeline.apply("ReadTable", Read.from(CloudBigtableIO.read(configSetUp(options))))

CloudBigtableScanConfiguration

private static CloudBigtableScanConfiguration configSetUp(LocationSetupOptions options) {
    ValueProvider<Integer>  pageFilter = options.getPageFilter();
    Scan scan = new Scan(Bytes.toBytes(options.getSourceLocation().get()));

    FilterList filterList = new FilterList();
    PrefixFilter prefixFilter = new PrefixFilter(Bytes.toBytes(options.getSourceLocation().get()));
    filterList.addFilter(new PageFilter(Long.valueOf(pageFilter.get())));
    filterList.addFilter(prefixFilter);
    scan.setFilter(filterList);

    return new CloudBigtableScanConfiguration.Builder()
        .withProjectId(options.getProjectId())
        .withInstanceId(options.getInstanceId())
        .withTableId(options.getTableId())
        .withScan(scan)
        .build();}

【问题讨论】:

    标签: google-cloud-platform google-cloud-dataflow


    【解决方案1】:

    Bigtable CloudBigtableIOBigtableIO 有两个客户端。 CloudBigtableIO 参数不会更新为通过 ValueProvider 由模板修改,但 BigtableIO 与 ValueProviders 兼容。

    在您的特定情况下,如果您正在寻找与模板一起使用的ValueProvider,那么我建议您转而使用BigtableIO。可以在此处找到示例AvroToBigtable

    更新

    @Default.InstanceFactory 可用于指定用户提供的工厂方法以生成参数的默认值。这样,您可以从 DefaultValueFactory 实现中的资源文件中读取默认值。

    例如,您可以查看WindowedWordCount 如何定义 DefaultToCurrentSystemTime 来注释 minTimestampMillis 参数:

    【讨论】:

    • 感谢您的回复。我可以将 ValueProvider 与 CloudBigtableIO 一起使用。在构建模板时,从应用程序属性中获取 BigTable 前缀。有没有办法在执行模板时传递运行时前缀?感谢您的回复
    • 我已经更新了答案。如果这有帮助,请接受答案。
    • 我有一个类似的实现来从应用程序属性中获取默认值。我们的管道使用特定输入查询 Bigtable,处理结果并插入到另一个表。在执行管道模板时,我在为大表查询传递动态输入时遇到问题。感谢您的回复
    猜你喜欢
    • 1970-01-01
    • 2015-05-24
    • 1970-01-01
    • 1970-01-01
    • 2021-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-31
    相关资源
    最近更新 更多