数组的 TDE 标量类型
TDE Scalar Type for Array
我正在尝试将 JSON 数组对象作为 TDE 中的列重新运行。标量类型应该是什么?
我正在使用 MarkLogic 10.0-1。我的 JSON 文档处于嵌套结构中,我想使用 TDE 公开行视图,其中包含一个数组对象的字段。我尝试将 scalarType 用作字符串,但出现 tde.nodeDataExtract 错误。有办法克服这个问题吗?
下面给出了示例文档和模板
var doc1 = xdmp.toJSON(
{
"customer":{
"Name": "afgasdfasfasffasf",
"Addr": [
{
"AddrTypeCd": "MailingAddress",
"Addr1": "911 FORBES AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "PA",
"PostalCode": "15219"
},
{
"AddrTypeCd": "OfficeAddress",
"Addr1": "911 Watson AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "CT",
"PostalCode": "15119"
}
]
}
});
var rowtde1 = xdmp.toJSON(
{
"template":{
"context":"/customer",
"rows":[
{
"schemaName":"Schemas",
"viewName":"SampleCustomer",
"columns":[
{
"name":"CustomerName",
"scalarType":"string",
"val":"Name"
},
{
"name":"Addr",
"scalarType":"string",
"val":"Addr"
}
]
}
]
}
}
);
tde.nodeDataExtract([doc1],[rowtde1]);
执行错误:
[javascript] TDE-EVALFAILED:
tde.nodeDataExtract([Document({"customer":{"Name":"afgasdfasfasffasf",
"Addr":[{"AddrTypeCd":"MailingAddress", ...}, ...]}})],
[Document({"template":{"context":"/customer", "rows":
[{"schemaName":"Schemas", ...}]}})]) -- Eval for Column Addr='Addr'
returns multiple values (only one is expected)
我认为稍微不同的方法可以让您到达您想去的地方。让我们将上下文从 /customer
更改为 /customer/Addr
。现在,TDE 可以为数组中的每一项提取一行。 (如果您有一堆要提取的数据不在数组中,您将使用多个模板来填充索引。
var doc1 = xdmp.toJSON(
{
"customer":{
"Name": "afgasdfasfasffasf",
"Addr": [
{
"AddrTypeCd": "MailingAddress",
"Addr1": "911 FORBES AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "PA",
"PostalCode": "15219"
},
{
"AddrTypeCd": "OfficeAddress",
"Addr1": "911 Watson AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "CT",
"PostalCode": "15119"
}
]
}
});
var rowtde1 = xdmp.toJSON(
{
"template":{
"context":"/customer/Addr",
"rows":[
{
"schemaName":"Schemas",
"viewName":"CustomerAddress",
"columns":[
{
"name":"CustomerName",
"scalarType":"string",
"val":"../../Name"
},
{
"name":"AddrTypeCd",
"scalarType":"string",
"val":"AddrTypeCd"
},
{
"name":"Addr1",
"scalarType":"string",
"val":"Addr1"
},
{
"name":"Addr2",
"scalarType":"string",
"val":"Addr2"
},
{
"name":"CityName",
"scalarType":"string",
"val":"CityName"
},
{
"name":"StateProvCd",
"scalarType":"string",
"val":"StateProvCd"
},
{
"name":"PostalCode",
"scalarType":"string",
"val":"PostalCode"
}
]
}
]
}
}
);
tde.nodeDataExtract([doc1],[rowtde1]);
这会为添加到 Schemas.CustomerAddress 视图的每个地址获取一行。
根据此评论添加信息:"I'm trying to avoid Joins as well as multiple views to build and maintain. Every new template, has a cost on the server due to indexing."
值得记住的是,MarkLogic 视图的实现方式与关系数据库中的视图不同。在幕后,MarkLogic 的视图是使用三重索引实现的,因此无论如何都会有连接。我上面列出的方法是处理这种情况的常用方法。
我正在尝试将 JSON 数组对象作为 TDE 中的列重新运行。标量类型应该是什么?
我正在使用 MarkLogic 10.0-1。我的 JSON 文档处于嵌套结构中,我想使用 TDE 公开行视图,其中包含一个数组对象的字段。我尝试将 scalarType 用作字符串,但出现 tde.nodeDataExtract 错误。有办法克服这个问题吗?
下面给出了示例文档和模板
var doc1 = xdmp.toJSON(
{
"customer":{
"Name": "afgasdfasfasffasf",
"Addr": [
{
"AddrTypeCd": "MailingAddress",
"Addr1": "911 FORBES AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "PA",
"PostalCode": "15219"
},
{
"AddrTypeCd": "OfficeAddress",
"Addr1": "911 Watson AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "CT",
"PostalCode": "15119"
}
]
}
});
var rowtde1 = xdmp.toJSON(
{
"template":{
"context":"/customer",
"rows":[
{
"schemaName":"Schemas",
"viewName":"SampleCustomer",
"columns":[
{
"name":"CustomerName",
"scalarType":"string",
"val":"Name"
},
{
"name":"Addr",
"scalarType":"string",
"val":"Addr"
}
]
}
]
}
}
);
tde.nodeDataExtract([doc1],[rowtde1]);
执行错误:
[javascript] TDE-EVALFAILED:
tde.nodeDataExtract([Document({"customer":{"Name":"afgasdfasfasffasf",
"Addr":[{"AddrTypeCd":"MailingAddress", ...}, ...]}})],
[Document({"template":{"context":"/customer", "rows":
[{"schemaName":"Schemas", ...}]}})]) -- Eval for Column Addr='Addr'
returns multiple values (only one is expected)
我认为稍微不同的方法可以让您到达您想去的地方。让我们将上下文从 /customer
更改为 /customer/Addr
。现在,TDE 可以为数组中的每一项提取一行。 (如果您有一堆要提取的数据不在数组中,您将使用多个模板来填充索引。
var doc1 = xdmp.toJSON(
{
"customer":{
"Name": "afgasdfasfasffasf",
"Addr": [
{
"AddrTypeCd": "MailingAddress",
"Addr1": "911 FORBES AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "PA",
"PostalCode": "15219"
},
{
"AddrTypeCd": "OfficeAddress",
"Addr1": "911 Watson AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "CT",
"PostalCode": "15119"
}
]
}
});
var rowtde1 = xdmp.toJSON(
{
"template":{
"context":"/customer/Addr",
"rows":[
{
"schemaName":"Schemas",
"viewName":"CustomerAddress",
"columns":[
{
"name":"CustomerName",
"scalarType":"string",
"val":"../../Name"
},
{
"name":"AddrTypeCd",
"scalarType":"string",
"val":"AddrTypeCd"
},
{
"name":"Addr1",
"scalarType":"string",
"val":"Addr1"
},
{
"name":"Addr2",
"scalarType":"string",
"val":"Addr2"
},
{
"name":"CityName",
"scalarType":"string",
"val":"CityName"
},
{
"name":"StateProvCd",
"scalarType":"string",
"val":"StateProvCd"
},
{
"name":"PostalCode",
"scalarType":"string",
"val":"PostalCode"
}
]
}
]
}
}
);
tde.nodeDataExtract([doc1],[rowtde1]);
这会为添加到 Schemas.CustomerAddress 视图的每个地址获取一行。
根据此评论添加信息:"I'm trying to avoid Joins as well as multiple views to build and maintain. Every new template, has a cost on the server due to indexing."
值得记住的是,MarkLogic 视图的实现方式与关系数据库中的视图不同。在幕后,MarkLogic 的视图是使用三重索引实现的,因此无论如何都会有连接。我上面列出的方法是处理这种情况的常用方法。