mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 19:51:00 +00:00
[improvement][headless]Remove unnecessary Database class
This commit is contained in:
@@ -2,6 +2,7 @@ package com.tencent.supersonic.headless.api.pojo.response;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.tencent.supersonic.common.pojo.RecordInfo;
|
import com.tencent.supersonic.common.pojo.RecordInfo;
|
||||||
|
import com.tencent.supersonic.common.util.AESEncryptionUtil;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -64,4 +65,8 @@ public class DatabaseResp extends RecordInfo {
|
|||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String passwordDecrypt() {
|
||||||
|
return AESEncryptionUtil.aesDecryptECB(password);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.tencent.supersonic.headless.core.executor;
|
package com.tencent.supersonic.headless.core.executor;
|
||||||
|
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
|
import com.tencent.supersonic.headless.api.pojo.response.DatabaseResp;
|
||||||
import com.tencent.supersonic.headless.api.pojo.response.SemanticQueryResp;
|
import com.tencent.supersonic.headless.api.pojo.response.SemanticQueryResp;
|
||||||
import com.tencent.supersonic.headless.core.pojo.Database;
|
|
||||||
import com.tencent.supersonic.headless.core.pojo.QueryStatement;
|
import com.tencent.supersonic.headless.core.pojo.QueryStatement;
|
||||||
import com.tencent.supersonic.headless.core.utils.ComponentFactory;
|
import com.tencent.supersonic.headless.core.utils.ComponentFactory;
|
||||||
import com.tencent.supersonic.headless.core.utils.SqlUtils;
|
import com.tencent.supersonic.headless.core.utils.SqlUtils;
|
||||||
@@ -38,7 +38,7 @@ public class JdbcExecutor implements QueryExecutor {
|
|||||||
SqlUtils sqlUtils = ContextUtils.getBean(SqlUtils.class);
|
SqlUtils sqlUtils = ContextUtils.getBean(SqlUtils.class);
|
||||||
String sql = StringUtils.normalizeSpace(queryStatement.getSql());
|
String sql = StringUtils.normalizeSpace(queryStatement.getSql());
|
||||||
log.info("executing SQL: {}", sql);
|
log.info("executing SQL: {}", sql);
|
||||||
Database database = queryStatement.getOntology().getDatabase();
|
DatabaseResp database = queryStatement.getOntology().getDatabase();
|
||||||
SemanticQueryResp queryResultWithColumns = new SemanticQueryResp();
|
SemanticQueryResp queryResultWithColumns = new SemanticQueryResp();
|
||||||
try {
|
try {
|
||||||
SqlUtils sqlUtil = sqlUtils.init(database);
|
SqlUtils sqlUtil = sqlUtils.init(database);
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
package com.tencent.supersonic.headless.core.pojo;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.tencent.supersonic.common.pojo.RecordInfo;
|
|
||||||
import com.tencent.supersonic.common.pojo.enums.EngineType;
|
|
||||||
import com.tencent.supersonic.common.util.AESEncryptionUtil;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@Builder
|
|
||||||
public class Database extends RecordInfo {
|
|
||||||
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
private Long domainId;
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
private String version;
|
|
||||||
|
|
||||||
private String url;
|
|
||||||
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
private String database;
|
|
||||||
|
|
||||||
private String schema;
|
|
||||||
/** mysql,clickhouse */
|
|
||||||
private EngineType type;
|
|
||||||
|
|
||||||
private List<String> admins = Lists.newArrayList();
|
|
||||||
|
|
||||||
private List<String> viewers = Lists.newArrayList();
|
|
||||||
|
|
||||||
public String passwordDecrypt() {
|
|
||||||
return AESEncryptionUtil.aesDecryptECB(password);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@ package com.tencent.supersonic.headless.core.pojo;
|
|||||||
|
|
||||||
import com.alibaba.druid.pool.DruidDataSource;
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
import com.tencent.supersonic.headless.api.pojo.enums.DataType;
|
import com.tencent.supersonic.headless.api.pojo.enums.DataType;
|
||||||
|
import com.tencent.supersonic.headless.api.pojo.response.DatabaseResp;
|
||||||
import com.tencent.supersonic.headless.core.utils.JdbcDataSourceUtils;
|
import com.tencent.supersonic.headless.core.utils.JdbcDataSourceUtils;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -106,7 +107,7 @@ public class JdbcDataSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeDatasource(Database database) {
|
public void removeDatasource(DatabaseResp database) {
|
||||||
|
|
||||||
String key = getDataSourceKey(database);
|
String key = getDataSourceKey(database);
|
||||||
|
|
||||||
@@ -128,7 +129,7 @@ public class JdbcDataSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DruidDataSource getDataSource(Database database) throws RuntimeException {
|
public DruidDataSource getDataSource(DatabaseResp database) throws RuntimeException {
|
||||||
|
|
||||||
String name = database.getName();
|
String name = database.getName();
|
||||||
String jdbcUrl = database.getUrl();
|
String jdbcUrl = database.getUrl();
|
||||||
@@ -239,7 +240,7 @@ public class JdbcDataSource {
|
|||||||
return druidDataSource;
|
return druidDataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getDataSourceKey(Database database) {
|
private String getDataSourceKey(DatabaseResp database) {
|
||||||
return JdbcDataSourceUtils.getKey(database.getName(), database.getUrl(),
|
return JdbcDataSourceUtils.getKey(database.getName(), database.getUrl(),
|
||||||
database.getUsername(), database.passwordDecrypt(), "", false);
|
database.getUsername(), database.passwordDecrypt(), "", false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.tencent.supersonic.headless.core.pojo;
|
package com.tencent.supersonic.headless.core.pojo;
|
||||||
|
|
||||||
import com.tencent.supersonic.common.pojo.enums.EngineType;
|
import com.tencent.supersonic.common.pojo.enums.EngineType;
|
||||||
|
import com.tencent.supersonic.headless.api.pojo.response.DatabaseResp;
|
||||||
import com.tencent.supersonic.headless.core.translator.parser.s2sql.DataModel;
|
import com.tencent.supersonic.headless.core.translator.parser.s2sql.DataModel;
|
||||||
import com.tencent.supersonic.headless.core.translator.parser.s2sql.Dimension;
|
import com.tencent.supersonic.headless.core.translator.parser.s2sql.Dimension;
|
||||||
import com.tencent.supersonic.headless.core.translator.parser.s2sql.Materialization;
|
import com.tencent.supersonic.headless.core.translator.parser.s2sql.Materialization;
|
||||||
@@ -18,7 +19,7 @@ public class Ontology {
|
|||||||
private Map<String, List<Dimension>> dimensionMap = new HashMap<>();
|
private Map<String, List<Dimension>> dimensionMap = new HashMap<>();
|
||||||
private List<Materialization> materializationList = new ArrayList<>();
|
private List<Materialization> materializationList = new ArrayList<>();
|
||||||
private List<JoinRelation> joinRelations;
|
private List<JoinRelation> joinRelations;
|
||||||
private Database database;
|
private DatabaseResp database;
|
||||||
|
|
||||||
public List<Dimension> getDimensions() {
|
public List<Dimension> getDimensions() {
|
||||||
return dimensionMap.values().stream().flatMap(Collection::stream)
|
return dimensionMap.values().stream().flatMap(Collection::stream)
|
||||||
@@ -27,9 +28,15 @@ public class Ontology {
|
|||||||
|
|
||||||
public EngineType getDatabaseType() {
|
public EngineType getDatabaseType() {
|
||||||
if (Objects.nonNull(database)) {
|
if (Objects.nonNull(database)) {
|
||||||
return database.getType();
|
return EngineType.fromString(database.getType().toUpperCase());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDatabaseVersion() {
|
||||||
|
if (Objects.nonNull(database)) {
|
||||||
|
return database.getVersion();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import com.tencent.supersonic.common.pojo.enums.EngineType;
|
|||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
import com.tencent.supersonic.common.util.DateModeUtils;
|
import com.tencent.supersonic.common.util.DateModeUtils;
|
||||||
import com.tencent.supersonic.headless.api.pojo.enums.AggOption;
|
import com.tencent.supersonic.headless.api.pojo.enums.AggOption;
|
||||||
import com.tencent.supersonic.headless.core.pojo.Database;
|
import com.tencent.supersonic.headless.api.pojo.response.DatabaseResp;
|
||||||
import com.tencent.supersonic.headless.core.pojo.OntologyQuery;
|
import com.tencent.supersonic.headless.core.pojo.OntologyQuery;
|
||||||
import com.tencent.supersonic.headless.core.pojo.QueryStatement;
|
import com.tencent.supersonic.headless.core.pojo.QueryStatement;
|
||||||
import com.tencent.supersonic.headless.core.pojo.SqlQuery;
|
import com.tencent.supersonic.headless.core.pojo.SqlQuery;
|
||||||
@@ -60,8 +60,9 @@ public class MetricRatioParser implements QueryParser {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void parse(QueryStatement queryStatement) throws Exception {
|
public void parse(QueryStatement queryStatement) throws Exception {
|
||||||
Database database = queryStatement.getOntology().getDatabase();
|
DatabaseResp database = queryStatement.getOntology().getDatabase();
|
||||||
generateRatioSql(queryStatement, database.getType(), database.getVersion());
|
generateRatioSql(queryStatement, queryStatement.getOntology().getDatabaseType(),
|
||||||
|
database.getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Ratio */
|
/** Ratio */
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.tencent.supersonic.common.pojo.Aggregator;
|
|||||||
import com.tencent.supersonic.common.pojo.ColumnOrder;
|
import com.tencent.supersonic.common.pojo.ColumnOrder;
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
import com.tencent.supersonic.headless.api.pojo.enums.AggOption;
|
import com.tencent.supersonic.headless.api.pojo.enums.AggOption;
|
||||||
import com.tencent.supersonic.headless.core.pojo.Database;
|
|
||||||
import com.tencent.supersonic.headless.core.pojo.OntologyQuery;
|
import com.tencent.supersonic.headless.core.pojo.OntologyQuery;
|
||||||
import com.tencent.supersonic.headless.core.pojo.QueryStatement;
|
import com.tencent.supersonic.headless.core.pojo.QueryStatement;
|
||||||
import com.tencent.supersonic.headless.core.pojo.SqlQuery;
|
import com.tencent.supersonic.headless.core.pojo.SqlQuery;
|
||||||
@@ -37,8 +36,8 @@ public class StructQueryParser implements QueryParser {
|
|||||||
sqlGenerateUtils.getSelect(structQuery), dsTable,
|
sqlGenerateUtils.getSelect(structQuery), dsTable,
|
||||||
sqlGenerateUtils.getGroupBy(structQuery), sqlGenerateUtils.getOrderBy(structQuery),
|
sqlGenerateUtils.getGroupBy(structQuery), sqlGenerateUtils.getOrderBy(structQuery),
|
||||||
sqlGenerateUtils.getLimit(structQuery));
|
sqlGenerateUtils.getLimit(structQuery));
|
||||||
Database database = queryStatement.getOntology().getDatabase();
|
if (!sqlGenerateUtils.isSupportWith(queryStatement.getOntology().getDatabaseType(),
|
||||||
if (!sqlGenerateUtils.isSupportWith(database.getType(), database.getVersion())) {
|
queryStatement.getOntology().getDatabaseVersion())) {
|
||||||
sqlParam.setSupportWith(false);
|
sqlParam.setSupportWith(false);
|
||||||
sql = String.format("select %s from %s t0 %s %s %s",
|
sql = String.format("select %s from %s t0 %s %s %s",
|
||||||
sqlGenerateUtils.getSelect(structQuery), dsTable,
|
sqlGenerateUtils.getSelect(structQuery), dsTable,
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class SchemaBuilder {
|
|||||||
Prepare.CatalogReader catalogReader = new CalciteCatalogReader(rootSchema,
|
Prepare.CatalogReader catalogReader = new CalciteCatalogReader(rootSchema,
|
||||||
Collections.singletonList(schema.getSchemaKey()), Configuration.typeFactory,
|
Collections.singletonList(schema.getSchemaKey()), Configuration.typeFactory,
|
||||||
Configuration.config);
|
Configuration.config);
|
||||||
EngineType engineType = schema.getOntology().getDatabase().getType();
|
EngineType engineType = schema.getOntology().getDatabaseType();
|
||||||
S2SQLSqlValidatorImpl s2SQLSqlValidator =
|
S2SQLSqlValidatorImpl s2SQLSqlValidator =
|
||||||
new S2SQLSqlValidatorImpl(Configuration.operatorTable, catalogReader,
|
new S2SQLSqlValidatorImpl(Configuration.operatorTable, catalogReader,
|
||||||
Configuration.typeFactory, Configuration.getValidatorConfig(engineType));
|
Configuration.typeFactory, Configuration.getValidatorConfig(engineType));
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package com.tencent.supersonic.headless.core.translator.parser.calcite;
|
|||||||
import com.tencent.supersonic.common.calcite.Configuration;
|
import com.tencent.supersonic.common.calcite.Configuration;
|
||||||
import com.tencent.supersonic.common.pojo.enums.EngineType;
|
import com.tencent.supersonic.common.pojo.enums.EngineType;
|
||||||
import com.tencent.supersonic.headless.api.pojo.enums.AggOption;
|
import com.tencent.supersonic.headless.api.pojo.enums.AggOption;
|
||||||
import com.tencent.supersonic.headless.core.pojo.Database;
|
|
||||||
import com.tencent.supersonic.headless.core.pojo.OntologyQuery;
|
import com.tencent.supersonic.headless.core.pojo.OntologyQuery;
|
||||||
import com.tencent.supersonic.headless.core.pojo.QueryStatement;
|
import com.tencent.supersonic.headless.core.pojo.QueryStatement;
|
||||||
import com.tencent.supersonic.headless.core.translator.parser.calcite.node.DataModelNode;
|
import com.tencent.supersonic.headless.core.translator.parser.calcite.node.DataModelNode;
|
||||||
@@ -19,7 +18,10 @@ import org.apache.calcite.sql.SqlNode;
|
|||||||
import org.apache.calcite.sql.parser.SqlParser;
|
import org.apache.calcite.sql.parser.SqlParser;
|
||||||
import org.apache.calcite.sql.validate.SqlValidatorScope;
|
import org.apache.calcite.sql.validate.SqlValidatorScope;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SqlBuilder {
|
public class SqlBuilder {
|
||||||
@@ -43,9 +45,8 @@ public class SqlBuilder {
|
|||||||
this.aggOption = ontologyQuery.getAggOption();
|
this.aggOption = ontologyQuery.getAggOption();
|
||||||
|
|
||||||
buildParseNode();
|
buildParseNode();
|
||||||
Database database = queryStatement.getOntology().getDatabase();
|
optimizeParseNode(queryStatement.getOntology().getDatabaseType());
|
||||||
optimizeParseNode(database.getType());
|
return getSql(queryStatement.getOntology().getDatabaseType());
|
||||||
return getSql(database.getType());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildParseNode() throws Exception {
|
private void buildParseNode() throws Exception {
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ public class DataModelNode extends SemanticNode {
|
|||||||
public static void mergeQueryFilterDimensionMeasure(Ontology ontology, OntologyQuery queryParam,
|
public static void mergeQueryFilterDimensionMeasure(Ontology ontology, OntologyQuery queryParam,
|
||||||
Set<String> dimensions, Set<String> measures, SqlValidatorScope scope)
|
Set<String> dimensions, Set<String> measures, SqlValidatorScope scope)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
EngineType engineType = ontology.getDatabase().getType();
|
EngineType engineType = ontology.getDatabaseType();
|
||||||
if (Objects.nonNull(queryParam.getWhere()) && !queryParam.getWhere().isEmpty()) {
|
if (Objects.nonNull(queryParam.getWhere()) && !queryParam.getWhere().isEmpty()) {
|
||||||
Set<String> filterConditions = new HashSet<>();
|
Set<String> filterConditions = new HashSet<>();
|
||||||
FilterNode.getFilterField(parse(queryParam.getWhere(), scope, engineType),
|
FilterNode.getFilterField(parse(queryParam.getWhere(), scope, engineType),
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class FilterRender extends Renderer {
|
|||||||
SqlNode filterNode = null;
|
SqlNode filterNode = null;
|
||||||
List<String> queryMetrics = new ArrayList<>(metricCommand.getMetrics());
|
List<String> queryMetrics = new ArrayList<>(metricCommand.getMetrics());
|
||||||
List<String> queryDimensions = new ArrayList<>(metricCommand.getDimensions());
|
List<String> queryDimensions = new ArrayList<>(metricCommand.getDimensions());
|
||||||
EngineType engineType = schema.getOntology().getDatabase().getType();
|
EngineType engineType = schema.getOntology().getDatabaseType();
|
||||||
|
|
||||||
if (metricCommand.getWhere() != null && !metricCommand.getWhere().isEmpty()) {
|
if (metricCommand.getWhere() != null && !metricCommand.getWhere().isEmpty()) {
|
||||||
filterNode = SemanticNode.parse(metricCommand.getWhere(), scope, engineType);
|
filterNode = SemanticNode.parse(metricCommand.getWhere(), scope, engineType);
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class JoinRender extends Renderer {
|
|||||||
public void render(OntologyQuery metricCommand, List<DataModel> dataModels,
|
public void render(OntologyQuery metricCommand, List<DataModel> dataModels,
|
||||||
SqlValidatorScope scope, S2CalciteSchema schema, boolean nonAgg) throws Exception {
|
SqlValidatorScope scope, S2CalciteSchema schema, boolean nonAgg) throws Exception {
|
||||||
String queryWhere = metricCommand.getWhere();
|
String queryWhere = metricCommand.getWhere();
|
||||||
EngineType engineType = schema.getOntology().getDatabase().getType();
|
EngineType engineType = schema.getOntology().getDatabaseType();
|
||||||
Set<String> whereFields = new HashSet<>();
|
Set<String> whereFields = new HashSet<>();
|
||||||
List<String> fieldWhere = new ArrayList<>();
|
List<String> fieldWhere = new ArrayList<>();
|
||||||
if (queryWhere != null && !queryWhere.isEmpty()) {
|
if (queryWhere != null && !queryWhere.isEmpty()) {
|
||||||
@@ -147,7 +147,7 @@ public class JoinRender extends Renderer {
|
|||||||
Set<String> sourceMeasure, SqlValidatorScope scope, S2CalciteSchema schema,
|
Set<String> sourceMeasure, SqlValidatorScope scope, S2CalciteSchema schema,
|
||||||
boolean nonAgg) throws Exception {
|
boolean nonAgg) throws Exception {
|
||||||
String alias = Constants.JOIN_TABLE_PREFIX + dataModel.getName();
|
String alias = Constants.JOIN_TABLE_PREFIX + dataModel.getName();
|
||||||
EngineType engineType = schema.getOntology().getDatabase().getType();
|
EngineType engineType = schema.getOntology().getDatabaseType();
|
||||||
for (String m : reqMetrics) {
|
for (String m : reqMetrics) {
|
||||||
if (getMatchMetric(schema, sourceMeasure, m, queryMetrics)) {
|
if (getMatchMetric(schema, sourceMeasure, m, queryMetrics)) {
|
||||||
MetricNode metricNode = buildMetricNode(m, dataModel, scope, schema, nonAgg, alias);
|
MetricNode metricNode = buildMetricNode(m, dataModel, scope, schema, nonAgg, alias);
|
||||||
@@ -182,7 +182,7 @@ public class JoinRender extends Renderer {
|
|||||||
Set<String> dimension, SqlValidatorScope scope, S2CalciteSchema schema)
|
Set<String> dimension, SqlValidatorScope scope, S2CalciteSchema schema)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
String alias = Constants.JOIN_TABLE_PREFIX + dataModel.getName();
|
String alias = Constants.JOIN_TABLE_PREFIX + dataModel.getName();
|
||||||
EngineType engineType = schema.getOntology().getDatabase().getType();
|
EngineType engineType = schema.getOntology().getDatabaseType();
|
||||||
for (String d : reqDimensions) {
|
for (String d : reqDimensions) {
|
||||||
if (getMatchDimension(schema, dimension, dataModel, d, queryDimension)) {
|
if (getMatchDimension(schema, dimension, dataModel, d, queryDimension)) {
|
||||||
if (d.contains(Constants.DIMENSION_IDENTIFY)) {
|
if (d.contains(Constants.DIMENSION_IDENTIFY)) {
|
||||||
@@ -262,7 +262,7 @@ public class JoinRender extends Renderer {
|
|||||||
private SqlNode buildJoin(SqlNode left, TableView leftTable, TableView tableView,
|
private SqlNode buildJoin(SqlNode left, TableView leftTable, TableView tableView,
|
||||||
Map<String, String> before, DataModel dataModel, S2CalciteSchema schema,
|
Map<String, String> before, DataModel dataModel, S2CalciteSchema schema,
|
||||||
SqlValidatorScope scope) throws Exception {
|
SqlValidatorScope scope) throws Exception {
|
||||||
EngineType engineType = schema.getOntology().getDatabase().getType();
|
EngineType engineType = schema.getOntology().getDatabaseType();
|
||||||
SqlNode condition =
|
SqlNode condition =
|
||||||
getCondition(leftTable, tableView, dataModel, schema, scope, engineType);
|
getCondition(leftTable, tableView, dataModel, schema, scope, engineType);
|
||||||
SqlLiteral sqlLiteral = SemanticNode.getJoinSqlLiteral("");
|
SqlLiteral sqlLiteral = SemanticNode.getJoinSqlLiteral("");
|
||||||
@@ -465,7 +465,7 @@ public class JoinRender extends Renderer {
|
|||||||
endTime = zipper.getAlias() + "." + endTimeOp.get().getName();
|
endTime = zipper.getAlias() + "." + endTimeOp.get().getName();
|
||||||
dateTime = partMetric.getAlias() + "." + partTime.get().getName();
|
dateTime = partMetric.getAlias() + "." + partTime.get().getName();
|
||||||
}
|
}
|
||||||
EngineType engineType = schema.getOntology().getDatabase().getType();
|
EngineType engineType = schema.getOntology().getDatabaseType();
|
||||||
ArrayList<SqlNode> operandList =
|
ArrayList<SqlNode> operandList =
|
||||||
new ArrayList<>(Arrays.asList(SemanticNode.parse(endTime, scope, engineType),
|
new ArrayList<>(Arrays.asList(SemanticNode.parse(endTime, scope, engineType),
|
||||||
SemanticNode.parse(dateTime, scope, engineType)));
|
SemanticNode.parse(dateTime, scope, engineType)));
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class OutputRender extends Renderer {
|
|||||||
public void render(OntologyQuery metricCommand, List<DataModel> dataModels,
|
public void render(OntologyQuery metricCommand, List<DataModel> dataModels,
|
||||||
SqlValidatorScope scope, S2CalciteSchema schema, boolean nonAgg) throws Exception {
|
SqlValidatorScope scope, S2CalciteSchema schema, boolean nonAgg) throws Exception {
|
||||||
TableView selectDataSet = super.tableView;
|
TableView selectDataSet = super.tableView;
|
||||||
EngineType engineType = schema.getOntology().getDatabase().getType();
|
EngineType engineType = schema.getOntology().getDatabaseType();
|
||||||
for (String dimension : metricCommand.getDimensions()) {
|
for (String dimension : metricCommand.getDimensions()) {
|
||||||
selectDataSet.getMeasure().add(SemanticNode.parse(dimension, scope, engineType));
|
selectDataSet.getMeasure().add(SemanticNode.parse(dimension, scope, engineType));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ public class SourceRender extends Renderer {
|
|||||||
S2CalciteSchema schema, boolean nonAgg, Map<String, String> extendFields,
|
S2CalciteSchema schema, boolean nonAgg, Map<String, String> extendFields,
|
||||||
TableView dataSet, TableView output, SqlValidatorScope scope) throws Exception {
|
TableView dataSet, TableView output, SqlValidatorScope scope) throws Exception {
|
||||||
List<Dimension> dimensionList = schema.getDimensions().get(datasource.getName());
|
List<Dimension> dimensionList = schema.getDimensions().get(datasource.getName());
|
||||||
EngineType engineType = schema.getOntology().getDatabase().getType();
|
EngineType engineType = schema.getOntology().getDatabaseType();
|
||||||
boolean isAdd = false;
|
boolean isAdd = false;
|
||||||
if (!CollectionUtils.isEmpty(dimensionList)) {
|
if (!CollectionUtils.isEmpty(dimensionList)) {
|
||||||
for (Dimension dim : dimensionList) {
|
for (Dimension dim : dimensionList) {
|
||||||
@@ -185,7 +185,7 @@ public class SourceRender extends Renderer {
|
|||||||
SqlValidatorScope scope, S2CalciteSchema schema, boolean nonAgg) throws Exception {
|
SqlValidatorScope scope, S2CalciteSchema schema, boolean nonAgg) throws Exception {
|
||||||
Iterator<String> iterator = fields.iterator();
|
Iterator<String> iterator = fields.iterator();
|
||||||
List<SqlNode> whereNode = new ArrayList<>();
|
List<SqlNode> whereNode = new ArrayList<>();
|
||||||
EngineType engineType = schema.getOntology().getDatabase().getType();
|
EngineType engineType = schema.getOntology().getDatabaseType();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
String cur = iterator.next();
|
String cur = iterator.next();
|
||||||
if (queryDimensions.contains(cur) || queryMetrics.contains(cur)) {
|
if (queryDimensions.contains(cur) || queryMetrics.contains(cur)) {
|
||||||
@@ -339,7 +339,7 @@ public class SourceRender extends Renderer {
|
|||||||
String queryWhere = ontologyQuery.getWhere();
|
String queryWhere = ontologyQuery.getWhere();
|
||||||
Set<String> whereFields = new HashSet<>();
|
Set<String> whereFields = new HashSet<>();
|
||||||
List<String> fieldWhere = new ArrayList<>();
|
List<String> fieldWhere = new ArrayList<>();
|
||||||
EngineType engineType = schema.getOntology().getDatabase().getType();
|
EngineType engineType = schema.getOntology().getDatabaseType();
|
||||||
if (queryWhere != null && !queryWhere.isEmpty()) {
|
if (queryWhere != null && !queryWhere.isEmpty()) {
|
||||||
SqlNode sqlNode = SemanticNode.parse(queryWhere, scope, engineType);
|
SqlNode sqlNode = SemanticNode.parse(queryWhere, scope, engineType);
|
||||||
FilterNode.getFilterField(sqlNode, whereFields);
|
FilterNode.getFilterField(sqlNode, whereFields);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import javax.sql.DataSource;
|
|||||||
import com.alibaba.druid.util.StringUtils;
|
import com.alibaba.druid.util.StringUtils;
|
||||||
import com.tencent.supersonic.common.util.MD5Util;
|
import com.tencent.supersonic.common.util.MD5Util;
|
||||||
import com.tencent.supersonic.headless.api.pojo.enums.DataType;
|
import com.tencent.supersonic.headless.api.pojo.enums.DataType;
|
||||||
import com.tencent.supersonic.headless.core.pojo.Database;
|
import com.tencent.supersonic.headless.api.pojo.response.DatabaseResp;
|
||||||
import com.tencent.supersonic.headless.core.pojo.JdbcDataSource;
|
import com.tencent.supersonic.headless.core.pojo.JdbcDataSource;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -18,14 +18,7 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.AT_SYMBOL;
|
import static com.tencent.supersonic.common.pojo.Constants.*;
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.COLON;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.DOUBLE_SLASH;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.EMPTY;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.JDBC_PREFIX_FORMATTER;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.NEW_LINE_CHAR;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.PATTERN_JDBC_TYPE;
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.SPACE;
|
|
||||||
|
|
||||||
/** tools functions about jdbc */
|
/** tools functions about jdbc */
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -39,7 +32,7 @@ public class JdbcDataSourceUtils {
|
|||||||
this.jdbcDataSource = jdbcDataSource;
|
this.jdbcDataSource = jdbcDataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean testDatabase(Database database) {
|
public static boolean testDatabase(DatabaseResp database) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class.forName(getDriverClassName(database.getUrl()));
|
Class.forName(getDriverClassName(database.getUrl()));
|
||||||
@@ -146,11 +139,11 @@ public class JdbcDataSourceUtils {
|
|||||||
return MD5Util.getMD5(sb.toString(), true, 64);
|
return MD5Util.getMD5(sb.toString(), true, 64);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataSource getDataSource(Database database) throws RuntimeException {
|
public DataSource getDataSource(DatabaseResp database) throws RuntimeException {
|
||||||
return jdbcDataSource.getDataSource(database);
|
return jdbcDataSource.getDataSource(database);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Connection getConnection(Database database) throws RuntimeException {
|
public Connection getConnection(DatabaseResp database) throws RuntimeException {
|
||||||
Connection conn = getConnectionWithRetry(database);
|
Connection conn = getConnectionWithRetry(database);
|
||||||
if (conn == null) {
|
if (conn == null) {
|
||||||
try {
|
try {
|
||||||
@@ -166,7 +159,7 @@ public class JdbcDataSourceUtils {
|
|||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Connection getConnectionWithRetry(Database database) {
|
private Connection getConnectionWithRetry(DatabaseResp database) {
|
||||||
int rc = 1;
|
int rc = 1;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
||||||
@@ -193,7 +186,7 @@ public class JdbcDataSourceUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void releaseDataSource(Database database) {
|
public void releaseDataSource(DatabaseResp database) {
|
||||||
jdbcDataSource.removeDatasource(database);
|
jdbcDataSource.removeDatasource(database);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,10 @@ package com.tencent.supersonic.headless.core.utils;
|
|||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import com.tencent.supersonic.common.pojo.QueryColumn;
|
import com.tencent.supersonic.common.pojo.QueryColumn;
|
||||||
import com.tencent.supersonic.common.pojo.enums.EngineType;
|
|
||||||
import com.tencent.supersonic.common.util.DateUtils;
|
import com.tencent.supersonic.common.util.DateUtils;
|
||||||
import com.tencent.supersonic.headless.api.pojo.enums.DataType;
|
import com.tencent.supersonic.headless.api.pojo.enums.DataType;
|
||||||
|
import com.tencent.supersonic.headless.api.pojo.response.DatabaseResp;
|
||||||
import com.tencent.supersonic.headless.api.pojo.response.SemanticQueryResp;
|
import com.tencent.supersonic.headless.api.pojo.response.SemanticQueryResp;
|
||||||
import com.tencent.supersonic.headless.core.pojo.Database;
|
|
||||||
import com.tencent.supersonic.headless.core.pojo.JdbcDataSource;
|
import com.tencent.supersonic.headless.core.pojo.JdbcDataSource;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -24,11 +23,7 @@ import java.sql.SQLException;
|
|||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static com.tencent.supersonic.common.pojo.Constants.AT_SYMBOL;
|
import static com.tencent.supersonic.common.pojo.Constants.AT_SYMBOL;
|
||||||
|
|
||||||
@@ -38,7 +33,7 @@ import static com.tencent.supersonic.common.pojo.Constants.AT_SYMBOL;
|
|||||||
public class SqlUtils {
|
public class SqlUtils {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private Database database;
|
private DatabaseResp database;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private JdbcDataSource jdbcDataSource;
|
private JdbcDataSource jdbcDataSource;
|
||||||
@@ -57,15 +52,15 @@ public class SqlUtils {
|
|||||||
|
|
||||||
public SqlUtils() {}
|
public SqlUtils() {}
|
||||||
|
|
||||||
public SqlUtils(Database database) {
|
public SqlUtils(DatabaseResp database) {
|
||||||
this.database = database;
|
this.database = database;
|
||||||
this.dataTypeEnum = DataType.urlOf(database.getUrl());
|
this.dataTypeEnum = DataType.urlOf(database.getUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
public SqlUtils init(Database database) {
|
public SqlUtils init(DatabaseResp database) {
|
||||||
return SqlUtilsBuilder.getBuilder()
|
return SqlUtilsBuilder.getBuilder()
|
||||||
.withName(database.getId() + AT_SYMBOL + database.getName())
|
.withName(database.getId() + AT_SYMBOL + database.getName())
|
||||||
.withType(database.getType().getName()).withJdbcUrl(database.getUrl())
|
.withType(database.getType()).withJdbcUrl(database.getUrl())
|
||||||
.withUsername(database.getUsername()).withPassword(database.getPassword())
|
.withUsername(database.getUsername()).withPassword(database.getPassword())
|
||||||
.withJdbcDataSource(this.jdbcDataSource).withResultLimit(this.resultLimit)
|
.withJdbcDataSource(this.jdbcDataSource).withResultLimit(this.resultLimit)
|
||||||
.withIsQueryLogEnable(this.isQueryLogEnable).build();
|
.withIsQueryLogEnable(this.isQueryLogEnable).build();
|
||||||
@@ -225,9 +220,8 @@ public class SqlUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SqlUtils build() {
|
public SqlUtils build() {
|
||||||
Database database = Database.builder().name(this.name)
|
DatabaseResp database = DatabaseResp.builder().name(this.name).type(this.type)
|
||||||
.type(EngineType.fromString(this.type.toUpperCase())).url(this.jdbcUrl)
|
.url(this.jdbcUrl).username(this.username).password(this.password).build();
|
||||||
.username(this.username).password(this.password).build();
|
|
||||||
|
|
||||||
SqlUtils sqlUtils = new SqlUtils(database);
|
SqlUtils sqlUtils = new SqlUtils(database);
|
||||||
sqlUtils.jdbcDataSource = this.jdbcDataSource;
|
sqlUtils.jdbcDataSource = this.jdbcDataSource;
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import com.tencent.supersonic.headless.core.translator.parser.s2sql.*;
|
|||||||
import com.tencent.supersonic.headless.core.translator.parser.s2sql.Materialization.TimePartType;
|
import com.tencent.supersonic.headless.core.translator.parser.s2sql.Materialization.TimePartType;
|
||||||
import com.tencent.supersonic.headless.server.pojo.yaml.*;
|
import com.tencent.supersonic.headless.server.pojo.yaml.*;
|
||||||
import com.tencent.supersonic.headless.server.service.SchemaService;
|
import com.tencent.supersonic.headless.server.service.SchemaService;
|
||||||
import com.tencent.supersonic.headless.server.utils.DatabaseConverter;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.tuple.Triple;
|
import org.apache.commons.lang3.tuple.Triple;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -40,7 +39,7 @@ public class SemanticSchemaManager {
|
|||||||
schemaService.getSchemaYamlTpl(semanticSchemaResp, dimensionYamlTpls, dataModelYamlTpls,
|
schemaService.getSchemaYamlTpl(semanticSchemaResp, dimensionYamlTpls, dataModelYamlTpls,
|
||||||
metricYamlTpls, modelIdName);
|
metricYamlTpls, modelIdName);
|
||||||
DatabaseResp databaseResp = semanticSchemaResp.getDatabaseResp();
|
DatabaseResp databaseResp = semanticSchemaResp.getDatabaseResp();
|
||||||
ontology.setDatabase(DatabaseConverter.convert(databaseResp));
|
ontology.setDatabase(databaseResp);
|
||||||
if (!CollectionUtils.isEmpty(semanticSchemaResp.getModelRelas())) {
|
if (!CollectionUtils.isEmpty(semanticSchemaResp.getModelRelas())) {
|
||||||
ontology.setJoinRelations(
|
ontology.setJoinRelations(
|
||||||
getJoinRelation(semanticSchemaResp.getModelRelas(), modelIdName));
|
getJoinRelation(semanticSchemaResp.getModelRelas(), modelIdName));
|
||||||
|
|||||||
@@ -16,17 +16,12 @@ import com.tencent.supersonic.headless.api.pojo.response.ModelResp;
|
|||||||
import com.tencent.supersonic.headless.api.pojo.response.SemanticQueryResp;
|
import com.tencent.supersonic.headless.api.pojo.response.SemanticQueryResp;
|
||||||
import com.tencent.supersonic.headless.core.adaptor.db.DbAdaptor;
|
import com.tencent.supersonic.headless.core.adaptor.db.DbAdaptor;
|
||||||
import com.tencent.supersonic.headless.core.adaptor.db.DbAdaptorFactory;
|
import com.tencent.supersonic.headless.core.adaptor.db.DbAdaptorFactory;
|
||||||
import com.tencent.supersonic.headless.core.pojo.Database;
|
|
||||||
import com.tencent.supersonic.headless.core.utils.JdbcDataSourceUtils;
|
import com.tencent.supersonic.headless.core.utils.JdbcDataSourceUtils;
|
||||||
import com.tencent.supersonic.headless.core.utils.SqlUtils;
|
import com.tencent.supersonic.headless.core.utils.SqlUtils;
|
||||||
import com.tencent.supersonic.headless.core.utils.SqlVariableParseUtils;
|
import com.tencent.supersonic.headless.core.utils.SqlVariableParseUtils;
|
||||||
import com.tencent.supersonic.headless.server.persistence.dataobject.DatabaseDO;
|
import com.tencent.supersonic.headless.server.persistence.dataobject.DatabaseDO;
|
||||||
import com.tencent.supersonic.headless.server.persistence.mapper.DatabaseDOMapper;
|
import com.tencent.supersonic.headless.server.persistence.mapper.DatabaseDOMapper;
|
||||||
import com.tencent.supersonic.headless.server.pojo.DatabaseParameter;
|
import com.tencent.supersonic.headless.server.pojo.*;
|
||||||
import com.tencent.supersonic.headless.server.pojo.DbParameterFactory;
|
|
||||||
import com.tencent.supersonic.headless.server.pojo.DbParametersBuilder;
|
|
||||||
import com.tencent.supersonic.headless.server.pojo.DefaultParametersBuilder;
|
|
||||||
import com.tencent.supersonic.headless.server.pojo.ModelFilter;
|
|
||||||
import com.tencent.supersonic.headless.server.service.DatabaseService;
|
import com.tencent.supersonic.headless.server.service.DatabaseService;
|
||||||
import com.tencent.supersonic.headless.server.service.ModelService;
|
import com.tencent.supersonic.headless.server.service.ModelService;
|
||||||
import com.tencent.supersonic.headless.server.utils.DatabaseConverter;
|
import com.tencent.supersonic.headless.server.utils.DatabaseConverter;
|
||||||
@@ -58,7 +53,7 @@ public class DatabaseServiceImpl extends ServiceImpl<DatabaseDOMapper, DatabaseD
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean testConnect(DatabaseReq databaseReq, User user) {
|
public boolean testConnect(DatabaseReq databaseReq, User user) {
|
||||||
Database database = DatabaseConverter.convert(databaseReq);
|
DatabaseResp database = DatabaseConverter.convert(databaseReq);
|
||||||
return JdbcDataSourceUtils.testDatabase(database);
|
return JdbcDataSourceUtils.testDatabase(database);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,7 +152,7 @@ public class DatabaseServiceImpl extends ServiceImpl<DatabaseDOMapper, DatabaseD
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SemanticQueryResp executeSql(String sql, DatabaseResp databaseResp) {
|
public SemanticQueryResp executeSql(String sql, DatabaseResp databaseResp) {
|
||||||
return queryWithColumns(sql, DatabaseConverter.convert(databaseResp));
|
return queryWithColumns(sql, databaseResp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -192,7 +187,7 @@ public class DatabaseServiceImpl extends ServiceImpl<DatabaseDOMapper, DatabaseD
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SemanticQueryResp queryWithColumns(String sql, Database database) {
|
private SemanticQueryResp queryWithColumns(String sql, DatabaseResp database) {
|
||||||
SemanticQueryResp queryResultWithColumns = new SemanticQueryResp();
|
SemanticQueryResp queryResultWithColumns = new SemanticQueryResp();
|
||||||
SqlUtils sqlUtils = this.sqlUtils.init(database);
|
SqlUtils sqlUtils = this.sqlUtils.init(database);
|
||||||
log.info("query SQL: {}", sql);
|
log.info("query SQL: {}", sql);
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
package com.tencent.supersonic.headless.server.utils;
|
package com.tencent.supersonic.headless.server.utils;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.tencent.supersonic.common.pojo.enums.EngineType;
|
|
||||||
import com.tencent.supersonic.headless.api.pojo.request.DatabaseReq;
|
import com.tencent.supersonic.headless.api.pojo.request.DatabaseReq;
|
||||||
import com.tencent.supersonic.headless.api.pojo.response.DatabaseResp;
|
import com.tencent.supersonic.headless.api.pojo.response.DatabaseResp;
|
||||||
import com.tencent.supersonic.headless.core.pojo.ConnectInfo;
|
import com.tencent.supersonic.headless.core.pojo.ConnectInfo;
|
||||||
import com.tencent.supersonic.headless.core.pojo.Database;
|
|
||||||
import com.tencent.supersonic.headless.server.persistence.dataobject.DatabaseDO;
|
import com.tencent.supersonic.headless.server.persistence.dataobject.DatabaseDO;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
@@ -14,15 +12,8 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
public class DatabaseConverter {
|
public class DatabaseConverter {
|
||||||
|
|
||||||
public static Database convert(DatabaseResp databaseResp) {
|
public static DatabaseResp convert(DatabaseReq databaseReq) {
|
||||||
Database database = new Database();
|
DatabaseResp database = new DatabaseResp();
|
||||||
BeanUtils.copyProperties(databaseResp, database);
|
|
||||||
database.setType(EngineType.fromString(databaseResp.getType().toUpperCase()));
|
|
||||||
return database;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Database convert(DatabaseReq databaseReq) {
|
|
||||||
Database database = new Database();
|
|
||||||
BeanUtils.copyProperties(databaseReq, database);
|
BeanUtils.copyProperties(databaseReq, database);
|
||||||
return database;
|
return database;
|
||||||
}
|
}
|
||||||
@@ -69,8 +60,7 @@ public class DatabaseConverter {
|
|||||||
return databaseResp;
|
return databaseResp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConnectInfo getConnectInfo(DatabaseResp databaseResp) {
|
public static ConnectInfo getConnectInfo(DatabaseResp database) {
|
||||||
Database database = convert(databaseResp);
|
|
||||||
ConnectInfo connectInfo = new ConnectInfo();
|
ConnectInfo connectInfo = new ConnectInfo();
|
||||||
connectInfo.setUserName(database.getUsername());
|
connectInfo.setUserName(database.getUsername());
|
||||||
connectInfo.setPassword(database.passwordDecrypt());
|
connectInfo.setPassword(database.passwordDecrypt());
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ public class ModelConverter {
|
|||||||
dimensionReq.setSemanticType(SemanticType.CATEGORY.name());
|
dimensionReq.setSemanticType(SemanticType.CATEGORY.name());
|
||||||
}
|
}
|
||||||
dimensionReq.setModelId(modelDO.getId());
|
dimensionReq.setModelId(modelDO.getId());
|
||||||
dimensionReq.setExpr(dim.getBizName());
|
dimensionReq.setExpr(dim.getExpr());
|
||||||
dimensionReq.setType(dim.getType().name());
|
dimensionReq.setType(dim.getType().name());
|
||||||
dimensionReq
|
dimensionReq
|
||||||
.setDescription(Objects.isNull(dim.getDescription()) ? "" : dim.getDescription());
|
.setDescription(Objects.isNull(dim.getDescription()) ? "" : dim.getDescription());
|
||||||
@@ -118,11 +118,11 @@ public class ModelConverter {
|
|||||||
public static MetricReq convert(Measure measure, ModelDO modelDO) {
|
public static MetricReq convert(Measure measure, ModelDO modelDO) {
|
||||||
MetricReq metricReq = new MetricReq();
|
MetricReq metricReq = new MetricReq();
|
||||||
metricReq.setName(measure.getName());
|
metricReq.setName(measure.getName());
|
||||||
metricReq.setBizName(measure.getExpr());
|
metricReq.setBizName(measure.getBizName());
|
||||||
metricReq.setDescription(measure.getName());
|
metricReq.setDescription(measure.getName());
|
||||||
metricReq.setModelId(modelDO.getId());
|
metricReq.setModelId(modelDO.getId());
|
||||||
MetricDefineByMeasureParams exprTypeParams = new MetricDefineByMeasureParams();
|
MetricDefineByMeasureParams exprTypeParams = new MetricDefineByMeasureParams();
|
||||||
exprTypeParams.setExpr(measure.getBizName());
|
exprTypeParams.setExpr(measure.getExpr());
|
||||||
Measure measureParam = new Measure();
|
Measure measureParam = new Measure();
|
||||||
BeanMapper.mapper(measure, measureParam);
|
BeanMapper.mapper(measure, measureParam);
|
||||||
exprTypeParams.setMeasures(Lists.newArrayList(measureParam));
|
exprTypeParams.setMeasures(Lists.newArrayList(measureParam));
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class HeadlessParserServiceTest {
|
|||||||
queryStatement.setOntologyQuery(ontologyQuery);
|
queryStatement.setOntologyQuery(ontologyQuery);
|
||||||
String sql = aggBuilder.buildOntologySql(queryStatement);
|
String sql = aggBuilder.buildOntologySql(queryStatement);
|
||||||
queryStatement.setSql(sql);
|
queryStatement.setSql(sql);
|
||||||
EngineType engineType = semanticSchema.getOntology().getDatabase().getType();
|
EngineType engineType = semanticSchema.getOntology().getDatabaseType();
|
||||||
sqlParser.setSql(aggBuilder.getSql(engineType));
|
sqlParser.setSql(aggBuilder.getSql(engineType));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
sqlParser.setErrMsg(e.getMessage());
|
sqlParser.setErrMsg(e.getMessage());
|
||||||
|
|||||||
Reference in New Issue
Block a user