标签: google-cloud-dataflow

从Dataflow中的压缩文件中读取

有没有办法(或任何类型的黑客)从压缩文件中读取输入数据?我的输入包含几百个文件,这些文件是用gzip压缩生成的,解压缩它们有点单调乏味.

谢谢,Genady

google-cloud-dataflow

2
推荐指数
1
解决办法
1678
查看次数

使用前缀键删除行范围

我正在使用数据包“ org.apache.hadoop.hbase.client”来管理Google的BigTable数据。

删除行的示例:

key = "PROV|CLI|800|20160714|8|30302.30301|ES";
byte[] byteKey = Bytes.toBytes(key);
Delete delete = new Delete(byteKey);
Run Code Online (Sandbox Code Playgroud)

这可以正常工作,但是我需要一种删除以键“ PROV | CLI | 800 |”开头的所有行的方法

反正有这样做吗?

java google-cloud-dataflow google-cloud-bigtable

2
推荐指数
1
解决办法
793
查看次数

数据流DoFn中的数据存储区查询在云中运行时会减慢管道

我试图通过在DoFn步骤中查询数据存储来增强管道中的数据.来自Class CustomClass的对象中的字段用于对数据存储表执行查询,返回的值用于增强对象.

代码如下所示:

public class EnhanceWithDataStore extends DoFn<CustomClass, CustomClass> {

private static Datastore datastore = DatastoreOptions.defaultInstance().service();
private static KeyFactory articleKeyFactory = datastore.newKeyFactory().kind("article");

@Override
public void processElement(ProcessContext c) throws Exception {

    CustomClass event = c.element();

    Entity article = datastore.get(articleKeyFactory.newKey(event.getArticleId()));

    String articleName = "";
    try{
        articleName = article.getString("articleName");         
    } catch(Exception e) {}

    CustomClass enhanced = new CustomClass(event);
    enhanced.setArticleName(articleName);

    c.output(enhanced);
}
Run Code Online (Sandbox Code Playgroud)

当它在本地运行时,这很快,但是当它在云中运行时,此步骤会显着减慢管道的速度.是什么导致了这个?有没有解决方法或更好的方法来做到这一点?

可以在此处找到管道的图片(​​最后一步是增强步骤): 管道架构

java google-cloud-datastore google-cloud-dataflow

2
推荐指数
1
解决办法
660
查看次数

如何从Google Dataflow中的PCollection中获取元素列表并在管道中使用它来循环写入转换?

我正在使用带有Python SDK的Google Cloud Dataflow.

我想要 :

  • 从主PCollection中获取唯一日期列表
  • 循环遍历该列表中的日期以创建过滤的PCollections(每个都具有唯一的日期),并将每个过滤的PCollection写入BigQuery中时间分区表中的分区.

我怎样才能获得该列表?在下面的combine变换之后,我创建了一个ListPCollectionView对象但是我无法迭代该对象:

class ToUniqueList(beam.CombineFn):

    def create_accumulator(self):
        return []

    def add_input(self, accumulator, element):
        if element not in accumulator:
            accumulator.append(element)
        return accumulator

    def merge_accumulators(self, accumulators):
        return list(set(accumulators))

    def extract_output(self, accumulator):
        return accumulator


def get_list_of_dates(pcoll):

    return (pcoll
            | 'get the list of dates' >> beam.CombineGlobally(ToUniqueList()))
Run Code Online (Sandbox Code Playgroud)

我做错了吗?最好的方法是什么?

谢谢.

python google-bigquery google-cloud-dataflow apache-beam

2
推荐指数
1
解决办法
4427
查看次数

在Google Dataflow/Apache Beam中读取嵌套的JSON

可以通过以下方式在Data Storage上读取未存储的JSON文件:

p.apply("read logfiles", TextIO.Read.from("gs://bucket/*").withCoder(TableRowJsonCoder.of()));
Run Code Online (Sandbox Code Playgroud)

如果我只想用BigQuery编写那些带有最小过滤的日志,我可以通过使用像这样的DoFn来实现:

private static class Formatter extends DoFn<TableRow,TableRow> {

