mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 12:37:55 +00:00
[improvement] supersonic adapt checkstyle (#451)
This commit is contained in:
@@ -49,7 +49,6 @@ public class QueryParser {
|
||||
return parser(metricReq);
|
||||
}
|
||||
|
||||
|
||||
public QueryStatement parser(ParseSqlReq sqlCommend) {
|
||||
log.info("parser MetricReq [{}] ", sqlCommend);
|
||||
QueryStatement queryStatement = new QueryStatement();
|
||||
@@ -121,5 +120,4 @@ public class QueryParser {
|
||||
return queryStatement;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -113,12 +113,10 @@ public class SemanticSchemaManager {
|
||||
return getMetricsByMetricYamlTpl(t);
|
||||
}
|
||||
|
||||
|
||||
public static List<Dimension> getDimensions(final List<DimensionYamlTpl> t) {
|
||||
return getDimension(t);
|
||||
}
|
||||
|
||||
|
||||
public static DataSource getDatasource(final DataModelYamlTpl d) {
|
||||
DataSource datasource = DataSource.builder().sourceId(d.getSourceId()).sqlQuery(d.getSqlQuery())
|
||||
.name(d.getName()).tableQuery(d.getTableQuery()).identifiers(getIdentify(d.getIdentifiers()))
|
||||
@@ -231,7 +229,6 @@ public class SemanticSchemaManager {
|
||||
return joinRelations;
|
||||
}
|
||||
|
||||
|
||||
public static void update(SemanticSchema schema, List<Metric> metric) throws Exception {
|
||||
if (schema != null) {
|
||||
updateMetric(metric, schema.getMetrics());
|
||||
|
||||
@@ -40,7 +40,6 @@ public class AggPlanner implements Planner {
|
||||
this.schema = schema;
|
||||
}
|
||||
|
||||
|
||||
public void parse() throws Exception {
|
||||
// find the match Datasource
|
||||
scope = SchemaBuilder.getScope(schema);
|
||||
@@ -74,7 +73,6 @@ public class AggPlanner implements Planner {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private List<DataSource> getMatchDataSource(SqlValidatorScope scope) throws Exception {
|
||||
return DataSourceNode.getMatchDataSources(scope, schema, metricReq);
|
||||
}
|
||||
@@ -93,7 +91,6 @@ public class AggPlanner implements Planner {
|
||||
return isAgg;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void explain(QueryStatement queryStatement, AggOption aggOption) throws Exception {
|
||||
this.metricReq = queryStatement.getMetricReq();
|
||||
|
||||
@@ -224,7 +224,6 @@ public class MaterializationPlanner implements Planner {
|
||||
return schema;
|
||||
}
|
||||
|
||||
|
||||
private void init() {
|
||||
viewSchema = SchemaBuilder.getMaterializationSchema();
|
||||
hepProgramBuilder = new HepProgramBuilder();
|
||||
@@ -336,5 +335,4 @@ public class MaterializationPlanner implements Planner {
|
||||
return tableNames;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ public class SchemaBuilder {
|
||||
public static final String MATERIALIZATION_SYS_FIELD_DATE = "C1";
|
||||
public static final String MATERIALIZATION_SYS_FIELD_DATA = "C2";
|
||||
|
||||
|
||||
public static SqlValidatorScope getScope(SemanticSchema schema) throws Exception {
|
||||
Map<String, RelDataType> nameToTypeMap = new HashMap<>();
|
||||
CalciteSchema rootSchema = CalciteSchema.createRootSchema(true, false);
|
||||
|
||||
@@ -84,6 +84,7 @@ public class SemanticSchema extends AbstractSchema {
|
||||
public void setMaterializationList(List<Materialization> materializationList) {
|
||||
semanticModel.setMaterializationList(materializationList);
|
||||
}
|
||||
|
||||
public List<Materialization> getMaterializationList() {
|
||||
return semanticModel.getMaterializationList();
|
||||
}
|
||||
@@ -120,9 +121,9 @@ public class SemanticSchema extends AbstractSchema {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SemanticSchema build() {
|
||||
return new SemanticSchema(rootPath, tableMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,7 +49,6 @@ public class DataSourceNode extends SemanticNode {
|
||||
return buildAs(datasource.getName(), getTable(sqlTable, scope));
|
||||
}
|
||||
|
||||
|
||||
public static SqlNode buildExtend(DataSource datasource, Set<String> exprList,
|
||||
SqlValidatorScope scope)
|
||||
throws Exception {
|
||||
|
||||
@@ -62,5 +62,4 @@ public class DimensionNode extends SemanticNode {
|
||||
return expand(dimension, scope);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ public class MeasureNode extends SemanticNode {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static SqlNode buildNonAgg(String alias, Measure measure, SqlValidatorScope scope) throws Exception {
|
||||
return buildAs(measure.getName(), getExpr(measure, alias, scope));
|
||||
}
|
||||
@@ -47,4 +46,5 @@ public class MeasureNode extends SemanticNode {
|
||||
}
|
||||
return parse(measure.getExpr(), scope);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -180,5 +180,4 @@ public abstract class SemanticNode {
|
||||
optimization.visit(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -199,7 +199,6 @@ public class JoinRender extends Renderer {
|
||||
Collectors.toSet());
|
||||
}
|
||||
|
||||
|
||||
private boolean getMatchMetric(SemanticSchema schema, Set<String> sourceMeasure, String m,
|
||||
List<String> queryMetrics) {
|
||||
Optional<Metric> metric = schema.getMetrics().stream().filter(mm -> mm.getName().equalsIgnoreCase(m))
|
||||
@@ -297,7 +296,6 @@ public class JoinRender extends Renderer {
|
||||
return matchJoinRelation;
|
||||
}
|
||||
|
||||
|
||||
private SqlNode getCondition(JoinRelation joinRelation,
|
||||
SqlValidatorScope scope) throws Exception {
|
||||
SqlNode condition = null;
|
||||
|
||||
@@ -320,5 +320,4 @@ public class SourceRender extends Renderer {
|
||||
super.tableView = joinRender.getTableView();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -93,7 +93,6 @@ public class CalculateAggConverter implements SemanticConverter {
|
||||
return sqlCommand;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean accept(QueryStructReq queryStructCmd) {
|
||||
if (queryStructCmd.getQueryType().isNativeAggQuery()) {
|
||||
@@ -131,7 +130,6 @@ public class CalculateAggConverter implements SemanticConverter {
|
||||
sqlCommend.setSupportWith(parseSqlReq.isSupportWith());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ratio
|
||||
*/
|
||||
@@ -388,7 +386,6 @@ public class CalculateAggConverter implements SemanticConverter {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getAllJoinSelect(QueryStructReq queryStructCmd, String alias) {
|
||||
String aggStr = queryStructCmd.getAggregators().stream()
|
||||
.map(f -> getSelectField(f, alias) + " as " + getSelectField(f, "")
|
||||
@@ -403,7 +400,6 @@ public class CalculateAggConverter implements SemanticConverter {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private String getGroupDimWithOutTime(QueryStructReq queryStructCmd) {
|
||||
String timeDim = getTimeDim(queryStructCmd);
|
||||
return queryStructCmd.getGroups().stream().filter(f -> !f.equalsIgnoreCase(timeDim))
|
||||
@@ -422,7 +418,6 @@ public class CalculateAggConverter implements SemanticConverter {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
private String getAllSelect(QueryStructReq queryStructCmd, String alias) {
|
||||
String aggStr = queryStructCmd.getAggregators().stream().map(f -> getSelectField(f, alias))
|
||||
.collect(Collectors.joining(","));
|
||||
|
||||
@@ -42,7 +42,6 @@ public class ParserDefaultConverter implements SemanticConverter {
|
||||
BeanUtils.copyProperties(metricReq, metricCommand);
|
||||
}
|
||||
|
||||
|
||||
public MetricReq generateSqlCommand(Catalog catalog, QueryStructReq queryStructCmd) {
|
||||
MetricReq sqlCommend = new MetricReq();
|
||||
sqlCommend.setMetrics(queryStructCmd.getMetrics());
|
||||
@@ -72,5 +71,4 @@ public class ParserDefaultConverter implements SemanticConverter {
|
||||
return sqlCommend;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ public class QueryStatement {
|
||||
private Integer status = 0;
|
||||
private List<ImmutablePair<String, String>> timeRanges;
|
||||
|
||||
|
||||
public boolean isOk() {
|
||||
this.ok = "".equals(errMsg) && !"".equals(sql);
|
||||
return ok;
|
||||
|
||||
@@ -45,7 +45,6 @@ public class QueryController {
|
||||
@Autowired
|
||||
private DownloadService downloadService;
|
||||
|
||||
|
||||
@PostMapping("/sql")
|
||||
public Object queryBySql(@RequestBody QueryS2SQLReq queryS2SQLReq,
|
||||
HttpServletRequest request,
|
||||
|
||||
@@ -128,7 +128,6 @@ public class MaterializationServiceImpl implements MaterializationService {
|
||||
throw new Exception("cant find MaterializationSource");
|
||||
}
|
||||
|
||||
|
||||
protected List<String> getMetric(MetricSchemaResp metricSchemaResp) {
|
||||
if (Objects.nonNull(metricSchemaResp.getTypeParams()) && metricSchemaResp.getTypeParams().getExpr()
|
||||
.contains(queryStructUtils.getVariablePrefix())) {
|
||||
@@ -137,4 +136,5 @@ public class MaterializationServiceImpl implements MaterializationService {
|
||||
}
|
||||
return Arrays.asList(metricSchemaResp.getBizName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ public interface QueryService {
|
||||
|
||||
QueryResultWithSchemaResp queryByMultiStruct(QueryMultiStructReq queryMultiStructCmd, User user) throws Exception;
|
||||
|
||||
|
||||
QueryResultWithSchemaResp queryDimValue(QueryDimValueReq queryDimValueReq, User user);
|
||||
|
||||
Object queryByQueryStatement(QueryStatement queryStatement);
|
||||
@@ -36,5 +35,4 @@ public interface QueryService {
|
||||
|
||||
QueryStatement parseMetricReq(MetricReq metricReq) throws Exception;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -140,7 +140,6 @@ public class QueryServiceImpl implements QueryService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@DataPermission
|
||||
@SneakyThrows
|
||||
@@ -148,7 +147,6 @@ public class QueryServiceImpl implements QueryService {
|
||||
return queryByStruct(queryStructCmd, user);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public QueryResultWithSchemaResp queryByMultiStruct(QueryMultiStructReq queryMultiStructReq, User user)
|
||||
throws Exception {
|
||||
@@ -199,7 +197,6 @@ public class QueryServiceImpl implements QueryService {
|
||||
return queryByStruct(queryStructReq, user);
|
||||
}
|
||||
|
||||
|
||||
private void handleGlobalCacheDisable(QueryStructReq queryStructCmd) {
|
||||
if (!cacheEnable) {
|
||||
Cache cacheInfo = new Cache();
|
||||
@@ -251,7 +248,6 @@ public class QueryServiceImpl implements QueryService {
|
||||
return ExplainResp.builder().sql(sql).build();
|
||||
}
|
||||
|
||||
|
||||
public QueryStatement parseMetricReq(MetricReq metricReq) throws Exception {
|
||||
QueryStructReq queryStructCmd = new QueryStructReq();
|
||||
return semanticQueryEngine.physicalSql(queryStructCmd, metricReq);
|
||||
@@ -321,5 +317,4 @@ public class QueryServiceImpl implements QueryService {
|
||||
return String.join(",", modelIds.stream().map(Object::toString).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ public class SchemaServiceImpl implements SchemaService {
|
||||
this.domainService = domainService;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<ModelSchemaResp> fetchModelSchema(ModelSchemaFilterReq filter, User user) {
|
||||
List<ModelSchemaResp> domainSchemaDescList = modelService.fetchModelSchema(filter);
|
||||
@@ -65,7 +64,6 @@ public class SchemaServiceImpl implements SchemaService {
|
||||
return domainSchemaDescList;
|
||||
}
|
||||
|
||||
|
||||
private void fillCnt(List<ModelSchemaResp> domainSchemaDescList, List<ItemUseResp> statInfos) {
|
||||
|
||||
Map<String, ItemUseResp> typeIdAndStatPair = statInfos.stream()
|
||||
|
||||
@@ -30,7 +30,6 @@ public class SemanticQueryEngineImpl implements SemanticQueryEngine {
|
||||
this.queryUtils = queryUtils;
|
||||
}
|
||||
|
||||
|
||||
public QueryResultWithSchemaResp execute(QueryStatement queryStatement) {
|
||||
QueryResultWithSchemaResp queryResultWithColumns = null;
|
||||
QueryExecutor queryExecutor = route(queryStatement);
|
||||
@@ -68,14 +67,13 @@ public class SemanticQueryEngineImpl implements SemanticQueryEngine {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public QueryStatement physicalSql(QueryStructReq queryStructCmd, ParseSqlReq sqlCommend) throws Exception {
|
||||
return optimize(queryStructCmd, queryParser.parser(sqlCommend));
|
||||
}
|
||||
|
||||
|
||||
public QueryStatement physicalSql(QueryStructReq queryStructCmd, MetricReq metricCommand) throws Exception {
|
||||
return queryParser.parser(metricCommand);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -88,5 +88,4 @@ public class ComponentFactory {
|
||||
queryExecutors.add(ContextUtils.getContext().getBean("JdbcExecutor", JdbcExecutor.class));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -133,7 +133,6 @@ public class DimValueAspect {
|
||||
filedNameToValueMap.put(fieldName, map);
|
||||
}
|
||||
|
||||
|
||||
@Around("execution(* com.tencent.supersonic.semantic.query.rest.QueryController.queryByStruct(..))"
|
||||
+ " || execution(* com.tencent.supersonic.semantic.query.service.QueryService.queryByStruct(..))"
|
||||
+ " || execution(* com.tencent.supersonic.semantic.query.service.QueryService.queryByStructWithAuth(..))")
|
||||
@@ -199,7 +198,6 @@ public class DimValueAspect {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private void rewriteFilter(List<Filter> dimensionFilters, Map<String, Map<String, String>> aliasAndTechNamePair) {
|
||||
for (Filter filter : dimensionFilters) {
|
||||
if (Objects.isNull(filter)) {
|
||||
@@ -278,7 +276,6 @@ public class DimValueAspect {
|
||||
return Objects.isNull(dimValueMap) || Strings.isEmpty(dimValueMap.getTechName());
|
||||
}
|
||||
|
||||
|
||||
private Map<String, Map<String, String>> getTechNameToBizName(List<DimensionResp> dimensions) {
|
||||
if (CollectionUtils.isEmpty(dimensions)) {
|
||||
return new HashMap<>();
|
||||
|
||||
@@ -92,7 +92,6 @@ public class QueryStructUtils {
|
||||
this.catalog = catalog;
|
||||
}
|
||||
|
||||
|
||||
private List<Long> getDimensionIds(QueryStructReq queryStructCmd) {
|
||||
List<Long> dimensionIds = new ArrayList<>();
|
||||
List<DimensionResp> dimensions = catalog.getDimensions(queryStructCmd.getModelIds());
|
||||
@@ -168,7 +167,6 @@ public class QueryStructUtils {
|
||||
return dateModeUtils.getDateWhereStr(dateInfo, dateDate);
|
||||
}
|
||||
|
||||
|
||||
public String generateWhere(QueryStructReq queryStructCmd) {
|
||||
String whereClauseFromFilter = sqlFilterUtils.getWhereClause(queryStructCmd.getOriginalFilter());
|
||||
String whereFromDate = getDateWhereClause(queryStructCmd);
|
||||
@@ -299,7 +297,6 @@ public class QueryStructUtils {
|
||||
return queryStatement.getSql();
|
||||
}
|
||||
|
||||
|
||||
public String getZipperDateWhereClause(QueryStructReq queryStructCmd) {
|
||||
List<ImmutablePair<String, String>> timeRanges = getTimeRanges(queryStructCmd);
|
||||
List<String> wheres = new ArrayList<>();
|
||||
|
||||
@@ -118,7 +118,6 @@ public class QueryUtils {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void fillItemNameInfo(QueryResultWithSchemaResp queryResultWithColumns,
|
||||
QueryMultiStructReq queryMultiStructCmd) {
|
||||
List<Aggregator> aggregators = queryMultiStructCmd.getQueryStructReqs().stream()
|
||||
@@ -205,7 +204,6 @@ public class QueryUtils {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void checkSqlParse(QueryStatement sqlParser) {
|
||||
if (com.google.common.base.Strings.isNullOrEmpty(sqlParser.getSql())
|
||||
|| com.google.common.base.Strings.isNullOrEmpty(sqlParser.getSourceId())) {
|
||||
@@ -213,7 +211,6 @@ public class QueryUtils {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public QueryStatement sqlParserUnion(QueryMultiStructReq queryMultiStructCmd, List<QueryStatement> sqlParsers) {
|
||||
QueryStatement sqlParser = new QueryStatement();
|
||||
StringBuilder unionSqlBuilder = new StringBuilder();
|
||||
|
||||
@@ -82,5 +82,4 @@ public class SqlGenerateUtils {
|
||||
.collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -85,7 +85,6 @@ public class StatUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void initStatInfo(QueryS2SQLReq queryS2SQLReq, User facadeUser) {
|
||||
QueryStat queryStatInfo = new QueryStat();
|
||||
List<String> allFields = SqlParserSelectHelper.getAllFields(queryS2SQLReq.getSql());
|
||||
@@ -119,8 +118,6 @@ public class StatUtils {
|
||||
StatUtils.set(queryStatInfo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void initStatInfo(QueryStructReq queryStructCmd, User facadeUser) {
|
||||
QueryStat queryStatInfo = new QueryStat();
|
||||
String traceId = "";
|
||||
@@ -186,4 +183,4 @@ public class StatUtils {
|
||||
public List<QueryStat> getQueryStatInfoWithoutCache(ItemUseReq itemUseCommend) {
|
||||
return statRepository.getQueryStatInfoWithoutCache(itemUseCommend);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +193,6 @@ class SemanticParserServiceTest {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static void addDepartment(SemanticSchema semanticSchema) {
|
||||
DataModelYamlTpl datasource = new DataModelYamlTpl();
|
||||
datasource.setName("user_department");
|
||||
@@ -253,4 +252,4 @@ class SemanticParserServiceTest {
|
||||
.put("user_department", SemanticSchemaManager.getDimensions(dimensionYamlTpls));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,6 @@ class DownloadServiceImplTest {
|
||||
return dimSchemaResp;
|
||||
}
|
||||
|
||||
|
||||
private MetricSchemaResp mockMetricPv() {
|
||||
return mockMetric(1L, "pv", "访问次数", Lists.newArrayList(1L, 2L));
|
||||
}
|
||||
@@ -118,4 +117,4 @@ class DownloadServiceImplTest {
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import java.util.Map;
|
||||
|
||||
class DataTransformUtilsTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testTransform() {
|
||||
List<Map<String, Object>> inputData = new ArrayList<>();
|
||||
@@ -38,4 +37,4 @@ class DataTransformUtilsTest {
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user