mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 19:38:13 +00:00
(improvement)(Headless) fix clickhouse month date format (#948)
Co-authored-by: jolunoluo
This commit is contained in:
@@ -1,17 +1,15 @@
|
||||
package com.tencent.supersonic.common.util;
|
||||
|
||||
import static com.tencent.supersonic.common.pojo.Constants.APOSTROPHE;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.COMMA;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.DAY;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.DAY_FORMAT;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.MONTH;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.MONTH_FORMAT;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.WEEK;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.YEAR;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.tencent.supersonic.common.pojo.Constants;
|
||||
import com.tencent.supersonic.common.pojo.DateConf;
|
||||
import com.tencent.supersonic.common.pojo.ItemDateResp;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@@ -24,12 +22,14 @@ import java.util.Objects;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.APOSTROPHE;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.COMMA;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.DAY;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.DAY_FORMAT;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.MONTH;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.MONTH_FORMAT;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.WEEK;
|
||||
import static com.tencent.supersonic.common.pojo.Constants.YEAR;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -253,6 +253,11 @@ public class DateModeUtils {
|
||||
*/
|
||||
public String betweenDateStr(ItemDateResp dateDate, DateConf dateInfo) {
|
||||
if (MONTH.equalsIgnoreCase(dateInfo.getPeriod())) {
|
||||
// startDate YYYYMM
|
||||
if (!dateInfo.getStartDate().contains(Constants.MINUS)) {
|
||||
return String.format("%s >= '%s' and %s <= '%s'",
|
||||
sysDateMonthCol, dateInfo.getStartDate(), sysDateMonthCol, dateInfo.getEndDate());
|
||||
}
|
||||
LocalDate endData = LocalDate.parse(dateInfo.getEndDate(),
|
||||
DateTimeFormatter.ofPattern(DAY_FORMAT));
|
||||
LocalDate startData = LocalDate.parse(dateInfo.getStartDate(),
|
||||
|
||||
@@ -12,7 +12,7 @@ public class ClickHouseAdaptor extends DbAdaptor {
|
||||
public String getDateFormat(String dateType, String dateFormat, String column) {
|
||||
if (dateFormat.equalsIgnoreCase(Constants.DAY_FORMAT_INT)) {
|
||||
if (TimeDimensionEnum.MONTH.name().equalsIgnoreCase(dateType)) {
|
||||
return "formatDateTime(toDate(parseDateTimeBestEffort(toString(%s))),'%Y-%m')".replace("%s", column);
|
||||
return "toYYYYMM(toDate(parseDateTimeBestEffort(toString(%s))))".replace("%s", column);
|
||||
} else if (TimeDimensionEnum.WEEK.name().equalsIgnoreCase(dateType)) {
|
||||
return "toMonday(toDate(parseDateTimeBestEffort(toString(%s))))".replace("%s", column);
|
||||
} else {
|
||||
|
||||
@@ -188,6 +188,13 @@ public class DatabaseServiceImpl implements DatabaseService {
|
||||
return queryWithColumns(metaQuerySql, DatabaseConverter.convert(databaseResp));
|
||||
}
|
||||
|
||||
public SemanticQueryResp getColumns(DatabaseResp databaseResp, String db, String table) {
|
||||
DbAdaptor engineAdaptor = DbAdaptorFactory.getEngineAdaptor(databaseResp.getType());
|
||||
String metaQueryTpl = engineAdaptor.getColumnMetaQueryTpl();
|
||||
String metaQuerySql = String.format(metaQueryTpl, db, table);
|
||||
return queryWithColumns(metaQuerySql, DatabaseConverter.convert(databaseResp));
|
||||
}
|
||||
|
||||
private void checkPermission(DatabaseResp databaseResp, User user) {
|
||||
List<String> admins = databaseResp.getAdmins();
|
||||
List<String> viewers = databaseResp.getViewers();
|
||||
|
||||
Reference in New Issue
Block a user