        @Override
        public void processElement(ProcessContext c) throws Exception {

            // .clone() since input is immutable
            TableRow output = c.element().clone();

            // remove misleading timestamp field
            output.remove("@timestamp");

            // set timestamp field by using the element's timestamp
            output.set("timestamp", c.timestamp().toString());

            c.output(output);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,我不知道如何以这种方式访问​​JSON文件中的嵌套字段.

  1. 如果TableRow包含一个RECORDnamed r,是否可以访问其键/值而无需进一步序列化/反序列化?
  2. 如果我需要序列化/反序列化自己与Jackson库,它让使用标准更有意义Coder的TextIO.Read替代TableRowJsonCoder,从而获得一些我失去这样的演出回来的?

编辑

文件是换行符的新行,看起来像这样:

{"@timestamp":"2015-x", "message":"bla", "r":{"analyzed":"blub", "query": {"where":"9999"}}}
{"@timestamp":"2015-x", "message":"blub", "r":{"analyzed":"bla", "query": {"where":"1111"}}}
Run Code Online (Sandbox Code Playgroud)

google-cloud-dataflow apache-beam

2
推荐指数
1
解决办法
3254
查看次数

Apache Beam Google Datastore ReadFromDatastore entity protobuf

I am trying to use apache beam's google datastore api to ReadFromDatastore

p = beam.Pipeline(options=options)
(p
 | 'Read from Datastore' >> ReadFromDatastore(gcloud_options.project, query)
 | 'reformat'            >> beam.Map(reformat)
 | 'Write To Datastore'  >> WriteToDatastore(gcloud_options.project))
Run Code Online (Sandbox Code Playgroud)

The object that gets passed to my reformat function is type

google.cloud.proto.datastore.v1.entity_pb2.Entity

It is in protobuf format which is hard to modify or read.

I think I can convert a entity_pb2.Entity to a dict with

entity= dict(google.cloud.datastore.helpers._property_tuples(entity_pb))
Run Code Online (Sandbox Code Playgroud)

But for some reason trying to import the following two …

python protocol-buffers google-cloud-datastore google-cloud-dataflow apache-beam

2
推荐指数
1
解决办法
1018
查看次数

google-cloud-dataflow vs apache-beam

每个用于数据流的Google文档都说它现在基于Apache Beam,将我定向到Beam网站真是令人困惑。另外,如果我寻找github项目,我会看到google dataflow项目为空,而所有内容都将归入Apache Beam Repo。现在说我需要创建一个管道,根据从Apache Beam读取的内容,我会做的:from apache_beam.options.pipeline_options但是,如果我使用google-cloud-dataflow,则会出现错误:no module named 'options',事实证明我应该使用from apache_beam.utils.pipeline_options。因此,看起来google-cloud-dataflow具有较旧的Beam版本,将被弃用吗?

我应该选择哪一个来开发我的数据流管道?

google-cloud-dataflow apache-beam

2
推荐指数
1
解决办法
2610
查看次数

拒绝拆分GroupedShuffleRangeTracker建议的拆分位置超出范围

我偶尔会收到以下错误:

W拒绝在'\ x00 \ x00 \ x00 \ x15 \ xbc \ x19)b \ x00 \ x01'分割:建议的分割位置超出范围['\ x00 \ x00 \ x00 \ x00 \ x15 \ x00 \ xff \ x00 \ xff \ x00 \ xff \ x00 \ xff \ x00 \ x01','\ x00 \ x00 \ x00 \ x15 \ xbc \ x19)b \ x00 \ x01')。最后处理的组的位置是'\ x00 \ x00 \ x00 \ x15 \ xbc \ x19)a \ x00 \ x01'。

发生这种情况时,错误记录得如此频繁,而且作业似乎永远也不会结束。尽管看起来它确实确实完成了这项工作。

在最后一个实例中,我使用10个工作线程,并且禁用了自动缩放功能。我正在使用Apache Beam的Python实现。

google-cloud-dataflow

2
推荐指数
1
解决办法
400
查看次数

使用Apache Beam以CSV格式将BigQuery结果写入GCS

我是Apache Beam的新手,我在其中尝试编写管道以从Google BigQuery提取数据,然后使用Python将数据以CSV格式写入GCS。

使用,beam.io.read(beam.io.BigQuerySource())我能够从BigQuery读取数据,但不确定如何将其以CSV格式写入GCS。

是否有实现相同功能的自定义功能,能否请您帮我吗?

import logging

import apache_beam as beam


PROJECT='project_id'
BUCKET='project_bucket'


def run():
    argv = [
        '--project={0}'.format(PROJECT),
        '--job_name=readwritebq',
        '--save_main_session',
        '--staging_location=gs://{0}/staging/'.format(BUCKET),
        '--temp_location=gs://{0}/staging/'.format(BUCKET),
        '--runner=DataflowRunner'
]

with beam.Pipeline(argv=argv) as p:

    # Execute the SQL in big query and store the result data set into given Destination big query table.
    BQ_SQL_TO_TABLE = p | 'read_bq_view' >> beam.io.Read(
        beam.io.BigQuerySource(query =  'Select * from `dataset.table`', use_standard_sql=True))
    # Extract data from Bigquery to GCS in CSV format.
    # This is where I need …
Run Code Online (Sandbox Code Playgroud)

python google-bigquery google-cloud-dataflow apache-beam

2
推荐指数
1
解决办法
924
查看次数

如何在Apache Beam中提取Google PubSub发布时间

我的目标是能够访问Google Beam在Apache Beam(数据流)中记录和设置的PubSub消息发布时间。

    PCollection<PubsubMessage> pubsubMsg
            = pipeline.apply("Read Messages From PubSub",
            PubsubIO.readMessagesWithAttributes()
                .fromSubscription(pocOptions.getInputSubscription()));
Run Code Online (Sandbox Code Playgroud)

似乎不包含一个作为属性。我试过了

 .withTimestampAttribute("publish_time")
Run Code Online (Sandbox Code Playgroud)

也没有运气。我想念什么?是否可以在数据流中提取Google PubSub发布时间?

google-cloud-platform google-cloud-dataflow apache-beam

2
推荐指数
1
解决办法
395
查看次数