Merge pull request #209 from dataease/pr@dev@refactor_SQL拼接

refactor: 底层SQL拼接
This commit is contained in:
XiaJunjie2020 2021-07-12 15:14:17 +08:00 committed by GitHub
commit c4720e8986
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -90,7 +90,7 @@ public class DorisQueryProvider extends QueryProvider {
if (CollectionUtils.isNotEmpty(fields)) { if (CollectionUtils.isNotEmpty(fields)) {
for (int i = 0; i < fields.size(); i++) { for (int i = 0; i < fields.size(); i++) {
DatasetTableField f = fields.get(i); DatasetTableField f = fields.get(i);
String originField = String.format(DorisConstants.KEYWORD_FIX, tableObj.getTableAlias(), f.getOriginName()); String originField = String.format(DorisConstants.KEYWORD_FIX, tableObj.getTableAlias(), f.getDataeaseName());
String fieldAlias = String.format(SQLConstants.FIELD_ALIAS_X_PREFIX, i); String fieldAlias = String.format(SQLConstants.FIELD_ALIAS_X_PREFIX, i);
String fieldName = ""; String fieldName = "";
// 处理横轴字段 // 处理横轴字段
@ -177,7 +177,7 @@ public class DorisQueryProvider extends QueryProvider {
if (CollectionUtils.isNotEmpty(xAxis)) { if (CollectionUtils.isNotEmpty(xAxis)) {
for (int i = 0; i < xAxis.size(); i++) { for (int i = 0; i < xAxis.size(); i++) {
ChartViewFieldDTO x = xAxis.get(i); ChartViewFieldDTO x = xAxis.get(i);
String originField = String.format(DorisConstants.KEYWORD_FIX, tableObj.getTableAlias(), x.getOriginName()); String originField = String.format(DorisConstants.KEYWORD_FIX, tableObj.getTableAlias(), x.getDataeaseName());
String fieldAlias = String.format(SQLConstants.FIELD_ALIAS_X_PREFIX, i); String fieldAlias = String.format(SQLConstants.FIELD_ALIAS_X_PREFIX, i);
// 处理横轴字段 // 处理横轴字段
xFields.add(getXFields(x, originField, fieldAlias)); xFields.add(getXFields(x, originField, fieldAlias));
@ -199,7 +199,7 @@ public class DorisQueryProvider extends QueryProvider {
if (CollectionUtils.isNotEmpty(yAxis)) { if (CollectionUtils.isNotEmpty(yAxis)) {
for (int i = 0; i < yAxis.size(); i++) { for (int i = 0; i < yAxis.size(); i++) {
ChartViewFieldDTO y = yAxis.get(i); ChartViewFieldDTO y = yAxis.get(i);
String originField = String.format(DorisConstants.KEYWORD_FIX, tableObj.getTableAlias(), y.getOriginName()); String originField = String.format(DorisConstants.KEYWORD_FIX, tableObj.getTableAlias(), y.getDataeaseName());
String fieldAlias = String.format(SQLConstants.FIELD_ALIAS_Y_PREFIX, i); String fieldAlias = String.format(SQLConstants.FIELD_ALIAS_Y_PREFIX, i);
// 处理纵轴字段 // 处理纵轴字段
yFields.add(getYFields(y, originField, fieldAlias)); yFields.add(getYFields(y, originField, fieldAlias));
@ -278,7 +278,7 @@ public class DorisQueryProvider extends QueryProvider {
if (CollectionUtils.isNotEmpty(yAxis)) { if (CollectionUtils.isNotEmpty(yAxis)) {
for (int i = 0; i < yAxis.size(); i++) { for (int i = 0; i < yAxis.size(); i++) {
ChartViewFieldDTO y = yAxis.get(i); ChartViewFieldDTO y = yAxis.get(i);
String originField = String.format(DorisConstants.KEYWORD_FIX, tableObj.getTableAlias(), y.getOriginName()); String originField = String.format(DorisConstants.KEYWORD_FIX, tableObj.getTableAlias(), y.getDataeaseName());
String fieldAlias = String.format(SQLConstants.FIELD_ALIAS_Y_PREFIX, i); String fieldAlias = String.format(SQLConstants.FIELD_ALIAS_Y_PREFIX, i);
// 处理纵轴字段 // 处理纵轴字段
yFields.add(getYFields(y, originField, fieldAlias)); yFields.add(getYFields(y, originField, fieldAlias));
@ -348,7 +348,7 @@ public class DorisQueryProvider extends QueryProvider {
public String createRawQuerySQL(String table, List<DatasetTableField> fields) { public String createRawQuerySQL(String table, List<DatasetTableField> fields) {
String[] array = fields.stream().map(f -> { String[] array = fields.stream().map(f -> {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("`").append(f.getOriginName()).append("` AS ").append(f.getDataeaseName()); stringBuilder.append("`").append(f.getDataeaseName()).append("` AS ").append(f.getDataeaseName());
return stringBuilder.toString(); return stringBuilder.toString();
}).toArray(String[]::new); }).toArray(String[]::new);
return MessageFormat.format("SELECT {0} FROM {1} ORDER BY null", StringUtils.join(array, ","), table); return MessageFormat.format("SELECT {0} FROM {1} ORDER BY null", StringUtils.join(array, ","), table);
@ -413,7 +413,7 @@ public class DorisQueryProvider extends QueryProvider {
String whereName = ""; String whereName = "";
String whereTerm = transMysqlFilterTerm(request.getTerm()); String whereTerm = transMysqlFilterTerm(request.getTerm());
String whereValue = ""; String whereValue = "";
String originName = String.format(DorisConstants.KEYWORD_FIX, tableObj.getTableAlias(), field.getOriginName()); String originName = String.format(DorisConstants.KEYWORD_FIX, tableObj.getTableAlias(), field.getDataeaseName());
if (field.getDeType() == 1 && field.getDeExtractType() != 1) { if (field.getDeType() == 1 && field.getDeExtractType() != 1) {
String cast = String.format(DorisConstants.CAST, originName, DorisConstants.DEFAULT_INT_FORMAT) + "/1000"; String cast = String.format(DorisConstants.CAST, originName, DorisConstants.DEFAULT_INT_FORMAT) + "/1000";
whereName = String.format(DorisConstants.FROM_UNIXTIME, cast, DorisConstants.DEFAULT_DATE_FORMAT); whereName = String.format(DorisConstants.FROM_UNIXTIME, cast, DorisConstants.DEFAULT_DATE_FORMAT);
@ -451,7 +451,7 @@ public class DorisQueryProvider extends QueryProvider {
String whereName = ""; String whereName = "";
String whereTerm = transMysqlFilterTerm(request.getOperator()); String whereTerm = transMysqlFilterTerm(request.getOperator());
String whereValue = ""; String whereValue = "";
String originName = String.format(DorisConstants.KEYWORD_FIX, tableObj.getTableAlias(), field.getOriginName()); String originName = String.format(DorisConstants.KEYWORD_FIX, tableObj.getTableAlias(), field.getDataeaseName());
if (field.getDeType() == 1 && field.getDeExtractType() != 1) { if (field.getDeType() == 1 && field.getDeExtractType() != 1) {
String cast = String.format(DorisConstants.CAST, originName, DorisConstants.DEFAULT_INT_FORMAT) + "/1000"; String cast = String.format(DorisConstants.CAST, originName, DorisConstants.DEFAULT_INT_FORMAT) + "/1000";
@ -572,7 +572,7 @@ public class DorisQueryProvider extends QueryProvider {
private SQLObj getYFields(ChartViewFieldDTO y, String originField, String fieldAlias) { private SQLObj getYFields(ChartViewFieldDTO y, String originField, String fieldAlias) {
String fieldName = ""; String fieldName = "";
if (StringUtils.equalsIgnoreCase(y.getOriginName(), "*")) { if (StringUtils.equalsIgnoreCase(y.getDataeaseName(), "*")) {
fieldName = DorisConstants.AGG_COUNT; fieldName = DorisConstants.AGG_COUNT;
} else if (SQLConstants.DIMENSION_TYPE.contains(y.getDeType())) { } else if (SQLConstants.DIMENSION_TYPE.contains(y.getDeType())) {
fieldName = String.format(DorisConstants.AGG_FIELD, y.getSummary(), originField); fieldName = String.format(DorisConstants.AGG_FIELD, y.getSummary(), originField);