(improvement)(Headless) Support setting fields as foreign keys when creating data-model (#1857)

Co-authored-by: lxwcodemonkey
This commit is contained in:
LXW
2024-10-29 18:42:31 +08:00
committed by GitHub
parent 0383683ac0
commit ec6d7ba93d
7 changed files with 61 additions and 11 deletions

View File

@@ -84,14 +84,14 @@ public class SchemaElement implements Serializable {
return false;
}
Object o = extInfo.get(DimensionConstants.DIMENSION_TYPE);
DimensionType dimensionTYpe = null;
DimensionType dimensionType = null;
if (o instanceof DimensionType) {
dimensionTYpe = (DimensionType) o;
dimensionType = (DimensionType) o;
}
if (o instanceof String) {
dimensionTYpe = DimensionType.valueOf((String) o);
dimensionType = DimensionType.valueOf((String) o);
}
return DimensionType.isIdentity(dimensionTYpe);
return DimensionType.isPrimaryKey(dimensionType);
}
public String getTimeFormat() {

View File

@@ -1,7 +1,16 @@
package com.tencent.supersonic.headless.api.pojo.enums;
public enum DimensionType {
categorical, time, partition_time, identify;
categorical, time, partition_time, primary_key, foreign_key;
public static DimensionType fromIdentify(String identify) {
if (IdentifyType.foreign.name().equalsIgnoreCase(identify)) {
return DimensionType.foreign_key;
} else if (IdentifyType.primary.name().equalsIgnoreCase(identify)) {
return DimensionType.primary_key;
}
return DimensionType.categorical;
}
public static boolean isTimeDimension(String type) {
try {
@@ -19,7 +28,7 @@ public enum DimensionType {
return type == partition_time;
}
public static boolean isIdentity(DimensionType type) {
return type == identify;
public static boolean isPrimaryKey(DimensionType type) {
return type == primary_key;
}
}

View File

@@ -7,6 +7,7 @@ import com.tencent.supersonic.headless.api.pojo.Field;
import com.tencent.supersonic.headless.api.pojo.Identify;
import com.tencent.supersonic.headless.api.pojo.ModelDetail;
import com.tencent.supersonic.headless.api.pojo.SchemaItem;
import com.tencent.supersonic.headless.api.pojo.enums.IdentifyType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -95,6 +96,16 @@ public class ModelResp extends SchemaItem {
return fieldSet;
}
public IdentifyType getIdentifyType(String fieldName) {
List<Identify> identifiers = modelDetail.getIdentifiers();
for (Identify identify : identifiers) {
if (Objects.equals(identify.getFieldName(), fieldName)) {
return IdentifyType.valueOf(identify.getType());
}
}
return null;
}
@Override
public boolean equals(Object o) {
if (this == o) {