- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
根据 BigQuery 文档,您可以通过提供 insertId
( https://cloud.google.com/bigquery/streaming-data-into-bigquery#dataconsistency ) 来确保数据的一致性。如果未提供,BQ 将尝试根据内部 ID 和尽力而为来确保一致性。
使用 BQ API,您可以使用 row_ids
参数 ( https://google-cloud-python.readthedocs.io/en/latest/bigquery/generated/google.cloud.bigquery.client.Client.insert_rows_json.html#google.cloud.bigquery.client.Client.insert_rows_json ) 来做到这一点,但我找不到 Apache Beam Python SDK 的相同参数。
查看 SDK 我注意到存在“unique_row_id”属性,但我真的不知道如何将我的参数传递给 WriteToBigQuery()
我如何写入 BQ(流式传输)以提供用于重复数据删除的行 ID?
最佳答案
If you use
WriteToBigQuery
then it will automatically create and insert a unique row id calledinsertId
for you, which will be inserted to bigquery. It's handled for you, you don't need to worry about it. :)
WriteToBigQuery
是一个PTransform
,在它的expand
方法中调用BigQueryWriteFn
BigQueryWriteFn
是一个DoFn
,在它的process
方法中调用_flush_batch
_flush_batch
是一个方法,然后调用 BigQueryWrapper.insert_rows
方法BigQueryWrspper.insert_rows
创建一个 bigquery.TableDataInsertAllRequest.RowsValueListEntry
对象列表,其中包含 insertId
和作为 json 对象的行数据insertId
是通过调用 unique_row_id
方法生成的,该方法返回一个由 UUID4 与 _
连接的值和一个自动递增的数字组成的值.在目前的2.7.0代码中,有这个开心的注释;我也证实了这是真的:) https://github.com/apache/beam/blob/master/sdks/python/apache_beam/io/gcp/bigquery.py#L1182
# Prepare rows for insertion. Of special note is the row ID that we add to
# each row in order to help BigQuery avoid inserting a row multiple times.
# BigQuery will do a best-effort if unique IDs are provided. This situation
# can happen during retries on failures.
BigQuerySink
至少,不是当前形式,因为它不支持流式传输。我想这可能会改变。
好问题,我也看过但找不到特定答案。
Apache Beam 似乎没有使用您链接到的那个 google.cloud.bigquery 客户端 sdk,它有一些内部生成的 api 客户端,但它似乎是最新的。
我看了下源码:insertall
方法在那里 https://github.com/apache/beam/blob/18d2168ee71a1b1b04976717f0f955199bb00961/sdks/python/apache_beam/io/gcp/internal/clients/bigquery/bigquery_v2_client.py#L476
我还发现提到的 insertid
https://github.com/apache/beam/blob/master/sdks/python/apache_beam/io/gcp/internal/clients/bigquery/bigquery_v2_messages.py#L1707
因此,如果您可以进行 InsertAll 调用,它将使用 TableDataInsertAllRequest
并传递 RowsValueListEntry
class TableDataInsertAllRequest(_messages.Message):
"""A TableDataInsertAllRequest object.
Messages:
RowsValueListEntry: A RowsValueListEntry object.
RowsValueListEntry
消息是 insertid 所在的位置。
这是用于全部插入的 API 文档 https://cloud.google.com/bigquery/docs/reference/rest/v2/tabledata/insertAll
我会进一步研究这个,因为我没有看到 WriteToBigQuery()
公开这个。
我怀疑“bigquery 会记住它至少一分钟”是一个非常松散的重复数据删除保证。如果您需要事务,文档建议使用数据存储。否则,您可能需要使用窗口函数运行 SQL 以在运行时进行重复数据删除,或者在 bigquery 上运行其他一些重复数据删除作业。
也许使用 WriteToBigQuery()
的 batch_size
参数,并在数据流中运行组合(或最坏情况下是 GroupByKey)步骤是一种更稳定的方法来删除先前的重复数据写作。
关于google-bigquery - Python Apache 光束 : BigQuery streaming deduplication by row_id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51080848/
下面是我的 SQL 查询 select c.course_id,c.course_title,c.course_credits,c.course_status from course c
我正在尝试从我的数据库中删除一条记录, 简短摘要: 我的数据库填充了一个 ListView 用户可以点击 ListView 并查看有关新 Activity 的更多详细信息 我希望能够删除从这项新 Ac
mysql - 如何在单个表中删除具有重复“row_id”但具有不同“recd_date”字段值的行,只留下具有最新“recd_date”的行? 试过下面的脚本... DELETE FROM ta
我在 SQLServer 中有表。 我在 c# 中有实体 ID 列表。 (例如:50、70、120 等)。 对于每个实体,我只需要获取具有最大日期的行,并在其中获取 row_id 的最大值。 例如:
如何在不使用 ROW_ID 的情况下创建 UPDATE 函数。出于某种原因,在 SQL 表中包含 ROW_ID 会给我多个错误。没有它,它工作得很好。我所需要的只是如何使用另一个约束更新中的 wher
我有一个 mysql 表,第一列名为“row_id”,并包含一个数字,显示在表中创建的行的 id。 下面是一个非常简单的示例,变得更容易: +--------+---------+------+---
我在 ScrollView 中使用自定义 GridView。我知道这不是正确的方法。我没有任何其他方法来完成我的应用程序布局。 我试图在 GridView 中获取数据库的 item id == row
我正在使用 Spring、MySQL 和 Hibernate 返回针对列“row_id”调整的超出范围的值,并且我正在尝试将一行插入到我的数据库中,但我收到以下错误: Hibernate: inser
我理解这个标题听起来很困惑,但目标很明确: 我正在构建一个需要两个表的应用程序:航迹和航路点。 用户通过文本字段输入轨道名称,表格在 track_id 下生成一个 ID。 在航点表中有一列叫做 tra
根据 BigQuery 文档,您可以通过提供 insertId ( https://cloud.google.com/bigquery/streaming-data-into-bigquery#dat
嗨,我有两个表“实验”和“示例”。我想创建一个触发器,这样每当我在 Sample 表中插入一行时,它都应该拉出 MySQL 在“Experiment”表中生成的最新“Experiment_id”,并拉
将 MySQL 与 InnoDB 存储结合使用时,如果表没有显式主键 (PK) 且没有唯一索引,则会导致将隐藏的 ROW_ID 列添加到这些表中,从而引入隐式 PK ( http://dev.mysq
我是一名优秀的程序员,十分优秀!