我可以将数据从 CloudSQL 实时加载到 BigQuery 吗?
Can I load data from CloudSQL to BigQuery in realtime?
当前抓取数据并将它们转储到 cloudSQL postgres 数据库中。这些数据呈指数增长,我需要一种有效的方法来执行查询。数据库增长了 ~3GB /天,我希望将数据保留至少 3 个月。因此,我已将 CloudSQL 连接到 BigQuery。以下是我在 BigQuery 上 运行 的查询示例,但我我持怀疑态度..不确定查询是在 Postgres 还是 BigQuery 中执行的..
SELECT * FROM EXTERNAL_QUERY("project.us-cloudsql-instance", "SELECT date_trunc('day', created_at) d, variable1, AVG(variable2) FROM my_table GROUP BY 1,2 ORDER BY d;");
好像查询是在 postgreSQL 中执行的,而不是 BigQuery ..这是真的吗?如果是,我有没有办法将数据从 postgresql 实时加载到 bigquery 并直接在 bigquery 中执行查询?
尽管从技术上讲,可以将查询重写为
SELECT date_trunc('day', created_at) d, variable1, AVG(variable2)
FROM EXTERNAL_QUERY("project.us-cloudsql-instance",
"SELECT created_at, variable1, variable2 FROM my_table")
GROUP BY 1,2 ORDER BY d;
虽然不推荐。最好尽可能在 CloudSQL 上进行聚合和过滤,以减少必须从 CloudSQL 传输到 BigQuery 的数据量。
我认为您正在使用 federated queries
。这些查询旨在从 BigQuery 和 CloudSQLInstance 收集数据:
BigQuery Cloud SQL federation enables BigQuery to query data residing in Cloud SQL in real-time, without copying or moving data. It supports both MySQL (2nd generation) and PostgreSQL instances in Cloud SQL.
查询正在 CloudSQL 中执行,这可能会导致性能低于 运行 在 BigQuery 中。
EXTERNAL_QUERY executes the query in Cloud SQL and returns results as a temporary table. The result would be a BigQuery
table.
现在,load data into BigQuery 的当前方式来自:GCS、其他 Google Ad Manager 和 Google Ads,一个可读数据源,通过使用流式插入插入单个记录, Dataflow 管道中的 DML 语句和 BigQuery I/O 转换。
This solution 非常值得一看,它与您需要的非常相似:
The MySQL to GCS operator executes a SELECT query against a MySQL table. The SELECT pulls all data greater than (or equal to) the last high watermark. The high watermark is either the primary key of the table (if the table is append-only), or a modification timestamp column (if the table receives updates). Again, the SELECT statement also goes back a bit in time (or rows) to catch potentially dropped rows from the last query (due to the issues mentioned above).
借助 Airflow,他们设法让 BigQuery 每 15 分钟与他们的 MySQL 数据库保持同步。
当前抓取数据并将它们转储到 cloudSQL postgres 数据库中。这些数据呈指数增长,我需要一种有效的方法来执行查询。数据库增长了 ~3GB /天,我希望将数据保留至少 3 个月。因此,我已将 CloudSQL 连接到 BigQuery。以下是我在 BigQuery 上 运行 的查询示例,但我我持怀疑态度..不确定查询是在 Postgres 还是 BigQuery 中执行的..
SELECT * FROM EXTERNAL_QUERY("project.us-cloudsql-instance", "SELECT date_trunc('day', created_at) d, variable1, AVG(variable2) FROM my_table GROUP BY 1,2 ORDER BY d;");
好像查询是在 postgreSQL 中执行的,而不是 BigQuery ..这是真的吗?如果是,我有没有办法将数据从 postgresql 实时加载到 bigquery 并直接在 bigquery 中执行查询?
尽管从技术上讲,可以将查询重写为
SELECT date_trunc('day', created_at) d, variable1, AVG(variable2)
FROM EXTERNAL_QUERY("project.us-cloudsql-instance",
"SELECT created_at, variable1, variable2 FROM my_table")
GROUP BY 1,2 ORDER BY d;
虽然不推荐。最好尽可能在 CloudSQL 上进行聚合和过滤,以减少必须从 CloudSQL 传输到 BigQuery 的数据量。
我认为您正在使用 federated queries
。这些查询旨在从 BigQuery 和 CloudSQLInstance 收集数据:
BigQuery Cloud SQL federation enables BigQuery to query data residing in Cloud SQL in real-time, without copying or moving data. It supports both MySQL (2nd generation) and PostgreSQL instances in Cloud SQL.
查询正在 CloudSQL 中执行,这可能会导致性能低于 运行 在 BigQuery 中。
EXTERNAL_QUERY executes the query in Cloud SQL and returns results as a temporary table. The result would be a
BigQuery
table.
现在,load data into BigQuery 的当前方式来自:GCS、其他 Google Ad Manager 和 Google Ads,一个可读数据源,通过使用流式插入插入单个记录, Dataflow 管道中的 DML 语句和 BigQuery I/O 转换。
This solution 非常值得一看,它与您需要的非常相似:
The MySQL to GCS operator executes a SELECT query against a MySQL table. The SELECT pulls all data greater than (or equal to) the last high watermark. The high watermark is either the primary key of the table (if the table is append-only), or a modification timestamp column (if the table receives updates). Again, the SELECT statement also goes back a bit in time (or rows) to catch potentially dropped rows from the last query (due to the issues mentioned above).
借助 Airflow,他们设法让 BigQuery 每 15 分钟与他们的 MySQL 数据库保持同步。