我想加载流数据,然后添加一个键,然后按键计数。
当我尝试使用流方法(无界数据)加载和按键分组大数据时,Apache Beam Dataflow 管道出现内存错误。因为似乎数据是按分组累积的,并且不会在触发每个窗口时更早地触发数据。
如果我减小元素大小(元素数量不会改变),它会起作用!因为实际上 group-by step 等待所有数据被分组,然后触发所有新的窗口数据。
我对两者进行了测试:
梁版本 2.11.0 和 scio 版本 0.7.4
梁版本 2.6.0 和 scio 版本 0.6.1
如您所见,数据是按组累积的,不会发出。
val windowedData = data.applyKvTransform(
Window.into[myt](
Sessions.withGapDuration(Duration.millis(1)))
.triggering(
Repeatedly.forever(AfterFirst.of(
AfterPane.elementCountAtLeast(10),
AfterProcessingTime.pastFirstElementInPane().plusDelayOf(Duration.millis(1)))
).orFinally(AfterWatermark.pastEndOfWindow())
).withAllowedLateness(Duration.standardSeconds(100))
.discardingFiredPanes()
)
Run Code Online (Sandbox Code Playgroud)
org.apache.beam.runners.dataflow.worker.StreamingDataflowWorker$KeyCommitTooLargeException: Commit request for stage S2 and …Run Code Online (Sandbox Code Playgroud) 我正在接收一个复杂的嵌套 JSON 对象流作为我对管道的输入。
我的目标是创建小批量以供另一个pubsub主题进行下游处理。我正在努力使用该beam.beam.GroupByKey()功能 - 从我读到的内容来看,这是尝试和聚合的正确方法。
一个简化的例子,输入事件:
{ data:['a', 'b', 'c'], url: 'websiteA.com' }
{ data:['a', 'b', 'c'], url: 'websiteA.com' }
{ data:['a'], url: 'websiteB.com' }
Run Code Online (Sandbox Code Playgroud)
我正在尝试创建以下内容:
{
'websiteA.com': {a:2, b:2, c:2},
'websiteB.com': {a:1},
}
Run Code Online (Sandbox Code Playgroud)
我的问题在于尝试对最简单的元组抛出ValueError: too many values to unpack.
我可以分两步运行它,但从我的阅读来看,使用beam.GroupByKey()成本很高,因此应该尽量减少。
根据@Cubez 的回答进行编辑。
这是我的组合功能,它似乎工作了一半:(
{ data:['a', 'b', 'c'], url: 'websiteA.com' }
{ data:['a', 'b', 'c'], url: 'websiteA.com' }
{ data:['a'], url: 'websiteB.com' }
Run Code Online (Sandbox Code Playgroud)
似乎过去add_input什么都没有被调用?
添加管道代码:
{
'websiteA.com': {a:2, b:2, …Run Code Online (Sandbox Code Playgroud) 我是 GCP 数据流的新手。
我尝试从 GCP 云存储中将文本文件(一行 JSON 字符串)读取为 JSON 格式,然后根据特定字段的值将其拆分并输出到 GCP 云存储(作为 JSON 字符串文本文件)。
这是我的代码
但是,我在 GCP 数据流上遇到了一些错误:
Traceback (most recent call last):
File "main.py", line 169, in <module>
run()
File "main.py", line 163, in run
shard_name_template='')
File "C:\ProgramData\Miniconda3\lib\site-packages\apache_beam\pipeline.py", line 426, in __exit__
self.run().wait_until_finish()
File "C:\ProgramData\Miniconda3\lib\site-packages\apache_beam\runners\dataflow\dataflow_runner.py", line 1346, in wait_until_finish
(self.state, getattr(self._runner, 'last_error_msg', None)), self)
apache_beam.runners.dataflow.dataflow_runner.DataflowRuntimeException: Dataflow pipeline failed. State: FAILED, Error:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/dataflow_worker/batchworker.py", line 773, in run
self._load_main_session(self.local_staging_directory)
File "/usr/local/lib/python3.7/site-packages/dataflow_worker/batchworker.py", line 489, in …Run Code Online (Sandbox Code Playgroud) 我有一个现有系统,其中数据发布到 Pub/Sub 主题,由云功能订阅者读取并推送到 Big Query 以存储它(订阅者 CF 中未完成其他转换)。
使用 pub/sub-BQ 模板将我的订阅者 CF 更改为 Dataflow 流作业是个好主意吗?使用它们的优点/缺点是什么?
google-cloud-platform google-cloud-pubsub google-cloud-dataflow google-cloud-functions
我正在尝试使用 Dataflow 创建一个流式管道,该管道从 PubSub 主题读取消息以最终将它们写入 BigQuery 表。我不想使用任何 Dataflow 模板。
目前,我只想在从 Google VM 实例执行的 Python3 脚本中创建一个管道,以对从 Pubsub 到达的每条消息(解析它包含的记录并添加一个新字段)执行加载和转换过程,以结束将结果写入 BigQuery 表。
简化,我的代码是:
#!/usr/bin/env python
from apache_beam.options.pipeline_options import PipelineOptions
from google.cloud import pubsub_v1,
import apache_beam as beam
import apache_beam.io.gcp.bigquery
import logging
import argparse
import sys
import json
from datetime import datetime, timedelta
def load_pubsub(message):
try:
data = json.loads(message)
records = data["messages"]
return records
except:
raise ImportError("Something went wrong reading data from the Pub/Sub topic")
class ParseTransformPubSub(beam.DoFn):
def __init__(self):
self.water_mark = (datetime.now() + timedelta(hours …Run Code Online (Sandbox Code Playgroud) python google-bigquery google-cloud-pubsub google-cloud-dataflow apache-beam
在我的管道中,我使用 WriteToBigQuery 是这样的:
| beam.io.WriteToBigQuery(
'thijs:thijsset.thijstable',
schema=table_schema,
write_disposition=beam.io.BigQueryDisposition.WRITE_APPEND,
create_disposition=beam.io.BigQueryDisposition.CREATE_IF_NEEDED)
Run Code Online (Sandbox Code Playgroud)
这将返回文档中描述的 Dict,如下所示:
beam.io.WriteToBigQuery PTransform 返回一个字典,其 BigQueryWriteFn.FAILED_ROWS 条目包含所有未能写入的行的 PCollection。
如何打印此 dict 并将其转换为 pcollection 或如何仅打印 FAILED_ROWS?
如果我做: | "print" >> beam.Map(print)
然后我得到: AttributeError: 'dict' object has no attribute 'pipeline'
我一定读过一百个管道,但在 WriteToBigQuery 之后我再也没有看到任何东西。
[编辑] 当我完成管道并将结果存储在一个变量中时,我有以下内容:
{'FailedRows': <PCollection[WriteToBigQuery/StreamInsertRows/ParDo(BigQueryWriteFn).FailedRows] at 0x7f0e0cdcfed0>}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何在管道中使用这个结果,如下所示:
| beam.io.WriteToBigQuery(
'thijs:thijsset.thijstable',
schema=table_schema,
write_disposition=beam.io.BigQueryDisposition.WRITE_APPEND,
create_disposition=beam.io.BigQueryDisposition.CREATE_IF_NEEDED)
| ['FailedRows'] from previous step
| "print" >> beam.Map(print)
Run Code Online (Sandbox Code Playgroud) python-3.x google-bigquery google-cloud-dataflow apache-beam
我需要为我正在处理的用例之一提供一些建议。
用例:
我们在 Cloud SQL 中有大约 5-10 个表的数据,有些被视为查找,有些被视为事务性的。我们需要以某种方式将其提供给 BigQuery,从中制作 3-4 个表(扁平化、嵌套或非规范化),这些表将用于 Data Studio、Looker 等中的报告。
数据应该以增量方式处理,并且 Cloud SQL 中的更改可能每 5 分钟发生一次,这意味着数据应该可以近乎实时地用于 BigQuery 报告。如果可能,我们还应该维护数据更改的历史记录。
解决方案:
我们在 BigQuery 中保留了 3 层,因此来自 Cloud SQL 的数据来到第一层,然后在展平后将其保存到第二层(维护历史记录),然后将其处理插入第三层(报告)。这种方法的 问题在于,它是为日常处理而开发的,无法帮助处理 Cloud SQL 中每 5 分钟更改一次的数据。
欢迎任何建议。
注意:-我们需要使用 Dataflow、VM 或其他方式来进行一些逻辑处理,这意味着我们不能只使用计划查询,因为我们不能使用查询来处理所有逻辑,但是可以使用视图和代码的混合.
dataflow google-cloud-sql google-bigquery google-cloud-platform google-cloud-dataflow
我看到 BigQuery 有一个内置的 I/O 连接器,但我们的很多数据都存储在 Snowflake 中。是否有连接到 Snowflake 的解决方法?我唯一能想到的就是使用 sqlalchemy 运行查询,然后将输出转储到 Cloud Storage Bucket,然后 Apache-Beam 可以从存储在 Bucket 中的文件中获取输入数据。
python pipeline google-cloud-dataflow snowflake-cloud-data-platform apache-beam
我正在研究一个从 Google Cloud Storage (GCS) 目录读取约 500 万个文件的管道。我已将其配置为在 Google Cloud Dataflow 上运行。
问题是,当我启动管道时,需要几个小时来“计算所有文件的大小”:
INFO:apache_beam.io.gcp.gcsio:Starting the size estimation of the input
INFO:apache_beam.io.gcp.gcsio:Finished computing size of: 10000 files
[...]
INFO:apache_beam.io.gcp.gcsio:Finished computing size of: 5480000 files
INFO:apache_beam.io.gcp.gcsio:Finished listing 5483720 files in 5549.38778591156 seconds.
INFO:apache_beam.io.gcp.gcsio:Starting the size estimation of the input
INFO:apache_beam.io.gcp.gcsio:Finished computing size of: 10000 files
[...]
INFO:apache_beam.io.gcp.gcsio:Finished computing size of: 5480000 files
INFO:apache_beam.io.gcp.gcsio:Finished listing 5483720 files in 7563.196493148804 seconds.
INFO:apache_beam.io.gcp.gcsio:Starting the size estimation of the input
INFO:apache_beam.io.gcp.gcsio:Finished computing size of: 10000 files …Run Code Online (Sandbox Code Playgroud) 我正在尝试执行去规范化操作,我需要使用以下逻辑重新组织表:
| itemid | class | value |
+--------+-------+-------+
| 1 | A | 0.2 | | itemid | value A | value B | value C |
| 1 | B | 10.3 | ==> +--------+---------+---------+---------+
| 2 | A | 3.0 | ==> | 1 | 0.2 | 10.3 | |
| 2 | B | 0.2 | ==> | 2 | 3.0 | 0.2 | |
| 3 | A | 0.0 | | 3 | 0.0 …Run Code Online (Sandbox Code Playgroud) apache-beam ×7
python ×6
dataflow ×1
json ×1
pipeline ×1
python-3.x ×1
snowflake-cloud-data-platform ×1
spotify-scio ×1