eldenmoon commented on code in PR #49768: URL: https://github.com/apache/doris/pull/49768#discussion_r2030810789
########## fe/fe-common/src/main/java/org/apache/doris/catalog/VariantType.java: ########## @@ -21,22 +21,105 @@ import org.apache.doris.thrift.TTypeNode; import org.apache.doris.thrift.TTypeNodeType; +import com.google.common.base.Joiner; +import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.gson.annotations.SerializedName; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Objects; + public class VariantType extends ScalarType { + private static final Logger LOG = LogManager.getLogger(VariantType.class); + @SerializedName(value = "fieldMap") + private final HashMap<String, VariantField> fieldMap = Maps.newHashMap(); + + @SerializedName(value = "fields") + private final ArrayList<VariantField> predefinedFields; + + @SerializedName(value = "variantMaxSubcolumnsCount") + private int variantMaxSubcolumnsCount; public VariantType() { super(PrimitiveType.VARIANT); + this.predefinedFields = Lists.newArrayList(); + } + + public VariantType(ArrayList<VariantField> fields) { + super(PrimitiveType.VARIANT); + Preconditions.checkNotNull(fields); + this.predefinedFields = fields; + for (VariantField predefinedField : this.predefinedFields) { + fieldMap.put(predefinedField.getPattern(), predefinedField); + } + } + + @Override + public String toSql(int depth) { + if (predefinedFields.isEmpty()) { + return "variant"; + } + if (depth >= MAX_NESTING_DEPTH) { + return "variant<...>"; + } + ArrayList<String> fieldsSql = Lists.newArrayList(); + for (VariantField f : predefinedFields) { + fieldsSql.add(f.toSql(depth + 1)); + } + return String.format("variant<%s>", Joiner.on(",").join(fieldsSql)); + } + + public ArrayList<VariantField> getPredefinedFields() { + return predefinedFields; } @Override public void toThrift(TTypeDesc container) { - // not use ScalarType's toThrift for compatibility, because VariantType is not extends ScalarType previously + // use ScalarType's toThrift for compatibility, because VariantType use ScalarType to thrift previously + if (predefinedFields.isEmpty()) { + super.toThrift(container); + return; + } TTypeNode node = new TTypeNode(); container.types.add(node); node.setType(TTypeNodeType.VARIANT); Review Comment: fixed -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org