Merge pull request #11912 from dataease/pr@dev-v2@fixDS

Pr@dev v2@fix ds
This commit is contained in:
taojinlong 2024-09-02 16:46:35 +08:00 committed by GitHub
commit 73286cebfb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 0 deletions

View File

@ -66,6 +66,7 @@ public class SqlparserUtils {
}
if (select.getSelectBody() instanceof PlainSelect) {
return handlePlainSelect((PlainSelect) select.getSelectBody(), select, dsType);
} else {
StringBuilder result = new StringBuilder();
@ -84,6 +85,7 @@ public class SqlparserUtils {
handleSelectItems(plainSelect, dsType);
handleFromItems(plainSelect, dsType);
handleJoins(plainSelect, dsType);
handleHaving(plainSelect);
return handleWhere(plainSelect, statementSelect, dsType);
}
@ -175,6 +177,29 @@ public class SqlparserUtils {
}
}
private static String handleHaving(PlainSelect plainSelect) throws Exception {
Expression expr = plainSelect.getHaving();
StringBuilder stringBuilder = new StringBuilder();
BinaryExpression binaryExpression = null;
try {
binaryExpression = (BinaryExpression) expr;
} catch (Exception e) {
}
if (binaryExpression != null) {
boolean hasSubBinaryExpression = binaryExpression instanceof AndExpression || binaryExpression instanceof OrExpression;
if (!hasSubBinaryExpression && !(binaryExpression.getLeftExpression() instanceof BinaryExpression) && !(binaryExpression.getLeftExpression() instanceof InExpression) && (hasVariable(binaryExpression.getLeftExpression().toString()) || hasVariable(binaryExpression.getRightExpression().toString()))) {
stringBuilder.append(SubstitutedSql);
} else {
expr.accept(getExpressionDeParser(stringBuilder));
}
} else {
expr.accept(getExpressionDeParser(stringBuilder));
}
plainSelect.setHaving(CCJSqlParserUtil.parseCondExpression(stringBuilder.toString()));
return plainSelect.toString();
}
private static String handleWhere(PlainSelect plainSelect, Select statementSelect, String dsType) throws Exception {
Expression expr = plainSelect.getWhere();
if (expr == null) {

View File

@ -55,6 +55,7 @@ const state = reactive({
})
const schemas = ref([])
const loading = ref(false)
const dsForm = ref<FormInstance>()
const cronEdit = ref(true)
@ -502,7 +503,9 @@ const getDsSchema = () => {
if (val) {
const request = JSON.parse(JSON.stringify(form.value))
request.configuration = Base64.encode(JSON.stringify(request.configuration))
loading.value = true
getSchema(request).then(res => {
loading.value = false
schemas.value = res.data
ElMessage.success(t('commons.success'))
})
@ -722,6 +725,7 @@ defineExpose({
label-width="180px"
label-position="top"
require-asterisk-position="right"
v-loading="loading"
>
<el-form-item
:label="t('auth.datasource') + t('chart.name')"

View File

@ -361,7 +361,9 @@ const validateDS = () => {
}
const doValidateDs = request => {
dsLoading.value = true
validate(request).then(res => {
dsLoading.value = false
if (res.data.type === 'API') {
let error = 0
const status = JSON.parse(res.data.status) as Array<{ status: string; name: string }>