快速查看向 SQL 查询添加嵌套会导致 Athena 出错

Quick sight adding nesting to SQL query which causes errors in Athena

我正在尝试在 Quicksight 中创建一个非常简单的可视化,为此我在 Quicksight 中使用 SQL 查询,

SELECT COUNT(distinct uuid), day
FROM analytics.myTable
GROUP BY day

不幸的是,每当我在 Quicksight 中 运行 这个查询时,它都会因以下错误而失败

from the AWS Athena client. SYNTAX_ERROR: line 2:8: Column '_col0' cannot be resolved

当我查看 Athena 时,我可以看到 Quicksight 是 "nesting" SQL 查询...这就是导致 Athena 出现错误的原因,

/* QuickSight 4da449cf-ffc6-11e8-92ea-9ffafcc3adb3 */
SELECT "_col0"
FROM (SELECT COUNT(distinct uuid)
FROM pregnancy_analytics.final_test_parquet) AS "DAU"

我不明白的是: a) 为什么这是标记错误? b) 为什么 Quicksight 嵌套 SQL?

如果我直接在Athena中直接运行命令,

SELECT COUNT(distinct uuid) FROM analytics.myTable

确实显示了列名“_col0”,

    _col0
1   1699174

所以 Quicksight 引发错误实际上应该不是问题。

有人可以就如何解决这个问题提供一些建议吗?

谢谢

通常在可视化软件中,您需要明确命名您的 aggregate/function-wrapped 列,因为它们默认为 _col0 之类的东西,软件无法很好地解析,因此会抛出该错误。

具体来说,我一直在使用 Presto 的 Superset 中看到这一点。

对于您的明确问题,您应该按照 Piotr 的建议进行操作,即在 COUNT(distinct uuid) 之后添加一个名称 - 我偏爱 freq,但看起来您需要像 uuid 或 unique_uuid :)

您可以修改查询以显式命名聚合列,然后查询将起作用。

示例:

SELECT COUNT(distinct uuid) as "distinct_uuid", day
FROM analytics.myTable
GROUP BY day