雪花sql,嵌套在变体的第一级的阵列的平坦路径参数
根据以下内容,有一个由存储对象(又称字典,键值对)组成的变体字段“事件”,如下所示:
[
{ "field_name": "status", "id": 987418431597, "previous_value": "new", "type": "Change", "value": "pending"},
{ "field_name": "360020024138", "id": 987418431617, "previous_value": null, "type": "Change", "value": "#55927" },
{ "field_name": "360016698218", "id": 987418431637, "previous_value": null, "type": "Change", "value": "0681102386"},
{ "field_name": "360016774537", "id": 987418431657, "previous_value": null, "type": "Change", "value": "89367031562011632212"}
]
此字段属于事件日志,我试图使用“事件“作为获得相关时间戳和ID的过滤器。
通过 flatten上的雪花文档我发现<我发现<代码>递归=&gt; true 参数使我能够将变体一直延伸到其嵌套对象,但是希望通过优化代码,我想使用path
参数,以选择性地展开“事件” 但是,对于我感兴趣的对象。
但是,由于某种原因,Flatten不允许我通过数字路径来识别我要扩展的对象的数组索引,例如:
select b.*
from "event_log" a
,lateral flatten (input => a."events", path => 0) b limit 100;
返回:无效类型,0)]对于参数'路径'
和
select b.*
from "event_log" a
, lateral flatten (input => a."events", path => [0]) b limit 100;
返回:语法错误:意外'['。 (第162行)
具有讽刺意味的是,使用recursive =&gt; true
,B.Path字段表示[i]
之类的索引。
Sflake Docs中的示例是使用存储数组的对象使用路径参数的一个示例变体。
There is a Variant field "events" that is made up of an Array storing Objects(aka dictionaries, key-value pairs), as per the below:
[
{ "field_name": "status", "id": 987418431597, "previous_value": "new", "type": "Change", "value": "pending"},
{ "field_name": "360020024138", "id": 987418431617, "previous_value": null, "type": "Change", "value": "#55927" },
{ "field_name": "360016698218", "id": 987418431637, "previous_value": null, "type": "Change", "value": "0681102386"},
{ "field_name": "360016774537", "id": 987418431657, "previous_value": null, "type": "Change", "value": "89367031562011632212"}
]
This field belongs to an event log, and I am trying to use the content of "events" as a filter to get the related timestamps and ids.
Through the Snowflake documentation on Flatten I found out that the recursive => True
parameter allows me to expand the Variant all the way down to its nested objects, but with hopes of optimising code, I wanted to use the path
parameter, to selectively expand "events" only for the Objects I was interested in.
However, for some reason, Flatten does not allow me to pass a numeric path to identify the Array index of Object that I want to expand, as:
select b.*
from "event_log" a
,lateral flatten (input => a."events", path => 0) b limit 100;
returns: invalid type [NUMBER(1,0)] for parameter 'path'
and
select b.*
from "event_log" a
, lateral flatten (input => a."events", path => [0]) b limit 100;
returns: Syntax error: unexpected '['. (line 162)
Ironically, when using recursive => True
, the b.path field represent indexes like this [i]
.
The example in the SFlake docs makes an example of the use of the path parameter with an Object that stores Arrays, whereas here "events" is made up of an Array of Objects, so I actually do not have any working example for this type of Variants.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
阵列索引应作为
Input
:示例
:
The array index should be provided as
input
:Sample:
Output:
因此,每行都有一个数组。该数组具有许多具有相同“结构”的对象。获得ID是有道理的,因为每个对象都有一个。
因此,您可以访问它。
给出:
,但鉴于每个对象的ID看起来与众不同,您知道自己要纠正ID的情况似乎更有意义地使用Flatter来展开数组。并访问对象元素。
2行”中
:
So you have an array in each row. The array has many objects with the same "structure". Getting the ID makes sense as there is one in every object.
So you could just access it.
gives:
But given each object's ID looks to be different how do you know you are getting to correct ID's it would seem to make more sense to use flatten to unroll the array. and access the object elements.
so in this "2 rows" of 4 fields:
we get: