Merge pull request #395 from dataease/pr@dev@fix_底层sql逻辑

fix: 底层sql逻辑
This commit is contained in:
XiaJunjie2020 2021-07-28 21:47:41 +08:00 committed by GitHub
commit 94bd4406a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 5 deletions

View File

@ -129,7 +129,7 @@ public class DorisQueryProvider extends QueryProvider {
}
STGroup stg = new STGroupFile(SQLConstants.SQL_TEMPLATE);
ST st_sql = stg.getInstanceOf("querySql");
ST st_sql = stg.getInstanceOf("previewSql");
st_sql.add("isGroup", isGroup);
if (CollectionUtils.isNotEmpty(xFields)) st_sql.add("groups", xFields);
if (ObjectUtils.isNotEmpty(tableObj)) st_sql.add("table", tableObj);

View File

@ -127,7 +127,7 @@ public class MysqlQueryProvider extends QueryProvider {
}
STGroup stg = new STGroupFile(SQLConstants.SQL_TEMPLATE);
ST st_sql = stg.getInstanceOf("querySql");
ST st_sql = stg.getInstanceOf("previewSql");
st_sql.add("isGroup", isGroup);
if (CollectionUtils.isNotEmpty(xFields)) st_sql.add("groups", xFields);
if (ObjectUtils.isNotEmpty(tableObj)) st_sql.add("table", tableObj);

View File

@ -101,7 +101,7 @@ public class OracleQueryProvider extends QueryProvider {
List<SQLObj> xFields = xFields(table, fields);
STGroup stg = new STGroupFile(SQLConstants.SQL_TEMPLATE);
ST st_sql = stg.getInstanceOf("querySql");
ST st_sql = stg.getInstanceOf("previewSql");
st_sql.add("isGroup", isGroup);
if (CollectionUtils.isNotEmpty(xFields)) st_sql.add("groups", xFields);
if (ObjectUtils.isNotEmpty(tableObj)) st_sql.add("table", tableObj);

View File

@ -1,4 +1,34 @@
querySql(groups, aggregators, filters, orders, table, isGroup)
querySql(groups, aggregators, filters, orders, table)
::=<<
SELECT
<if(!groups && !aggregators)>
*
<endif>
<if(groups)>
<groups:{group|<if(group)><group.fieldName> AS <group.fieldAlias><endif>}; separator=",\n">
<endif>
<if(groups && aggregators)>,<endif>
<if(aggregators)>
<aggregators:{agg|<if(agg)><agg.fieldName> AS <agg.fieldAlias><endif>}; separator=",\n">
<endif>
FROM
<table.tableName> <table.tableAlias>
<if(filters)>
WHERE
<filters:{filter|<if(filter)><filter.whereField> <filter.whereTermAndValue><endif>}; separator="\nAND ">
<endif>
<if(groups)>
GROUP BY
<groups:{group|<if(group)><group.fieldName><endif>}; separator=",\n">
<endif>
<if(orders)>
ORDER BY
<orders:{order|<if(order)><order.orderAlias> <order.orderDirection><endif>}; separator=",\n">
<endif>
>>
previewSql(groups, aggregators, filters, orders, table, isGroup)
::=<<
SELECT
<if(!groups && !aggregators)>
@ -25,4 +55,4 @@ GROUP BY
ORDER BY
<orders:{order|<if(order)><order.orderAlias> <order.orderDirection><endif>}; separator=",\n">
<endif>
>>
>>