BQ 加入并在加入的列上进行铸造
BQ join with casting on joined column
我一直在与一个列进行艰难的连接,以连接存储为浮点数。另外,我需要加入 table 名称。我一直 以正确的格式朝着正确的方向前进,但我一直 运行 遇到连接问题。澄清一下(不要问我为什么,但是其中一个 (PARENT_ID
) 的列条目是 float
)。数据是历史数据,我无法更改这些 table,但希望能够 select 适当的 table 并加入 start_date 和 product_id
.为了让事情变得更紧密,我在田野上放了石膏。但是我不明白错误的来源。
with tab1 as (
select
cast(product_id as INT64) as product_id_64,
cast(FORMAT_DATE('%Y%m%d', CAST(start_date AS DATE)) as STRING) as start_date_string
from `project.user.table`
)
select * EXCEPT(GTIN, SALE_PRICE) from `user2.dataset.*` b
inner join tab1
on b._TABLE_SUFFIX = tab1.start_date_string
and tab1.product_id_64 = cast(b.PARENT_ID as INT64)
然后出现以下错误:Cannot read field of type FLOAT64 as STRING Field: PARENT_ID
不幸的是,你不能在这个查询中使用命令_TABLE_SUFFIX
,因为限制是你不能比较具有相同名称的列并且其中一个列具有不同的类型。您将收到此错误(无法将 FLOAT64 类型的字段读取为 STRING 字段:PARENT_ID)。
If a single scanned table has a schema mismatch (that is, a column
with the same name is of a different type), the query fails with the
error Cannot read field of type X as Y Field: column_name.
你可以在这个document中看到所有的限制。
我一直在与一个列进行艰难的连接,以连接存储为浮点数。另外,我需要加入 table 名称。我一直 PARENT_ID
) 的列条目是 float
)。数据是历史数据,我无法更改这些 table,但希望能够 select 适当的 table 并加入 start_date 和 product_id
.为了让事情变得更紧密,我在田野上放了石膏。但是我不明白错误的来源。
with tab1 as (
select
cast(product_id as INT64) as product_id_64,
cast(FORMAT_DATE('%Y%m%d', CAST(start_date AS DATE)) as STRING) as start_date_string
from `project.user.table`
)
select * EXCEPT(GTIN, SALE_PRICE) from `user2.dataset.*` b
inner join tab1
on b._TABLE_SUFFIX = tab1.start_date_string
and tab1.product_id_64 = cast(b.PARENT_ID as INT64)
然后出现以下错误:Cannot read field of type FLOAT64 as STRING Field: PARENT_ID
不幸的是,你不能在这个查询中使用命令_TABLE_SUFFIX
,因为限制是你不能比较具有相同名称的列并且其中一个列具有不同的类型。您将收到此错误(无法将 FLOAT64 类型的字段读取为 STRING 字段:PARENT_ID)。
If a single scanned table has a schema mismatch (that is, a column with the same name is of a different type), the query fails with the error Cannot read field of type X as Y Field: column_name.
你可以在这个document中看到所有的限制。