在 ArangoDB 中调用函数 'ATTRIBUTES()' 时参数类型无效
invalid argument type in call to function 'ATTRIBUTES()' in ArangoDB
我已将我的数据存储在 AreangoDB 中的给定甲酸盐中,我在 DSP 中的 collection 名称:
"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 提交查询时,returns 响应为:
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"
}
希望哪一个是您想要的?
我已将我的数据存储在 AreangoDB 中的给定甲酸盐中,我在 DSP 中的 collection 名称:
"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 提交查询时,returns 响应为:
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"
}
希望哪一个是您想要的?