gpt4 book ai didi

arangodb - 在 ArangoDB 中调用函数 'ATTRIBUTES()' 时参数类型无效

转载 作者:行者123 更新时间:2023-12-05 03:11:10 25 4
gpt4 key购买 nike

我已将我的数据存储在 AreangoDB 中的给定格式中,我在 DSP 中的集合名称:

 "data": {
"1": [ {"db_name": "DSP"}, {"rel": "2"} ],
"2": [ {"rel_name": "DataSource"}, {"tuple": "201"}, {"tuple": "202"}, {"tuple": "203"} ],
"201": [ {"src_id": "Pos201510070"}, {"src_name": "Postgres"}, {"password": "root"}, {"host": "localhost"}, {"created_date": "20151007"}, {"user_name": "postgres"}, {"src_type": "Structured"}, {"db_name": "postgres"}, {"port": "None"} ],
"202": [ {"src_id": "pos201510060"}, {"src_name": "Postgres"},{"password": "root"}, {"host": "localhost"}, {"created_date": "20151006"}, {"user_name": "postgres"}, {"src_type": "Structured"}, {"db_name": "DSP"}, {"port": "5432"} ],
"203": [ {"src_id": "pos201510060"}, {"src_name": "Postgres"}, {"password": "root"}, {"host": "localhost"}, {"created_date": "20151006"}, {"user_name": "postgres"},{"src_type": "Structured"},{"db_name": "maindb"},{"port": "5432"} ]
}

我正在使用以下格式的上述数据执行查询:

  FOR p IN NestedDSP
LET attributes = ATTRIBUTES(p)
FOR attribute IN attributes
LET key = ATTRIBUTES(attribute)[0]
LET value = attribute[key]
RETURN { subject: attribute, predicate: key, object: value }

当我向 ArangoDB 提交查询时,它返回的响应如下:

    Warnings:

[1542], 'invalid argument type in call to function 'ATTRIBUTES()''
[1542], 'invalid argument type in call to function 'ATTRIBUTES()''
[1542], 'invalid argument type in call to function 'ATTRIBUTES()''
[1542], 'invalid argument type in call to function 'ATTRIBUTES()''

Result:

[
{
"subject": "data",
"predicate": null,
"object": null
},
{
"subject": "_id",
"predicate": null,
"object": null
},
{
"subject": "_rev",
"predicate": null,
"object": null
},
{
"subject": "_key",
"predicate": null,
"object": null
}
]

请告诉我这个查询有什么问题,以及为什么答案像上面那样......我在 ArangoDB-2.7.3-win64 中工作。

谢谢

最佳答案

让我演示如何构造深入挖掘嵌套数据结构的复杂查询。我开始采用查询的外部部分,以获得内部结果:

FOR p IN NestedDSP
LET attributes = ATTRIBUTES(p)
FOR attribute IN attributes
RETURN attribute

这给了我:

[ 
"data",
"_rev",
"_key",
"_id"
]

那么让我们深入到下一层。我猜您只对 data 键下的值感兴趣,对吗?所以我们选择p.data:

FOR p IN NestedDSP
LET attributes = ATTRIBUTES(p.data)
FOR attribute IN attributes
RETURN attribute

然后为我提供下一个内部数组的键:

[ 
"203",
"202",
"201",
"2",
"1"
]

我们现在探索我们发现附加到这些节点的内容:

FOR p IN NestedDSP
LET attributes = ATTRIBUTES(p.data)
FOR oneAttribute IN attributes
LET keys = p.data[oneAttribute]
RETURN keys

它又是一个数组,我们需要使用 FOR 键循环遍历它:

[
[
{
"src_id" : "pos201510060"
},
{
"src_name" : "Postgres"
}, ...

我们添加这个额外的 FOR 循环:

FOR p IN NestedDSP
LET attributes = ATTRIBUTES(p.data)
FOR oneAttribute IN attributes
LET keys = p.data[oneAttribute]
FOR key IN keys
RETURN key

我们得到最里面的对象:

[ 
{
"src_id" : "pos201510060"
},
{
"src_name" : "Postgres"
},
{
"password" : "root"
},
...

您想使用 ATTRIBUTES 函数,但对象只有一个成员,因此我们可以访问 [0]:

FOR p IN NestedDSP
LET attributes = ATTRIBUTES(p.data)
FOR oneAttribute IN attributes
LET keys = p.data[oneAttribute]
FOR key IN keys
LET keyAttributes=ATTRIBUTES(key)
RETURN keyAttributes

这给了我们对象键,每个最里面的对象一个:

[ 
[
"src_id"
],
[
"src_name"
],

我们检查现在是否只获得了最内层结构的对象键;我们选择比上面更聪明的变量名:

  FOR p IN NestedDSP
LET attributes = ATTRIBUTES(p.data)
FOR oneAttribute IN attributes
LET pairs = p.data[oneAttribute]
FOR onePair IN pairs
LET pairKey=ATTRIBUTES(onePair)[0]
RETURN pairKey

是的:

[ 
"src_id",
"src_name",
"password",
"host",
...

现在是时候根据需要构建结果对象了:

  FOR p IN NestedDSP
LET attributes = ATTRIBUTES(p.data)
FOR oneAttribute IN attributes
LET pairs = p.data[oneAttribute]
FOR onePair IN pairs
LET pairKey=ATTRIBUTES(onePair)[0]
RETURN { subject: oneAttribute, predicate: pairKey, object: onePair[pairKey] }

subject 是标识最外层项的数字,predicate 是对象键,object 是其中的值:

[ 
{
"subject" : "203",
"predicate" : "src_id",
"object" : "pos201510060"
},
{
"subject" : "203",
"predicate" : "src_name",
"object" : "Postgres"
}

希望哪一个是您想要的?

关于arangodb - 在 ArangoDB 中调用函数 'ATTRIBUTES()' 时参数类型无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37904470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com