mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-13 21:17:08 +00:00
(improvement)(chat) SQL field replacement supports IN. (#1460)
This commit is contained in:
@@ -1,10 +1,5 @@
|
||||
package com.tencent.supersonic.common.jsqlparser;
|
||||
|
||||
import com.tencent.supersonic.common.util.JsonUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.jsqlparser.expression.DoubleValue;
|
||||
import net.sf.jsqlparser.expression.Expression;
|
||||
@@ -24,6 +19,11 @@ import net.sf.jsqlparser.schema.Column;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
public class FieldlValueReplaceVisitor extends ExpressionVisitorAdapter {
|
||||
|
||||
@@ -71,17 +71,13 @@ public class FieldlValueReplaceVisitor extends ExpressionVisitorAdapter {
|
||||
values.add(((StringValue) o).getValue());
|
||||
}
|
||||
});
|
||||
if (valueMap == null) {
|
||||
if (valueMap == null || CollectionUtils.isEmpty(values)) {
|
||||
return;
|
||||
}
|
||||
String value = valueMap.get(JsonUtil.toString(values));
|
||||
if (StringUtils.isBlank(value)) {
|
||||
return;
|
||||
}
|
||||
List<String> valueList = JsonUtil.toList(value, String.class);
|
||||
List<Expression> newExpressions = new ArrayList<>();
|
||||
valueList.stream().forEach(o -> {
|
||||
StringValue stringValue = new StringValue(o);
|
||||
values.stream().forEach(o -> {
|
||||
String replaceValue = valueMap.getOrDefault(o, o);
|
||||
StringValue stringValue = new StringValue(replaceValue);
|
||||
newExpressions.add(stringValue);
|
||||
});
|
||||
rightItemsList.setExpressions(newExpressions);
|
||||
|
||||
@@ -94,31 +94,6 @@ public class Parameter {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean isVisible(Map<String, String> otherParameterValues) {
|
||||
if (dependencies == null) {
|
||||
return true;
|
||||
}
|
||||
for (Dependency dependency : dependencies) {
|
||||
String dependentValue = otherParameterValues.get(dependency.getName());
|
||||
if (dependentValue == null || !dependency.getShow().getIncludesValue().contains(dependentValue)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void applyDefaultValue(Map<String, String> otherParameterValues) {
|
||||
if (dependencies == null) {
|
||||
return;
|
||||
}
|
||||
for (Dependency dependency : dependencies) {
|
||||
String dependentValue = otherParameterValues.get(dependency.getName());
|
||||
if (dependentValue != null && dependency.getSetDefaultValue().containsKey(dependentValue)) {
|
||||
this.defaultValue = dependency.getSetDefaultValue().get(dependentValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Dependency {
|
||||
private String name;
|
||||
|
||||
Reference in New Issue
Block a user