[WIP](dynamic-table) support dynamic schema table (#16335)

Issue Number: close #16351

Dynamic schema table is a special type of table, it's schema change with loading procedure.Now we implemented this feature mainly for semi-structure data such as JSON, since JSON is schema self-described we could extract schema info from the original documents and inference the final type infomation.This speical table could reduce manual schema change operation and easily import semi-structure data and extends it's schema automatically.
This commit is contained in:
lihangyu
2023-02-11 13:37:50 +08:00
committed by GitHub
parent e99202754e
commit 37d1519316
131 changed files with 5628 additions and 282 deletions

View File

@ -71,6 +71,7 @@ public enum PrimitiveType {
// Aligning to 16 bytes total.
STRUCT("STRUCT", 16, TPrimitiveType.STRUCT),
STRING("STRING", 16, TPrimitiveType.STRING),
VARIANT("VARIANT", 24, TPrimitiveType.VARIANT),
// Unsupported scalar types.
BINARY("BINARY", -1, TPrimitiveType.BINARY),
ALL("ALL", -1, TPrimitiveType.INVALID_TYPE);
@ -557,6 +558,7 @@ public enum PrimitiveType {
supportedTypes.add(ARRAY);
supportedTypes.add(MAP);
supportedTypes.add(QUANTILE_STATE);
supportedTypes.add(VARIANT);
}
public static ArrayList<PrimitiveType> getIntegerTypes() {
@ -1004,6 +1006,8 @@ public enum PrimitiveType {
return STRUCT;
case ALL:
return ALL;
case VARIANT:
return VARIANT;
default:
return INVALID_TYPE;
}
@ -1112,6 +1116,10 @@ public enum PrimitiveType {
return this == HLL || this == BITMAP;
}
public boolean isVariantType() {
return this == VARIANT;
}
public boolean isStringType() {
return (this == VARCHAR || this == CHAR || this == HLL || this == STRING);
}

View File

@ -603,6 +603,7 @@ public class ScalarType extends Type {
case DATEV2:
case HLL:
case BITMAP:
case VARIANT:
case QUANTILE_STATE:
stringBuilder.append(type.toString().toLowerCase());
break;

View File

@ -106,6 +106,7 @@ public abstract class Type {
public static final MapType MAP = new MapType();
public static final ArrayType ARRAY = ArrayType.create();
public static final StructType STRUCT = new StructType();
public static final VariantType VARIANT = new VariantType();
private static final Logger LOG = LogManager.getLogger(Type.class);
private static final ArrayList<ScalarType> integerTypes;
@ -474,6 +475,10 @@ public abstract class Type {
return isStructType() || isCollectionType();
}
public boolean isVariantType() {
return this instanceof VariantType;
}
public boolean isCollectionType() {
return isMapType() || isArrayType() || isMultiRowType() || isStructType();
}
@ -780,6 +785,8 @@ public abstract class Type {
return Type.BITMAP;
case QUANTILE_STATE:
return Type.QUANTILE_STATE;
case VARIANT:
return new VariantType();
default:
return null;
}
@ -1553,7 +1560,8 @@ public abstract class Type {
|| t1 == PrimitiveType.TIMEV2 || t2 == PrimitiveType.TIMEV2
|| t1 == PrimitiveType.MAP || t2 == PrimitiveType.MAP
|| t1 == PrimitiveType.STRUCT || t2 == PrimitiveType.STRUCT
|| t1 == PrimitiveType.UNSUPPORTED || t2 == PrimitiveType.UNSUPPORTED) {
|| t1 == PrimitiveType.UNSUPPORTED || t2 == PrimitiveType.UNSUPPORTED
|| t1 == PrimitiveType.VARIANT || t2 == PrimitiveType.VARIANT) {
continue;
}
Preconditions.checkNotNull(compatibilityMatrix[i][j]);

View File

@ -0,0 +1,80 @@
// 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;
public class VariantType extends Type {
public VariantType() {
}
@Override
public String toSql(int depth) {
return "VARIANT";
}
@Override
protected String prettyPrint(int lpad) {
return "VARIANT";
}
@Override
public boolean equals(Object other) {
return other instanceof VariantType;
}
@Override
public void toThrift(TTypeDesc container) {
TTypeNode node = new TTypeNode();
container.types.add(node);
node.setType(TTypeNodeType.VARIANT);
}
@Override
public String toString() {
return toSql(0);
}
@Override
public PrimitiveType getPrimitiveType() {
return PrimitiveType.VARIANT;
}
@Override
public boolean supportsTablePartitioning() {
return false;
}
@Override
public int getSlotSize() {
return PrimitiveType.VARIANT.getSlotSize();
}
@Override
public boolean isSupported() {
return true;
}
@Override
public boolean matchesType(Type t) {
return t.isVariantType() || t.isStringType();
}
}