BigQuery位置函数



我试图使用位置函数,它似乎不像预期的那样工作:

POSITION(field) -返回一组重复字段中字段的基于1的顺序位置。

我希望位置在加载的数据中给出原始位置,而我在结果集中获得位置(即-在where子句运行之后)。

是否有一种方法可以在原始数据中加载位置?

比较下面的两个查询来查看问题。

SELECT  
  ngram,
  cell.value,
  position(cell.volume_count) as pos,
FROM [publicdata:samples.trigrams] 
where ngram contains ", says Blake"
SELECT  
  ngram,
  cell.value,
  position(cell.volume_count) as pos,
FROM [publicdata:samples.trigrams] 
where ngram contains ", says Blake" and integer(cell.value) % 5 = 0

问题是位置函数在where子句过滤嵌套值之后得到评估。你可以通过嵌套select:

来修复这个问题。
select
  ngram,
  value,
  pos,
from (
  select  
    ngram,
    cell.value as value,
    position(cell.volume_count) as pos,
  from [publicdata:samples.trigrams] 
  where ngram contains ", says Blake"
)
where integer(cell.value) % 5 == 0

最新更新