【问题标题】:How to parse json data in a column with Druid SQL?如何使用 Druid SQL 解析列中的 json 数据?
【发布时间】:2022-04-29 04:45:25
【问题描述】:

我正在尝试在 Superset SQL 实验室中使用 Druid SQL 解析列中的 json 数据。我的桌子是这样的:

id json_scores
0 {"foo": 20, "bar": 10}
1 {"foo": 30, "bar": 10}

我在 MySQL 中寻找类似于 json_extract 的东西,例如

SELECT *
FROM my_table 
WHERE json_extract(json_scores, '$.foo') > 10;

【问题讨论】:

    标签: sql json apache-superset druid


    【解决方案1】:

    Druid 不支持json_extract 函数。 Druid 仅支持 ANSI SQL 92,它不将 JSON 理解为一种数据类型。

    此页面列出了支持的数据类型:https://docs.imply.io/latest/druid/querying/sql-data-types/

    您可以使用此处列出的任何表达式:https://druid.apache.org/docs/latest/misc/math-expr.html#string-functions

    在你的情况下考虑使用regexp_extract:

    regexp_extract(json_scprs, '(?<=\"foo\":\s)(\d+)(?=,)', 0) AS foo,
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-03
      • 1970-01-01
      • 2019-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-11
      • 1970-01-01
      相关资源
      最近更新 更多