fix:【数据集】sql使用系统变量时,用特殊复杂界定符替换中括号

This commit is contained in:
taojinlong
2025-03-17 17:31:10 +08:00
committed by dataeaseShu
parent 1f29ce93b6
commit 8ca761937f
3 changed files with 18 additions and 14 deletions

View File

@@ -42,7 +42,7 @@ import static org.apache.calcite.sql.SqlKind.*;
public class SqlparserUtils {
public static final String regex = "\\$\\{(.*?)\\}";
public static final String regex2 = "\\[(.*?)\\]";
public static final String regex2 = "\\$f2cde\\[(.*?)\\]";
private static final String SubstitutedParams = "DATAEASE_PATAMS_BI";
private static final String SysParamsSubstitutedParams = "DeSysParams_";
private static final String SubstitutedSql = " 'DE-BI' = 'DE-BI' ";
@@ -177,7 +177,7 @@ public class SqlparserUtils {
pattern = Pattern.compile(regex2);
matcher = pattern.matcher(tmpSql);
while (matcher.find()) {
String paramId = matcher.group().substring(1, matcher.group().length() - 1);
String paramId = matcher.group().substring(7, matcher.group().length() - 1);
if(!isParams(paramId)){
continue;
}
@@ -188,15 +188,15 @@ public class SqlparserUtils {
pattern = Pattern.compile(regex2);
matcher = pattern.matcher(tmpSql);
while (matcher.find()) {
String paramId = matcher.group().substring(1, matcher.group().length() - 1);
String paramId = matcher.group().substring(7, matcher.group().length() - 1);
if(!isParams(paramId)){
continue;
}
hasVariables = true;
tmpSql = tmpSql.replace(matcher.group(), SysParamsSubstitutedParams + matcher.group().substring(1, matcher.group().length() - 1));
tmpSql = tmpSql.replace(matcher.group(), SysParamsSubstitutedParams + matcher.group().substring(7, matcher.group().length() - 1));
Map<String, String> sysParam = new HashMap<>();
sysParam.put("origin", matcher.group());
sysParam.put("replace", SysParamsSubstitutedParams + matcher.group().substring(1, matcher.group().length() - 1));
sysParam.put("replace", SysParamsSubstitutedParams + matcher.group().substring(7, matcher.group().length() - 1));
sysParams.add(sysParam);
}
}

View File

@@ -209,18 +209,18 @@ const setNameIdTrans = (from, to, originName, name2Auto?: string[]) => {
pre[next[from]] = next[to]
return pre
}, {})
const on = originName.match(/\[(.+?)\]/g)
const on = originName.match(/\$f2cde\[(.+?)\]/g)
if (on) {
on.forEach(itm => {
const ele = itm.slice(1, -1)
const ele = itm.slice(7, -1)
if (name2Auto) {
name2Auto.push(nameIdMap[ele])
}
if (from === 'id' && ids.includes(ele)) {
name2Id = name2Id.replace(`[${ele}]`, `[${nameIdMap[ele]}]`)
name2Id = name2Id.replace(`$f2cde[${ele}]`, `$f2cde[${nameIdMap[ele]}]`)
}
if (from === 'name' && names.includes(ele)) {
name2Id = name2Id.replace(`[${ele}]`, `[${nameIdMap[ele]}]`)
name2Id = name2Id.replace(`$f2cde[${ele}]`, `$f2cde[${nameIdMap[ele]}]`)
}
})
}
@@ -785,6 +785,7 @@ const mousedownDrag = () => {
@change="changeFlagCode = true"
:height="`${dragHeight}px`"
dom-id="sql-editor"
:regexp="/\$f2cde\[(.*?)\]/g"
ref="myCm"
:quotaMap="fieldFormList.filter(ele => ['num'].includes(ele.type)).map(ele => ele.name)"
:dimensionMap="
@@ -912,7 +913,7 @@ const mousedownDrag = () => {
</div>
<div
class="variable-item flex-align-center"
@click="insertFieldToCodeMirror(`[${fieldForm.name}]`)"
@click="insertFieldToCodeMirror(`$f2cde[${fieldForm.name}]`)"
v-for="fieldForm in builtInList"
:key="fieldForm.id"
>
@@ -925,7 +926,7 @@ const mousedownDrag = () => {
class="variable-item flex-align-center"
v-for="fieldForm in fieldFormListComputed"
:key="fieldForm.id"
@click="insertFieldToCodeMirror(`[${fieldForm.name}]`)"
@click="insertFieldToCodeMirror(`$f2cde[${fieldForm.name}]`)"
:class="['num'].includes(fieldForm.type) && 'with-type'"
>
<el-icon>

View File

@@ -16,9 +16,12 @@ const props = defineProps({
domId: propTypes.string.def('editor'),
height: propTypes.string.def('250px'),
quotaMap: propTypes.arrayOf(String).def(() => []),
dimensionMap: propTypes.arrayOf(String).def(() => [])
dimensionMap: propTypes.arrayOf(String).def(() => []),
regexp: {
type: RegExp,
default: /\[(.*?)\]/g
}
})
const emits = defineEmits(['change'])
const codeComInit = (doc: string, sqlMode?: boolean) => {
@@ -45,7 +48,7 @@ const codeComInit = (doc: string, sqlMode?: boolean) => {
} //!placeholderMatcher
const placeholderMatcher = new MatchDecorator({
regexp: /\[(.*?)\]/g,
regexp: new RegExp(props.regexp),
decoration: match =>
Decoration.replace({
widget: new PlaceholderWidget(match[1])