Skip to main content
Version: 3.6

CallQueryComponent 数据查询

1. 结构声明

class CallQueryComponent extends LogicItem {
typeAnnotation?: TypeAnnotation;
select: QuerySelectExpression;
from: QueryFromExpression;
where: LogicItem;
wherePlayground: Array<LogicItem>;
groupBy: Array<QueryGroupByExpression>;
having?: LogicItem;
havingPlayground: Array<LogicItem>;
orderBy: Array<QueryOrderByExpression>;
limit: QueryLimitExpression;
ideVersion: string;
}

2. 节点示例

(1) 示例

AST 如下:

{
"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"
}

对应的代码如下:

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