-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(improvement)(headless) Parse sql variable
- Loading branch information
jolunoluo
committed
Feb 26, 2024
1 parent
0beb3ce
commit f95c9c6
Showing
14 changed files
with
111 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...java/com/tencent/supersonic/headless/core/parser/converter/SqlVariableParseConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.tencent.supersonic.headless.core.parser.converter; | ||
|
||
import com.tencent.supersonic.headless.api.pojo.enums.ModelDefineType; | ||
import com.tencent.supersonic.headless.api.pojo.response.ModelResp; | ||
import com.tencent.supersonic.headless.api.pojo.response.SemanticSchemaResp; | ||
import com.tencent.supersonic.headless.core.parser.calcite.s2sql.DataSource; | ||
import com.tencent.supersonic.headless.core.pojo.QueryStatement; | ||
import com.tencent.supersonic.headless.core.utils.SqlVariableParseUtils; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.CollectionUtils; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@Slf4j | ||
@Component("SqlVariableParseConverter") | ||
public class SqlVariableParseConverter implements HeadlessConverter { | ||
|
||
@Override | ||
public boolean accept(QueryStatement queryStatement) { | ||
if (Objects.isNull(queryStatement.getQueryParam())) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public void convert(QueryStatement queryStatement) { | ||
SemanticSchemaResp semanticSchemaResp = queryStatement.getSemanticSchemaResp(); | ||
List<ModelResp> modelResps = semanticSchemaResp.getModelResps(); | ||
if (CollectionUtils.isEmpty(modelResps)) { | ||
return; | ||
} | ||
for (ModelResp modelResp : modelResps) { | ||
if (ModelDefineType.SQL_QUERY.getName() | ||
.equalsIgnoreCase(modelResp.getModelDetail().getQueryType())) { | ||
String sqlParsed = SqlVariableParseUtils.parse( | ||
modelResp.getModelDetail().getSqlQuery(), | ||
modelResp.getModelDetail().getSqlVariables(), | ||
queryStatement.getQueryParam().getParams() | ||
); | ||
DataSource dataSource = queryStatement.getSemanticModel() | ||
.getDatasourceMap().get(modelResp.getBizName()); | ||
dataSource.setSqlQuery(sqlParsed); | ||
} | ||
} | ||
} | ||
} |
4 changes: 1 addition & 3 deletions
4
headless/core/src/main/java/com/tencent/supersonic/headless/core/pojo/MetricQueryParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 2 additions & 12 deletions
14
headless/core/src/main/java/com/tencent/supersonic/headless/core/pojo/ViewQueryParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,14 @@ | ||
package com.tencent.supersonic.headless.core.pojo; | ||
|
||
import com.tencent.supersonic.headless.api.pojo.MetricTable; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
public class ViewQueryParam { | ||
|
||
private Map<String, String> variables; | ||
private String sql = ""; | ||
private List<MetricTable> tables; | ||
private boolean supportWith = true; | ||
private boolean withAlias = true; | ||
|
||
public Map<String, String> getVariables() { | ||
if (variables == null) { | ||
variables = new HashMap<>(); | ||
} | ||
return variables; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.