如何将 op.arrayAggregate 方法调用到 return 多列
How can I call op.arrayAggregate method to return multiple columns
我尝试按名称对以下回复进行分组:
{
"document1": [
{
"row": {
"schema": "Schemas",
"view": "CustomerAddress",
"data": {
"rownum": "1",
"CustomerName": "Name1",
"AddrTypeCd": "MailingAddress",
"Addr1": "911 FORBES AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "PA",
"PostalCode": "15219"
}
}
},
{
"row": {
"schema": "Schemas",
"view": "CustomerAddress",
"data": {
"rownum": "2",
"CustomerName": "Name1",
"AddrTypeCd": "OfficeAddress",
"Addr1": "911 Watson AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "CT",
"PostalCode": "15119"
}
}
}
],
"document2": []
}
我是这样用的arrayAggregate
方法
.groupBy(customerAddreses.col('CustomerName'),
op.arrayAggregate("Customer addresses", customerAddreses.col('Addr1')))
我当前的响应数据如下所示:
{
"schemas.customerAddreses.CustomerName": "Name1",
"Customer addresses": [
"911 FORBES AVE",
"911 Watson AVE"
]
}
是否可以使用多个列调用 arrayAggregate
并在客户地址数组中接收对象?以下是我想要获得的回复:
{
"schemas.customerAddreses.CustomerName": "Name1",
"Customer addresses": [
{
"Addr1": "911 FORBES AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "PA",
},
{
"Addr1": "911 Watson AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "CT"
}
]
}
Input
{
"document1": [
{
"data": {
"rownum": "1",
"CustomerName": "Name1",
"AddrTypeCd": "MailingAddress",
"Addr1": "911 FORBES AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "PA",
"PostalCode": "15219"
}
},
{
"data": {
"rownum": "2",
"CustomerName": "Name1",
"AddrTypeCd": "OfficeAddress",
"Addr1": "911 Watson AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "CT",
"PostalCode": "15119"
}
}
]
}
JavaScript Optic
op.fromView('main', 'CustomerAddress')
.select(['Addr1',
'Addr2',
'CityName',
'StateProvCd',
'CustomerName',
op.as('addrAggr', op.jsonObject([
op.prop('Addr1', op.col('Addr1')),
op.prop('Addr2', op.col('Addr2')),
op.prop('CityName', op.col('CityName')),
op.prop('StateProvCd', op.col('StateProvCd'))
]))
])
.orderBy(op.asc('Addr1')) //Line14
.groupBy('CustomerName', op.arrayAggregate("Customer addresses", "addrAggr"))
.result();
Result
{
"CustomerName": "Name1",
"Customer addresses": [
{
"Addr1": "911 FORBES AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "PA"
},
{
"Addr1": "911 Watson AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "CT"
}
]
}
Note
- 您的 TDE 视图名称一个是
CustomerAddress
而另一个是 customerAddreses
。不确定如何获得任何结果。
- 要镜像SQL-like
ORDER
,请在Optic中添加sort
子句(Line14
)。
- JSON root 属性 名称要一致。也许,
address
而不是 document1
.
我尝试按名称对以下回复进行分组:
{
"document1": [
{
"row": {
"schema": "Schemas",
"view": "CustomerAddress",
"data": {
"rownum": "1",
"CustomerName": "Name1",
"AddrTypeCd": "MailingAddress",
"Addr1": "911 FORBES AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "PA",
"PostalCode": "15219"
}
}
},
{
"row": {
"schema": "Schemas",
"view": "CustomerAddress",
"data": {
"rownum": "2",
"CustomerName": "Name1",
"AddrTypeCd": "OfficeAddress",
"Addr1": "911 Watson AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "CT",
"PostalCode": "15119"
}
}
}
],
"document2": []
}
我是这样用的arrayAggregate
方法
.groupBy(customerAddreses.col('CustomerName'),
op.arrayAggregate("Customer addresses", customerAddreses.col('Addr1')))
我当前的响应数据如下所示:
{
"schemas.customerAddreses.CustomerName": "Name1",
"Customer addresses": [
"911 FORBES AVE",
"911 Watson AVE"
]
}
是否可以使用多个列调用 arrayAggregate
并在客户地址数组中接收对象?以下是我想要获得的回复:
{
"schemas.customerAddreses.CustomerName": "Name1",
"Customer addresses": [
{
"Addr1": "911 FORBES AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "PA",
},
{
"Addr1": "911 Watson AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "CT"
}
]
}
Input
{
"document1": [
{
"data": {
"rownum": "1",
"CustomerName": "Name1",
"AddrTypeCd": "MailingAddress",
"Addr1": "911 FORBES AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "PA",
"PostalCode": "15219"
}
},
{
"data": {
"rownum": "2",
"CustomerName": "Name1",
"AddrTypeCd": "OfficeAddress",
"Addr1": "911 Watson AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "CT",
"PostalCode": "15119"
}
}
]
}
JavaScript Optic
op.fromView('main', 'CustomerAddress')
.select(['Addr1',
'Addr2',
'CityName',
'StateProvCd',
'CustomerName',
op.as('addrAggr', op.jsonObject([
op.prop('Addr1', op.col('Addr1')),
op.prop('Addr2', op.col('Addr2')),
op.prop('CityName', op.col('CityName')),
op.prop('StateProvCd', op.col('StateProvCd'))
]))
])
.orderBy(op.asc('Addr1')) //Line14
.groupBy('CustomerName', op.arrayAggregate("Customer addresses", "addrAggr"))
.result();
Result
{
"CustomerName": "Name1",
"Customer addresses": [
{
"Addr1": "911 FORBES AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "PA"
},
{
"Addr1": "911 Watson AVE",
"Addr2": "SUITE XXX",
"CityName": "asdfasfd",
"StateProvCd": "CT"
}
]
}
Note
- 您的 TDE 视图名称一个是
CustomerAddress
而另一个是customerAddreses
。不确定如何获得任何结果。 - 要镜像SQL-like
ORDER
,请在Optic中添加sort
子句(Line14
)。 - JSON root 属性 名称要一致。也许,
address
而不是document1
.