在我们的组织中,我们需要在 Databricks 和 Athena 中公开我们的数据。 我们有一些使用“get_json_object(my_col)['path']”函数的视图,并按 Databricks 的预期运行。一旦尝试从 Athena 查询相同的视图,我们就会得到以下异常:
VIEW_IS_STALE: line 2:6: View 'my_view' is stale or in invalid state:
column [my_col] of type json projected from query view
at position 256 cannot be coerced to column [response_syn_exp_pos_1_feature]
of type varchar stored in view definition
在 Athena 中,并行函数是“json_extract_scalar(my_col,'path')”,但它具有不同的名称和签名。
我确实想知道是否有任何方法可以解决这个问题,以便我们可以从 databricks 和 athena 查询相同的视图?
在 Databricks 中,您可能正在使用 get_json_object(my_col)['path'],它按预期工作。但是,在 Athena 中,等效函数是 json_extract_scalar(my_col,'path')。当尝试从 Athena 查询相同视图时,这种差异会导致错误,因为提取的 JSON 数据无法直接强制转换为视图定义所需的 VARCHAR 类型。
我想不出在 Athena 和 databricks 中使用相同视图的方法。您可以使用 json_extract_scalar 重新定义 Athena 中的视图
CREATE VIEW my_athena_view AS SELECT json_extract_scalar(my_col, '$.path') AS response_syn_exp_pos_1_feature FROM my_table