mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 19:18:23 +00:00
(improvement)(headless)Add expr to semantic column.
This commit is contained in:
@@ -14,11 +14,11 @@ public class ModelSchema {
|
||||
|
||||
private String description;
|
||||
|
||||
private List<ColumnSchema> columnSchemas;
|
||||
private List<SemanticColumn> semanticColumns;
|
||||
|
||||
@JsonIgnore
|
||||
public ColumnSchema getColumnByName(String columnName) {
|
||||
for (ColumnSchema fieldSchema : columnSchemas) {
|
||||
public SemanticColumn getColumnByName(String columnName) {
|
||||
for (SemanticColumn fieldSchema : semanticColumns) {
|
||||
if (fieldSchema.getColumnName().equalsIgnoreCase(columnName)) {
|
||||
return fieldSchema;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.tencent.supersonic.headless.api.pojo.enums.FieldType;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ColumnSchema {
|
||||
public class SemanticColumn {
|
||||
|
||||
private String columnName;
|
||||
|
||||
@@ -19,4 +19,6 @@ public class ColumnSchema {
|
||||
|
||||
private String name;
|
||||
|
||||
private String expr;
|
||||
|
||||
}
|
||||
@@ -75,6 +75,7 @@ public class LLMSemanticModeller implements SemanticModeller {
|
||||
if (!chatApp.isPresent() || !chatApp.get().isEnable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<DbSchema> otherDbSchema = getOtherDbSchema(dbSchema, dbSchemas);
|
||||
ModelSchemaExtractor extractor =
|
||||
AiServices.create(ModelSchemaExtractor.class, getChatModel(modelBuildReq));
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.tencent.supersonic.headless.server.modeller;
|
||||
|
||||
import com.tencent.supersonic.headless.api.pojo.ColumnSchema;
|
||||
import com.tencent.supersonic.headless.api.pojo.DBColumn;
|
||||
import com.tencent.supersonic.headless.api.pojo.DbSchema;
|
||||
import com.tencent.supersonic.headless.api.pojo.ModelSchema;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticColumn;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.ModelBuildReq;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -16,19 +16,20 @@ public class RuleSemanticModeller implements SemanticModeller {
|
||||
@Override
|
||||
public void build(DbSchema dbSchema, List<DbSchema> dbSchemas, ModelSchema modelSchema,
|
||||
ModelBuildReq modelBuildReq) {
|
||||
List<ColumnSchema> columnSchemas =
|
||||
List<SemanticColumn> semanticColumns =
|
||||
dbSchema.getDbColumns().stream().map(this::convert).collect(Collectors.toList());
|
||||
modelSchema.setColumnSchemas(columnSchemas);
|
||||
modelSchema.setSemanticColumns(semanticColumns);
|
||||
}
|
||||
|
||||
private ColumnSchema convert(DBColumn dbColumn) {
|
||||
ColumnSchema columnSchema = new ColumnSchema();
|
||||
columnSchema.setName(dbColumn.getColumnName());
|
||||
columnSchema.setColumnName(dbColumn.getColumnName());
|
||||
columnSchema.setComment(dbColumn.getComment());
|
||||
columnSchema.setDataType(dbColumn.getDataType());
|
||||
columnSchema.setFiledType(dbColumn.getFieldType());
|
||||
return columnSchema;
|
||||
private SemanticColumn convert(DBColumn dbColumn) {
|
||||
SemanticColumn semanticColumn = new SemanticColumn();
|
||||
semanticColumn.setName(dbColumn.getColumnName());
|
||||
semanticColumn.setColumnName(dbColumn.getColumnName());
|
||||
semanticColumn.setExpr(dbColumn.getColumnName());
|
||||
semanticColumn.setComment(dbColumn.getComment());
|
||||
semanticColumn.setDataType(dbColumn.getDataType());
|
||||
semanticColumn.setFiledType(dbColumn.getFieldType());
|
||||
return semanticColumn;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ import com.tencent.supersonic.headless.api.pojo.request.ModelBuildReq;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A semantic modeler builds semantic-layer schemas from database-layer schemas.
|
||||
*/
|
||||
public interface SemanticModeller {
|
||||
|
||||
void build(DbSchema dbSchema, List<DbSchema> otherDbSchema, ModelSchema modelSchema,
|
||||
|
||||
@@ -158,22 +158,23 @@ public class ModelConverter {
|
||||
modelDetail.setTableQuery(String.format("%s.%s", modelBuildReq.getDb(), tableName));
|
||||
}
|
||||
List<Field> fields = new ArrayList<>();
|
||||
for (ColumnSchema columnSchema : modelSchema.getColumnSchemas()) {
|
||||
FieldType fieldType = columnSchema.getFiledType();
|
||||
fields.add(new Field(columnSchema.getName(), columnSchema.getDataType()));
|
||||
for (SemanticColumn semanticColumn : modelSchema.getSemanticColumns()) {
|
||||
FieldType fieldType = semanticColumn.getFiledType();
|
||||
fields.add(new Field(semanticColumn.getName(), semanticColumn.getDataType()));
|
||||
|
||||
if (getIdentifyType(fieldType) != null) {
|
||||
Identify identify = new Identify(columnSchema.getName(),
|
||||
getIdentifyType(fieldType).name(), columnSchema.getColumnName(), 1);
|
||||
Identify identify = new Identify(semanticColumn.getName(),
|
||||
getIdentifyType(fieldType).name(), semanticColumn.getColumnName(), 1);
|
||||
modelDetail.getIdentifiers().add(identify);
|
||||
} else if (FieldType.measure.equals(fieldType)) {
|
||||
Measure measure = new Measure(columnSchema.getName(), columnSchema.getColumnName(),
|
||||
columnSchema.getColumnName(), columnSchema.getAgg().getOperator(), 1);
|
||||
Measure measure =
|
||||
new Measure(semanticColumn.getName(), semanticColumn.getColumnName(),
|
||||
semanticColumn.getExpr(), semanticColumn.getAgg().getOperator(), 1);
|
||||
modelDetail.getMeasures().add(measure);
|
||||
} else {
|
||||
Dimension dim = new Dimension(columnSchema.getName(), columnSchema.getColumnName(),
|
||||
columnSchema.getColumnName(),
|
||||
DimensionType.valueOf(columnSchema.getFiledType().name()), 1);
|
||||
Dimension dim = new Dimension(semanticColumn.getName(),
|
||||
semanticColumn.getColumnName(), semanticColumn.getExpr(),
|
||||
DimensionType.valueOf(semanticColumn.getFiledType().name()), 1);
|
||||
modelDetail.getDimensions().add(dim);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user