Apache Drill - 在 KVGEN 方法上出错

Apache Drill - Getting error on KVGEN method

我有一个庞大的数据集,其中每条记录都有 json 类似于以下的数据 -

{"project":{"id":"2625","createDate":1542597000000,"rank":0,"highlight":false,"isDisplay":true,"isNewProject":true,"propertyId":2231,"districts":{"id":41,"name":"abc","region":"123"}}}

当我尝试在 apache drill 中使用 select kvgen(t.project) from dfs.filePath t 生成键值对时,出现以下错误 -

DrillRuntimeException: Mappify/kvgen does not support heterogeneous value types. All values in the input map must be of the same type. The field [createDate] has a differing type [minor_type: BIGINT mode: OPTIONAL ]

看起来 drill 期望所有值都是同一类型。但是怎么做呢? drill有什么功能可用吗?

我的钻头版本是1.9.0

尝试将会话选项 store.json.all_text_mode 设置为 true。

https://drill.apache.org/docs/json-data-model/

我明白了。如果嵌套了 json,KVGEN 方法将不起作用。 为了让它工作,有两种方法可以遵循 -

  • 取出
  • 外面的嵌套json

{"project":{"id":"2625","createDate":1542597000000,"rank":0,"highlight":false,"isDisplay":true,"isNewProject":true,"propertyId":2231},"districts":{"id":41,"name":"abc","region":"123"}}

然后应用 KVGEN 方法作为 select kvgen(t.project) from dfs.filePath t

  • 首先在内部 json 上应用 kvgen 方法,然后使用如下嵌套查询

    select tbl2.col1.id, tbl2.col2.value from (select tbl1.project as col1, flatten(kvgen(tbl1.project.districts)) col2 from dfs.filePath tbl1) tbl2

正如@arina-yelchiyeva 正确提到的那样,会话选项 store.json.all_text_mode 需要设置为 true。