CallQueryComponent 数据查询
1. 结构声明
- TS Declaration
- JSON Schema
class CallQueryComponent extends LogicItem {
select: QuerySelectExpression;
from: QueryFromExpression;
where?: LogicItem;
wherePlayground?: Array<LogicItem>;
groupBy: Array<QueryGroupByExpression>;
having?: LogicItem;
havingPlayground?: Array<LogicItem>;
orderBy: Array<QueryOrderByExpression>;
limit?: QueryLimitExpression;
ideVersion: string;
}
{
"type": "object",
"properties": {
"composedBy": {
"type": "array",
"items": {
"type": "string"
}
},
"label": {
"type": "string"
},
"description": {
"type": "string"
},
"folded": {
"type": "boolean"
},
"offsetX": {
"type": "number"
},
"offsetY": {
"type": "number"
},
"typeAnnotation": {
"$ref": "#/definitions/TypeAnnotation"
},
"select": {
"$ref": "#/definitions/QuerySelectExpression"
},
"from": {
"$ref": "#/definitions/QueryFromExpression"
},
"where": {
"$ref": "#/definitions/LogicItem"
},
"wherePlayground": {
"type": "array",
"items": {
"$ref": "#/definitions/LogicItem"
}
},
"groupBy": {
"type": "array",
"items": {
"$ref": "#/definitions/QueryGroupByExpression"
}
},
"having": {
"$ref": "#/definitions/LogicItem"
},
"havingPlayground": {
"type": "array",
"items": {
"$ref": "#/definitions/LogicItem"
}
},
"orderBy": {
"type": "array",
"items": {
"$ref": "#/definitions/QueryOrderByExpression"
}
},
"limit": {
"$ref": "#/definitions/QueryLimitExpression"
},
"ideVersion": {
"type": "string"
}
},
"required": [
"select",
"from",
"groupBy",
"orderBy",
"ideVersion"
],
"additionalProperties": false
}
2. 节点示例
(1) 示例
AST 如下:
- JSON
- YAML
{
"concept": "CallQueryComponent",
"select": {
"concept": "QuerySelectExpression",
"distinct": false,
"star": true,
"selectElements": [
{
"concept": "QueryFieldExpression",
"isDotStar": true,
"entityAsName": "OrderProduct",
"propertyName": "",
"asName": ""
},
{
"concept": "QueryFieldExpression",
"isDotStar": true,
"entityAsName": "OrderForm",
"propertyName": "",
"asName": ""
},
{
"concept": "QueryFieldExpression",
"isDotStar": true,
"entityAsName": "Product",
"propertyName": "",
"asName": ""
},
{
"concept": "QueryAggregateExpression",
"asName": "totalAmount",
"aggregateName": "SUM",
"aggregateParam": {
"concept": "QueryFieldExpression",
"isDotStar": false,
"entityAsName": "OrderProduct",
"propertyName": "amount",
"asName": ""
}
}
]
},
"from": {
"concept": "QueryFromExpression",
"entityNamespace": "app.dataSources.defaultDS.entities",
"entityName": "OrderProduct",
"joinParts": [
{
"concept": "QueryJoinExpression",
"entityNamespace": "app.dataSources.defaultDS.entities",
"entityName": "OrderForm",
"joinType": "INNER",
"onExpressions": [
{
"concept": "BinaryExpression",
"left": {
"concept": "QueryFieldExpression",
"isDotStar": false,
"entityAsName": "OrderProduct",
"propertyName": "orderId",
"asName": ""
},
"right": {
"concept": "QueryFieldExpression",
"isDotStar": false,
"entityAsName": "OrderForm",
"propertyName": "id",
"asName": ""
},
"operator": "=="
}
],
"joinParts": [],
"asName": ""
},
{
"concept": "QueryJoinExpression",
"entityNamespace": "app.dataSources.defaultDS.entities",
"entityName": "Product",
"joinType": "INNER",
"onExpressions": [
{
"concept": "BinaryExpression",
"left": {
"concept": "QueryFieldExpression",
"isDotStar": false,
"entityAsName": "OrderProduct",
"propertyName": "productId",
"asName": ""
},
"right": {
"concept": "QueryFieldExpression",
"isDotStar": false,
"entityAsName": "Product",
"propertyName": "id",
"asName": ""
},
"operator": "=="
}
],
"joinParts": [],
"asName": ""
}
],
"asName": ""
},
"where": {
"concept": "BinaryExpression",
"left": {
"concept": "BinaryExpression",
"left": {
"concept": "QueryFieldExpression",
"isDotStar": false,
"entityAsName": "OrderProduct",
"propertyName": "createdBy",
"asName": "createdBy"
},
"right": {
"concept": "StringLiteral",
"value": "张三"
},
"operator": "=="
},
"right": {
"concept": "BinaryExpression",
"left": {
"concept": "QueryFieldExpression",
"isDotStar": false,
"entityAsName": "OrderProduct",
"propertyName": "createdTime",
"asName": ""
},
"right": {
"concept": "Identifier",
"namespace": "",
"name": "startDateTime"
},
"operator": ">"
},
"operator": "&&"
},
"wherePlayground": [],
"groupBy": [
{
"concept": "QueryGroupByExpression",
"groupElement": {
"concept": "QueryFieldExpression",
"isDotStar": false,
"asName": "productId",
"entityAsName": "OrderProduct",
"propertyName": "productId"
}
},
{
"concept": "QueryGroupByExpression",
"groupElement": {
"concept": "QueryFieldExpression",
"isDotStar": false,
"asName": "productName",
"entityAsName": "Product",
"propertyName": "name"
}
}
],
"havingPlayground": [],
"orderBy": [
{
"concept": "QueryOrderByExpression",
"orderElement": {
"concept": "Identifier",
"namespace": "inner",
"name": "productName"
},
"order": {
"concept": "StringLiteral",
"value": "ASC"
}
}
],
"limit": {
"concept": "QueryLimitExpression",
"pageElement": {
"concept": "NumericLiteral",
"value": "1",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Long",
"inferred": false,
"ruleMap": {}
}
},
"pageSizeElement": {
"concept": "NumericLiteral",
"value": "1000",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Long",
"inferred": false,
"ruleMap": {}
}
}
},
"ideVersion": "2.22"
}
concept: CallQueryComponent
select:
concept: QuerySelectExpression
distinct: false
star: true
selectElements:
- concept: QueryFieldExpression
isDotStar: true
entityAsName: OrderProduct
propertyName: ""
asName: ""
- concept: QueryFieldExpression
isDotStar: true
entityAsName: OrderForm
propertyName: ""
asName: ""
- concept: QueryFieldExpression
isDotStar: true
entityAsName: Product
propertyName: ""
asName: ""
- concept: QueryAggregateExpression
asName: totalAmount
aggregateName: SUM
aggregateParam:
concept: QueryFieldExpression
isDotStar: false
entityAsName: OrderProduct
propertyName: amount
asName: ""
from:
concept: QueryFromExpression
entityNamespace: app.dataSources.defaultDS.entities
entityName: OrderProduct
joinParts:
- concept: QueryJoinExpression
entityNamespace: app.dataSources.defaultDS.entities
entityName: OrderForm
joinType: INNER
onExpressions:
- concept: BinaryExpression
left:
concept: QueryFieldExpression
isDotStar: false
entityAsName: OrderProduct
propertyName: orderId
asName: ""
right:
concept: QueryFieldExpression
isDotStar: false
entityAsName: OrderForm
propertyName: id
asName: ""
operator: ==
joinParts: []
asName: ""
- concept: QueryJoinExpression
entityNamespace: app.dataSources.defaultDS.entities
entityName: Product
joinType: INNER
onExpressions:
- concept: BinaryExpression
left:
concept: QueryFieldExpression
isDotStar: false
entityAsName: OrderProduct
propertyName: productId
asName: ""
right:
concept: QueryFieldExpression
isDotStar: false
entityAsName: Product
propertyName: id
asName: ""
operator: ==
joinParts: []
asName: ""
asName: ""
where:
concept: BinaryExpression
left:
concept: BinaryExpression
left:
concept: QueryFieldExpression
isDotStar: false
entityAsName: OrderProduct
propertyName: createdBy
asName: createdBy
right:
concept: StringLiteral
value: 张三
operator: ==
right:
concept: BinaryExpression
left:
concept: QueryFieldExpression
isDotStar: false
entityAsName: OrderProduct
propertyName: createdTime
asName: ""
right:
concept: Identifier
namespace: ""
name: startDateTime
operator: ">"
operator: "&&"
wherePlayground: []
groupBy:
- concept: QueryGroupByExpression
groupElement:
concept: QueryFieldExpression
isDotStar: false
asName: productId
entityAsName: OrderProduct
propertyName: productId
- concept: QueryGroupByExpression
groupElement:
concept: QueryFieldExpression
isDotStar: false
asName: productName
entityAsName: Product
propertyName: name
havingPlayground: []
orderBy:
- concept: QueryOrderByExpression
orderElement:
concept: Identifier
namespace: inner
name: productName
order:
concept: StringLiteral
value: ASC
limit:
concept: QueryLimitExpression
pageElement:
concept: NumericLiteral
value: "1"
typeAnnotation:
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: Long
inferred: false
ruleMap: {}
pageSizeElement:
concept: NumericLiteral
value: "1000"
typeAnnotation:
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: Long
inferred: false
ruleMap: {}
ideVersion: "2.22"
对应的代码如下:
- 文本化 NASL
- Natural TS
for OrderProduct in OrderProductEntity
inner join OrderForm in OrderForm
on OrderProduct.orderId == OrderForm.id
inner join Product in Product
on OrderProduct.productId == Product.id
where OrderProduct.createdBy == '张三' && OrderProduct.createdTime > startDateTime
groupby OrderProduct.productId, Product.name
orderby productName asc
select {
orderProduct: OrderProduct,
orderForm: OrderForm,
product: Product,
totalAmount: SUM(OrderProduct.amount),
productId: OrderProduct.productId,
productName: Product.name,
}
page 1 size 1000
FROM(app.dataSources.defaultDS.entities.OrderProductEntity, OrderProduct => $
.INNER_JOIN(app.dataSources.defaultDS.entities.OrderFormEntity, OrderForm => ON(() => OrderProduct.orderId == OrderForm.id)
.INNER_JOIN(app.dataSources.defaultDS.entities.ProductEntity, Product => ON(() => OrderProduct.productId == Product.id)
.WHERE(() => OrderProduct.createdBy == '张三' && OrderProduct.createdTime > startDateTime)
.GROUP_BY(() => OrderProduct.productId, Product.name)
.ORDER_BY(() => [productName, 'ASC'])
.SELECT(() => ({
orderProduct: OrderProduct,
orderForm: OrderForm,
product: Product,
totalAmount: SUM(OrderProduct.amount),
productId: OrderProduct.productId,
productName: Product.name,
}))
.PAGINATE(() => [1, 1000]))))