提交 20437880 authored 作者: taojinlong's avatar taojinlong

fix: impala 时间格式化

上级 ec28949d
...@@ -92,24 +92,24 @@ public class ImpalaQueryProvider extends QueryProvider { ...@@ -92,24 +92,24 @@ public class ImpalaQueryProvider extends QueryProvider {
String fieldAlias = String.format(SQLConstants.FIELD_ALIAS_X_PREFIX, i); String fieldAlias = String.format(SQLConstants.FIELD_ALIAS_X_PREFIX, i);
String fieldName = ""; String fieldName = "";
// 处理横轴字段 // 处理横轴字段
if (f.getDeExtractType() == DeTypeConstants.DE_TIME) { if (f.getDeExtractType() == DeTypeConstants.DE_TIME) { //时间转数值
if (f.getDeType() == 2 || f.getDeType() == 3) { if (f.getDeType() == 2 || f.getDeType() == 3) {
fieldName = String.format(ImpalaConstants.UNIX_TIMESTAMP, originField) + "*1000"; fieldName = String.format(ImpalaConstants.UNIX_TIMESTAMP, originField) + "*1000";
} else { } else {
fieldName = originField; fieldName = originField;
} }
} else if (f.getDeExtractType() == DeTypeConstants.DE_STRING) { } else if (f.getDeExtractType() == DeTypeConstants.DE_STRING) { //字符串转时间
if (f.getDeType() == DeTypeConstants.DE_INT) { if (f.getDeType() == DeTypeConstants.DE_INT) {
fieldName = String.format(ImpalaConstants.CAST, originField, ImpalaConstants.DEFAULT_INT_FORMAT); fieldName = String.format(ImpalaConstants.CAST, originField, ImpalaConstants.DEFAULT_INT_FORMAT);
} else if (f.getDeType() == DeTypeConstants.DE_FLOAT) { } else if (f.getDeType() == DeTypeConstants.DE_FLOAT) {
fieldName = String.format(ImpalaConstants.CAST, originField, ImpalaConstants.DEFAULT_FLOAT_FORMAT); fieldName = String.format(ImpalaConstants.CAST, originField, ImpalaConstants.DEFAULT_FLOAT_FORMAT);
} else if (f.getDeType() == DeTypeConstants.DE_TIME) { } else if (f.getDeType() == DeTypeConstants.DE_TIME) {
fieldName = String.format(ImpalaConstants.STR_TO_DATE, originField, ImpalaConstants.DEFAULT_DATE_FORMAT); fieldName = String.format(ImpalaConstants.DATE_FORMAT, originField, ImpalaConstants.DEFAULT_DATE_FORMAT);
} else { } else {
fieldName = originField; fieldName = originField;
} }
} else { } else {
if (f.getDeType() == DeTypeConstants.DE_TIME) { if (f.getDeType() == DeTypeConstants.DE_TIME) {//数值转时间
String cast = String.format(ImpalaConstants.CAST, originField, ImpalaConstants.DEFAULT_INT_FORMAT) + "/1000"; String cast = String.format(ImpalaConstants.CAST, originField, ImpalaConstants.DEFAULT_INT_FORMAT) + "/1000";
fieldName = String.format(ImpalaConstants.FROM_UNIXTIME, cast, ImpalaConstants.DEFAULT_DATE_FORMAT); fieldName = String.format(ImpalaConstants.FROM_UNIXTIME, cast, ImpalaConstants.DEFAULT_DATE_FORMAT);
} else if (f.getDeType() == 2) { } else if (f.getDeType() == 2) {
...@@ -745,7 +745,7 @@ public class ImpalaQueryProvider extends QueryProvider { ...@@ -745,7 +745,7 @@ public class ImpalaQueryProvider extends QueryProvider {
} }
if (field.getDeType() == DeTypeConstants.DE_TIME) { if (field.getDeType() == DeTypeConstants.DE_TIME) {
if (field.getDeExtractType() == DeTypeConstants.DE_STRING || field.getDeExtractType() == 5) { if (field.getDeExtractType() == DeTypeConstants.DE_STRING || field.getDeExtractType() == 5) {
whereName = String.format(ImpalaConstants.STR_TO_DATE, originName, ImpalaConstants.DEFAULT_DATE_FORMAT); whereName = String.format(ImpalaConstants.DATE_FORMAT, originName, ImpalaConstants.DEFAULT_DATE_FORMAT);
} }
if (field.getDeExtractType() == DeTypeConstants.DE_INT || field.getDeExtractType() == 3 || field.getDeExtractType() == 4) { if (field.getDeExtractType() == DeTypeConstants.DE_INT || field.getDeExtractType() == 3 || field.getDeExtractType() == 4) {
String cast = String.format(ImpalaConstants.CAST, originName, ImpalaConstants.DEFAULT_INT_FORMAT) + "/1000"; String cast = String.format(ImpalaConstants.CAST, originName, ImpalaConstants.DEFAULT_INT_FORMAT) + "/1000";
...@@ -792,7 +792,11 @@ public class ImpalaQueryProvider extends QueryProvider { ...@@ -792,7 +792,11 @@ public class ImpalaQueryProvider extends QueryProvider {
} else if (StringUtils.containsIgnoreCase(filterItemDTO.getTerm(), "like")) { } else if (StringUtils.containsIgnoreCase(filterItemDTO.getTerm(), "like")) {
whereValue = "'%" + value + "%'"; whereValue = "'%" + value + "%'";
} else { } else {
whereValue = String.format(ImpalaConstants.WHERE_VALUE_VALUE, value); if(field.getDeExtractType() == DeTypeConstants.DE_INT || field.getDeExtractType() == DeTypeConstants.DE_FLOAT|| field.getDeExtractType() == DeTypeConstants.DE_BOOL){
whereValue = String.format(ImpalaConstants.WHERE_NUMBER_VALUE_VALUE, value);
}else {
whereValue = String.format(ImpalaConstants.WHERE_VALUE_VALUE, value);
}
} }
list.add(SQLObj.builder() list.add(SQLObj.builder()
.whereField(whereName) .whereField(whereName)
...@@ -837,7 +841,7 @@ public class ImpalaQueryProvider extends QueryProvider { ...@@ -837,7 +841,7 @@ public class ImpalaQueryProvider extends QueryProvider {
if (field.getDeType() == DeTypeConstants.DE_TIME) { if (field.getDeType() == DeTypeConstants.DE_TIME) {
if (field.getDeExtractType() == DeTypeConstants.DE_STRING || field.getDeExtractType() == 5) { if (field.getDeExtractType() == DeTypeConstants.DE_STRING || field.getDeExtractType() == 5) {
whereName = String.format(ImpalaConstants.STR_TO_DATE, originName, ImpalaConstants.DEFAULT_DATE_FORMAT); whereName = String.format(ImpalaConstants.DATE_FORMAT, originName, ImpalaConstants.DEFAULT_DATE_FORMAT);
} }
if (field.getDeExtractType() == DeTypeConstants.DE_INT || field.getDeExtractType() == 3 || field.getDeExtractType() == 4) { if (field.getDeExtractType() == DeTypeConstants.DE_INT || field.getDeExtractType() == 3 || field.getDeExtractType() == 4) {
String cast = String.format(ImpalaConstants.CAST, originName, ImpalaConstants.DEFAULT_INT_FORMAT) + "/1000"; String cast = String.format(ImpalaConstants.CAST, originName, ImpalaConstants.DEFAULT_INT_FORMAT) + "/1000";
...@@ -875,7 +879,11 @@ public class ImpalaQueryProvider extends QueryProvider { ...@@ -875,7 +879,11 @@ public class ImpalaQueryProvider extends QueryProvider {
whereValue = String.format(ImpalaConstants.WHERE_BETWEEN, value.get(0), value.get(1)); whereValue = String.format(ImpalaConstants.WHERE_BETWEEN, value.get(0), value.get(1));
} }
} else { } else {
whereValue = String.format(ImpalaConstants.WHERE_VALUE_VALUE, value.get(0)); if(field.getDeExtractType() == DeTypeConstants.DE_INT || field.getDeExtractType() == DeTypeConstants.DE_FLOAT|| field.getDeExtractType() == DeTypeConstants.DE_BOOL){
whereValue = String.format(ImpalaConstants.WHERE_NUMBER_VALUE_VALUE, value.get(0));
}else {
whereValue = String.format(ImpalaConstants.WHERE_VALUE_VALUE, value.get(0));
}
} }
list.add(SQLObj.builder() list.add(SQLObj.builder()
.whereField(whereName) .whereField(whereName)
...@@ -957,44 +965,6 @@ public class ImpalaQueryProvider extends QueryProvider { ...@@ -957,44 +965,6 @@ public class ImpalaQueryProvider extends QueryProvider {
.build(); .build();
} }
private List<SQLObj> getXWheres(ChartViewFieldDTO x, String originField, String fieldAlias) {
List<SQLObj> list = new ArrayList<>();
if (CollectionUtils.isNotEmpty(x.getFilter()) && x.getFilter().size() > 0) {
x.getFilter().forEach(f -> {
String whereName = "";
String whereTerm = transMysqlFilterTerm(f.getTerm());
String whereValue = "";
if (x.getDeType() == DeTypeConstants.DE_TIME && x.getDeExtractType() != 1) {
String cast = String.format(ImpalaConstants.CAST, originField, ImpalaConstants.DEFAULT_INT_FORMAT) + "/1000";
whereName = String.format(ImpalaConstants.FROM_UNIXTIME, cast, ImpalaConstants.DEFAULT_DATE_FORMAT);
} else {
whereName = originField;
}
if (StringUtils.equalsIgnoreCase(f.getTerm(), "null")) {
whereValue = "";
} else if (StringUtils.equalsIgnoreCase(f.getTerm(), "not_null")) {
whereValue = "";
} else if (StringUtils.equalsIgnoreCase(f.getTerm(), "empty")) {
whereValue = "''";
} else if (StringUtils.equalsIgnoreCase(f.getTerm(), "not_empty")) {
whereValue = "''";
} else if (StringUtils.containsIgnoreCase(f.getTerm(), "in")) {
whereValue = "('" + StringUtils.join(f.getValue(), "','") + "')";
} else if (StringUtils.containsIgnoreCase(f.getTerm(), "like")) {
whereValue = "'%" + f.getValue() + "%'";
} else {
whereValue = String.format(ImpalaConstants.WHERE_VALUE_VALUE, f.getValue());
}
list.add(SQLObj.builder()
.whereField(whereName)
.whereAlias(fieldAlias)
.whereTermAndValue(whereTerm + whereValue)
.build());
});
}
return list;
}
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.getOriginName(), "*")) {
...@@ -1037,7 +1007,11 @@ public class ImpalaQueryProvider extends QueryProvider { ...@@ -1037,7 +1007,11 @@ public class ImpalaQueryProvider extends QueryProvider {
} else if (StringUtils.containsIgnoreCase(f.getTerm(), "like")) { } else if (StringUtils.containsIgnoreCase(f.getTerm(), "like")) {
whereValue = "'%" + f.getValue() + "%'"; whereValue = "'%" + f.getValue() + "%'";
} else { } else {
whereValue = String.format(ImpalaConstants.WHERE_VALUE_VALUE, f.getValue()); if(y.getDeExtractType() == DeTypeConstants.DE_INT || y.getDeExtractType() == DeTypeConstants.DE_FLOAT|| y.getDeExtractType() == DeTypeConstants.DE_BOOL){
whereValue = String.format(ImpalaConstants.WHERE_NUMBER_VALUE_VALUE, f.getValue());
}else {
whereValue = String.format(ImpalaConstants.WHERE_VALUE_VALUE, f.getValue());
}
} }
list.add(SQLObj.builder() list.add(SQLObj.builder()
.whereField(fieldAlias) .whereField(fieldAlias)
......
...@@ -160,8 +160,20 @@ public class EngineService { ...@@ -160,8 +160,20 @@ public class EngineService {
engine.setType("engine_doris"); engine.setType("engine_doris");
engine.setConfiguration(jsonObject.toJSONString()); engine.setConfiguration(jsonObject.toJSONString());
setDs(engine); setDs(engine);
} else { }
List<DeEngine> deEngines = deEngineMapper.selectByExampleWithBLOBs(new DeEngineExample()); if (isClusterMode()) {
DeEngineExample engineExample = new DeEngineExample();
engineExample.createCriteria().andTypeEqualTo("engine_doris");
List<DeEngine> deEngines = deEngineMapper.selectByExampleWithBLOBs(engineExample);
if (CollectionUtils.isEmpty(deEngines)) {
throw new Exception("未设置数据引擎");
}
setDs(deEngines.get(0));
}
if (isSimpleMode()) {
DeEngineExample engineExample = new DeEngineExample();
engineExample.createCriteria().andTypeEqualTo("engine_mysql");
List<DeEngine> deEngines = deEngineMapper.selectByExampleWithBLOBs(engineExample);
if (CollectionUtils.isEmpty(deEngines)) { if (CollectionUtils.isEmpty(deEngines)) {
throw new Exception("未设置数据引擎"); throw new Exception("未设置数据引擎");
} }
......
...@@ -400,7 +400,7 @@ export default { ...@@ -400,7 +400,7 @@ export default {
allTypes: [ allTypes: [
{name: 'mysql', label: 'MySQL', type: 'jdbc', extraParams: 'characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true'}, {name: 'mysql', label: 'MySQL', type: 'jdbc', extraParams: 'characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true'},
{name: 'hive', label: 'Apache Hive', type: 'jdbc', extraParams: ''}, {name: 'hive', label: 'Apache Hive', type: 'jdbc', extraParams: ''},
{name: 'impala', label: 'Apache Impala', type: 'jdbc', extraParams: 'auth=noSasl'}, {name: 'impala', label: 'Apache Impala', type: 'jdbc', extraParams: 'AuthMech=0'},
{name: 'oracle', label: 'Oracle', type: 'jdbc'}, {name: 'oracle', label: 'Oracle', type: 'jdbc'},
{name: 'sqlServer', label: 'SQL Server', type: 'jdbc', extraParams: ''}, {name: 'sqlServer', label: 'SQL Server', type: 'jdbc', extraParams: ''},
{name: 'pg', label: 'PostgreSQL', type: 'jdbc', extraParams: ''}, {name: 'pg', label: 'PostgreSQL', type: 'jdbc', extraParams: ''},
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论