mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-14 13:47:09 +00:00
(improvement) Move out the datasource and merge the datasource with the model, and adapt the chat module (#423)
Co-authored-by: jolunoluo <jolunoluo@tencent.com>
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.tencent.supersonic.common.pojo;
|
||||
|
||||
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class JoinCondition {
|
||||
|
||||
private String leftField;
|
||||
|
||||
private String rightField;
|
||||
|
||||
private FilterOperatorEnum operator;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.tencent.supersonic.common.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Data
|
||||
public class ModelCluster {
|
||||
|
||||
private static final String split = "_";
|
||||
|
||||
private Set<Long> modelIds = new LinkedHashSet<>();
|
||||
|
||||
private String key;
|
||||
|
||||
private String name;
|
||||
|
||||
public static ModelCluster build(Set<Long> modelIds) {
|
||||
ModelCluster modelCluster = new ModelCluster();
|
||||
modelCluster.setModelIds(modelIds);
|
||||
modelCluster.setKey(StringUtils.join(modelIds, split));
|
||||
return modelCluster;
|
||||
}
|
||||
|
||||
public static ModelCluster build(String key) {
|
||||
ModelCluster modelCluster = new ModelCluster();
|
||||
modelCluster.setModelIds(getModelIdFromKey(key));
|
||||
modelCluster.setKey(key);
|
||||
return modelCluster;
|
||||
}
|
||||
|
||||
public void buildName(Map<Long, String> modelNameMap) {
|
||||
name = modelNameMap.entrySet().stream().filter(entry ->
|
||||
modelIds.contains(entry.getKey())).map(Map.Entry::getValue)
|
||||
.collect(Collectors.joining(split));
|
||||
}
|
||||
|
||||
public static Set<Long> getModelIdFromKey(String key) {
|
||||
return Arrays.stream(key.split(split))
|
||||
.map(Long::parseLong).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public Long getFirstModel() {
|
||||
return modelIds.stream().findFirst().orElse(null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.tencent.supersonic.common.pojo;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ModelRela extends RecordInfo {
|
||||
|
||||
private Long id;
|
||||
|
||||
private Long domainId;
|
||||
|
||||
private Long fromModelId;
|
||||
|
||||
private Long toModelId;
|
||||
|
||||
//left join, inner join, right join, outer join
|
||||
private String joinType;
|
||||
|
||||
private List<JoinCondition> joinConditions;
|
||||
|
||||
}
|
||||
@@ -42,4 +42,11 @@ public enum FilterOperatorEnum {
|
||||
}
|
||||
|
||||
|
||||
public static boolean isValueCompare(FilterOperatorEnum filterOperatorEnum) {
|
||||
return EQUALS.equals(filterOperatorEnum) || GREATER_THAN.equals(filterOperatorEnum)
|
||||
|| GREATER_THAN_EQUALS.equals(filterOperatorEnum) || MINOR_THAN.equals(filterOperatorEnum)
|
||||
|| MINOR_THAN_EQUALS.equals(filterOperatorEnum) || NOT_EQUALS.equals(filterOperatorEnum);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
package com.tencent.supersonic.common.util.jsqlparser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.jsqlparser.JSQLParserException;
|
||||
import net.sf.jsqlparser.expression.Expression;
|
||||
@@ -35,6 +29,13 @@ import net.sf.jsqlparser.statement.select.SubSelect;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Sql Parser Select Helper
|
||||
*/
|
||||
@@ -111,7 +112,7 @@ public class SqlParserSelectHelper {
|
||||
try {
|
||||
statement = CCJSqlParserUtil.parse(sql);
|
||||
} catch (JSQLParserException e) {
|
||||
log.error("parse error", e);
|
||||
log.error("parse error, sql:{}", sql, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user