阵列的TDE标量类型

时间:2019-07-11 14:24:58

标签: marklogic marklogic-9

我正在尝试重新运行JSON Array对象作为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)

1 个答案:

答案 0 :(得分:0)

我认为略有不同的方法将使您到达想要去的地方。让我们将上下文从/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视图的每个地址,这将使您一行。


基于此注释添加信息:“我试图避免使用Joins以及要构建和维护的多个视图。由于建立索引,每个新模板在服务器上都会产生成本。”

值得记住的是,MarkLogic视图的实现与关系数据库中的视图不同。在后台,MarkLogic的视图是使用三重索引实现的,因此无论如何都会有联接。我上面列出的方法是处理这种情况的常用方法。