forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
415 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
fe/fe-common/src/main/java/org/apache/doris/catalog/ComplexVariantType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.apache.doris.catalog; | ||
|
||
|
||
import org.apache.doris.thrift.TTypeDesc; | ||
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 java.util.ArrayList; | ||
import java.util.HashMap; | ||
|
||
public class ComplexVariantType extends Type { | ||
|
||
@SerializedName(value = "fieldMap") | ||
private final HashMap<String, StructField> fieldMap = Maps.newHashMap(); | ||
|
||
@SerializedName(value = "fields") | ||
private final ArrayList<StructField> predefinedFields; | ||
|
||
public ComplexVariantType() { | ||
this.predefinedFields = Lists.newArrayList(); | ||
} | ||
|
||
public ComplexVariantType(ArrayList<StructField> fields) { | ||
Preconditions.checkNotNull(fields); | ||
this.predefinedFields = fields; | ||
for (int i = 0; i < this.predefinedFields.size(); ++i) { | ||
this.predefinedFields.get(i).setPosition(i); | ||
fieldMap.put(this.predefinedFields.get(i).getName(), this.predefinedFields.get(i)); | ||
} | ||
} | ||
|
||
public ArrayList<StructField> getPredefinedFields() { | ||
return predefinedFields; | ||
} | ||
|
||
@Override | ||
protected String toSql(int depth) { | ||
if (depth >= MAX_NESTING_DEPTH) { | ||
return "variant<...>"; | ||
} | ||
ArrayList<String> fieldsSql = Lists.newArrayList(); | ||
for (StructField f : predefinedFields) { | ||
fieldsSql.add(f.toSql(depth + 1)); | ||
} | ||
return String.format("variant<%s>", Joiner.on(",").join(fieldsSql)); | ||
} | ||
|
||
@Override | ||
protected String prettyPrint(int lpad) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void toThrift(TTypeDesc container) { | ||
// not use ScalarType's toThrift for compatibility, because VariantType is not extends ScalarType previously | ||
TTypeNode node = new TTypeNode(); | ||
container.types.add(node); | ||
node.setType(TTypeNodeType.VARIANT); | ||
// predefined fields | ||
node.setStructFields(new ArrayList<>()); | ||
for (StructField field : predefinedFields) { | ||
field.toThrift(container, node); | ||
} | ||
} | ||
|
||
@Override | ||
public PrimitiveType getPrimitiveType() { | ||
return PrimitiveType.VARIANT; | ||
} | ||
|
||
|
||
@Override | ||
public boolean matchesType(Type t) { | ||
return t.isVariantType() || t.isStringType(); | ||
} | ||
|
||
@Override | ||
public boolean supportSubType(Type subType) { | ||
for (Type supportedType : Type.getComplexVariantSubTypes()) { | ||
if (subType.getPrimitiveType() == supportedType.getPrimitiveType()) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (!(other instanceof ComplexVariantType)) { | ||
return false; | ||
} | ||
ComplexVariantType otherVariantType = (ComplexVariantType) other; | ||
return otherVariantType.getPredefinedFields().equals(predefinedFields); | ||
} | ||
|
||
@Override | ||
public int getSlotSize() { | ||
return PrimitiveType.VARIANT.getSlotSize(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.