forked from github/dataease
refactor: 优化SQL逻辑
This commit is contained in:
parent
2f197e8024
commit
97c4a43c67
@ -49,24 +49,16 @@ public class SQLConstants {
|
|||||||
|
|
||||||
public static final String FIELD_DOT = "`%s`";
|
public static final String FIELD_DOT = "`%s`";
|
||||||
|
|
||||||
public static final String UNIX_TIMESTAMP = "UNIX_TIMESTAMP(%s)";
|
public static final String UNIX_TIMESTAMP = "DE_UNIX_TIMESTAMP(%s)";
|
||||||
|
|
||||||
public static final String DATE_FORMAT = "DATE_FORMAT(%s,'%s')";
|
|
||||||
|
|
||||||
public static final String DE_DATE_FORMAT = "DE_DATE_FORMAT(%s,'%s')";
|
public static final String DE_DATE_FORMAT = "DE_DATE_FORMAT(%s,'%s')";
|
||||||
|
|
||||||
public static final String CAST_DATE_FORMAT = "CAST_DATE_FORMAT(%s,'%s','%s')";
|
|
||||||
|
|
||||||
public static final String DE_CAST_DATE_FORMAT = "DE_CAST_DATE_FORMAT(%s,'%s','%s')";
|
public static final String DE_CAST_DATE_FORMAT = "DE_CAST_DATE_FORMAT(%s,'%s','%s')";
|
||||||
|
|
||||||
public static final String FROM_UNIXTIME = "FROM_UNIXTIME(%s,'%s')";
|
public static final String FROM_UNIXTIME = "DE_FROM_UNIXTIME(%s,'%s')";
|
||||||
|
|
||||||
public static final String STR_TO_DATE = "STR_TO_DATE(%s,'%s')";
|
|
||||||
|
|
||||||
public static final String DE_STR_TO_DATE = "DE_STR_TO_DATE(%s,'%s')";
|
public static final String DE_STR_TO_DATE = "DE_STR_TO_DATE(%s,'%s')";
|
||||||
|
|
||||||
public static final String GET_DATE_FORMAT = "GET_DATE_FORMAT(%s)";
|
|
||||||
|
|
||||||
public static final String CAST = "CAST(%s AS %s)";
|
public static final String CAST = "CAST(%s AS %s)";
|
||||||
|
|
||||||
public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||||
|
@ -67,10 +67,10 @@ public class Dimension2SQLObj {
|
|||||||
String format = Utils.transDateFormat(x.getDateStyle(), x.getDatePattern());
|
String format = Utils.transDateFormat(x.getDateStyle(), x.getDatePattern());
|
||||||
if (StringUtils.equalsIgnoreCase(x.getDateStyle(), "y_Q")) {
|
if (StringUtils.equalsIgnoreCase(x.getDateStyle(), "y_Q")) {
|
||||||
fieldName = String.format(format,
|
fieldName = String.format(format,
|
||||||
String.format(SQLConstants.DATE_FORMAT, originField, "yyyy"),
|
String.format(SQLConstants.DE_DATE_FORMAT, originField, "yyyy"),
|
||||||
String.format(SQLConstants.QUARTER, originField));
|
String.format(SQLConstants.QUARTER, originField));
|
||||||
} else {
|
} else {
|
||||||
fieldName = String.format(SQLConstants.CAST_DATE_FORMAT, originField,
|
fieldName = String.format(SQLConstants.DE_CAST_DATE_FORMAT, originField,
|
||||||
SQLConstants.DEFAULT_DATE_FORMAT,
|
SQLConstants.DEFAULT_DATE_FORMAT,
|
||||||
format);
|
format);
|
||||||
}
|
}
|
||||||
@ -94,13 +94,13 @@ public class Dimension2SQLObj {
|
|||||||
String from_unixtime = String.format(SQLConstants.FROM_UNIXTIME, cast, SQLConstants.DEFAULT_DATE_FORMAT);
|
String from_unixtime = String.format(SQLConstants.FROM_UNIXTIME, cast, SQLConstants.DEFAULT_DATE_FORMAT);
|
||||||
if (StringUtils.equalsIgnoreCase(x.getDateStyle(), "y_Q")) {
|
if (StringUtils.equalsIgnoreCase(x.getDateStyle(), "y_Q")) {
|
||||||
fieldName = String.format(format,
|
fieldName = String.format(format,
|
||||||
String.format(SQLConstants.DATE_FORMAT, from_unixtime, "yyyy"),
|
String.format(SQLConstants.DE_DATE_FORMAT, from_unixtime, "yyyy"),
|
||||||
String.format(SQLConstants.QUARTER, from_unixtime));
|
String.format(SQLConstants.QUARTER, from_unixtime));
|
||||||
} else {
|
} else {
|
||||||
fieldName = String.format(SQLConstants.CAST_DATE_FORMAT, from_unixtime, SQLConstants.DEFAULT_DATE_FORMAT, format);
|
fieldName = String.format(SQLConstants.DE_CAST_DATE_FORMAT, from_unixtime, SQLConstants.DEFAULT_DATE_FORMAT, format);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fieldName = String.format(SQLConstants.DATE_FORMAT, originField, format);
|
fieldName = String.format(SQLConstants.DE_DATE_FORMAT, originField, format);
|
||||||
}
|
}
|
||||||
} else if (Objects.equals(x.getDeType(), DeTypeConstants.DE_STRING) && Objects.equals(x.getDeExtractType(), DeTypeConstants.DE_STRING)) {
|
} else if (Objects.equals(x.getDeType(), DeTypeConstants.DE_STRING) && Objects.equals(x.getDeExtractType(), DeTypeConstants.DE_STRING)) {
|
||||||
fieldName = originField;
|
fieldName = originField;
|
||||||
|
@ -61,8 +61,8 @@ public class Order2SQLObj {
|
|||||||
} else if (Objects.equals(f.getDeType(), DeTypeConstants.DE_FLOAT)) {
|
} else if (Objects.equals(f.getDeType(), DeTypeConstants.DE_FLOAT)) {
|
||||||
fieldName = String.format(SQLConstants.CAST, originField, SQLConstants.DEFAULT_FLOAT_FORMAT);
|
fieldName = String.format(SQLConstants.CAST, originField, SQLConstants.DEFAULT_FLOAT_FORMAT);
|
||||||
} else if (Objects.equals(f.getDeType(), DeTypeConstants.DE_TIME)) {
|
} else if (Objects.equals(f.getDeType(), DeTypeConstants.DE_TIME)) {
|
||||||
fieldName = StringUtils.isEmpty(f.getDateFormat()) ? String.format(SQLConstants.STR_TO_DATE, originField, SQLConstants.DEFAULT_DATE_FORMAT) :
|
fieldName = StringUtils.isEmpty(f.getDateFormat()) ? String.format(SQLConstants.DE_STR_TO_DATE, originField, SQLConstants.DEFAULT_DATE_FORMAT) :
|
||||||
String.format(SQLConstants.DATE_FORMAT, String.format(SQLConstants.STR_TO_DATE, originField, f.getDateFormat()), SQLConstants.DEFAULT_DATE_FORMAT);
|
String.format(SQLConstants.DE_DATE_FORMAT, String.format(SQLConstants.DE_STR_TO_DATE, originField, f.getDateFormat()), SQLConstants.DEFAULT_DATE_FORMAT);
|
||||||
} else {
|
} else {
|
||||||
fieldName = originField;
|
fieldName = originField;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user