Same exactly Query Fails or "Succeeds" with different Aliases used

时间:2016-04-21 22:27:10

标签: google-bigquery

Below two versions of the same exactly query

Version 1 (uses k as alias in inner SELECT):

SELECT k as [year], w_vol, 
  ROW_NUMBER() OVER (ORDER BY k DESC) AS rank1,
  ROW_NUMBER() OVER (ORDER BY w_vol DESC) AS rank2
FROM (
  SELECT w_vol, c_date AS k FROM 
    (SELECT 1590 AS c_date, 1 AS w_vol),
    (SELECT 1599 AS c_date, 1 AS w_vol),
    (SELECT 1602 AS c_date, 1 AS w_vol),
    (SELECT 1609 AS c_date, 2 AS w_vol),
    (SELECT 1610 AS c_date, 1 AS w_vol),
)
ORDER BY 1

Version 2 (uses l as alias in inner SELECT):

SELECT l as [year], w_vol, 
  ROW_NUMBER() OVER (ORDER BY l DESC) AS rank1,
  ROW_NUMBER() OVER (ORDER BY w_vol DESC) AS rank2
FROM (
  SELECT w_vol, c_date AS l FROM 
    (SELECT 1590 AS c_date, 1 AS w_vol),
    (SELECT 1599 AS c_date, 1 AS w_vol),
    (SELECT 1602 AS c_date, 1 AS w_vol),
    (SELECT 1609 AS c_date, 2 AS w_vol),
    (SELECT 1610 AS c_date, 1 AS w_vol),
)
ORDER BY 1 

Below is output i am consistently getting for both queries (note No Cached Results is used)

enter image description here

I expected result be the same no matter what alias is used - it is just alias at all!

Question: Why I am consistently getting failure for Version 1 and "success" for Version 2?

2 个答案:

答案 0 :(得分:1)

这是一个相当有趣的错误,但好消息是它在BigQuery的标准SQL中得到修复。有关如何试用的详细信息 - 请查看https://cloud.google.com/bigquery/sql-reference/enabling-standard-sql

答案 1 :(得分:0)

我认为这是我提交为issue 403的错误的一个实例。将别名与不同范围的分区窗口组合时,似乎会发生错误。回复的团队成员表示,这将在即将进行的sql方言改革中得到修复。

那就是说,对我来说新鲜的是这个错误只发生在某些别名上。我无法使用k以外的任何别名重现您的错误。如果来自BigQuery团队的人能够确认这是否确实是同一个问题以及是否将通过承诺的更新修复它将会很棒。