我正在尝试使用BigQuery中的虚拟表和数据来测试一些逻辑。我使用
成功完成了这项工作WITH dummy AS (SELECT 1 AS a)
SELECT a FROM dummy
通过使用更复杂的WITH语句,我可以在这个虚拟表上尝试一些不同的逻辑。
现在我打了一堵墙,因为我在不同的分区中有一些我想要测试的数据。使用标准SQL我可以执行以下操作:
SELECT a
FROM
`dummy_*`
WHERE
_TABLE_SUFFIX BETWEEN '20161001' AND '20161003'
但是我真的希望能够为WITH子句中的子查询做同样的事情:
WITH
dummy_20161001 AS (SELECT 1 AS a UNION ALL SELECT 4 AS a),
dummy_20161002 AS (SELECT 7 AS a UNION ALL SELECT 10 AS a)
SELECT a FROM dummy_*
WHERE
_TABLE_SUFFIX BETWEEN '20161001' AND '20161003'
有什么东西我可以替换_TABLE_SUFFIX来执行此操作,还是有其他方法来创建表分区的虚拟表示形式?
答案 0 :(得分:1)
在我看来,下面可以满足您的测试需求。至少这是一个选项:o)
WITH
dummy_20161001 AS (SELECT 1 AS a UNION ALL SELECT 2 AS a),
dummy_20161002 AS (SELECT 3 AS a UNION ALL SELECT 4 AS a),
dummy_20161003 AS (SELECT 5 AS a UNION ALL SELECT 6 AS a),
dummy_20161004 AS (SELECT 7 AS a UNION ALL SELECT 8 AS a),
`dummy_*` as (
SELECT *, '20161001' as _TABLE_SUFFIX FROM dummy_20161001 UNION ALL
SELECT *, '20161002' as _TABLE_SUFFIX FROM dummy_20161002 UNION ALL
SELECT *, '20161003' as _TABLE_SUFFIX FROM dummy_20161003 UNION ALL
SELECT *, '20161004' as _TABLE_SUFFIX FROM dummy_20161004
)
SELECT a
FROM `dummy_*`
WHERE
_TABLE_SUFFIX BETWEEN '20161001' AND '20161003'
答案 1 :(得分:0)
_TABLE_SUFFIX
和(如果使用分区表 - _PARTITIONTIME
)伪列仅适用于BigQuery托管表。
您是否可以将示例数据写入多个表或单个分区表(使用带有destination_table的SELECT查询)?之后,您应该能够使用伪列。