[Improve](complex-type)improve array/map/struct creating and function with decimalv3 (#19830)

This commit is contained in:
amory
2023-05-19 17:43:36 +08:00
committed by GitHub
parent d8d6880ef1
commit 67dc68630b
4 changed files with 67 additions and 11 deletions

View File

@ -199,6 +199,9 @@ public abstract class Type {
mapSubTypes.add(FLOAT);
mapSubTypes.add(DOUBLE);
mapSubTypes.add(DECIMALV2);
mapSubTypes.add(DECIMAL32); // same DEFAULT_DECIMALV3
mapSubTypes.add(DECIMAL64);
mapSubTypes.add(DECIMAL128);
mapSubTypes.add(DATE);
mapSubTypes.add(DATETIME);
mapSubTypes.add(DATEV2);
@ -214,6 +217,9 @@ public abstract class Type {
structSubTypes.add(FLOAT);
structSubTypes.add(DOUBLE);
structSubTypes.add(DECIMALV2);
structSubTypes.add(DECIMAL32); // same DEFAULT_DECIMALV3
structSubTypes.add(DECIMAL64);
structSubTypes.add(DECIMAL128);
structSubTypes.add(DATE);
structSubTypes.add(DATETIME);
structSubTypes.add(DATEV2);
@ -341,6 +347,41 @@ public abstract class Type {
return isScalarType(PrimitiveType.DECIMALV2);
}
public boolean typeContainsPrecision() {
if (PrimitiveType.typeWithPrecision.contains(this.getPrimitiveType())) {
return true;
} else if (isStructType()) {
for (StructField field : ((StructType) this).getFields()) {
if (PrimitiveType.typeWithPrecision.contains(field.getType().getPrimitiveType())) {
return true;
}
}
} else if (isMapType()) {
return PrimitiveType.typeWithPrecision.contains(((MapType) this).getKeyType().getPrimitiveType())
|| PrimitiveType.typeWithPrecision.contains(((MapType) this).getValueType().getPrimitiveType());
} else if (isArrayType()) {
return PrimitiveType.typeWithPrecision.contains(((ArrayType) this).getItemType().getPrimitiveType());
}
return false;
}
public boolean isDecimalV3OrContainsDecimalV3() {
if (isDecimalV3()) {
return true;
} else if (isStructType()) {
for (StructField field : ((StructType) this).getFields()) {
if (field.getType().isDecimalV3()) {
return true;
}
}
} else if (isMapType()) {
return ((MapType) this).getKeyType().isDecimalV3() || ((MapType) this).getValueType().isDecimalV3();
} else if (isArrayType()) {
return ((ArrayType) this).getItemType().isDecimalV3();
}
return false;
}
public boolean isDecimalV3() {
return isScalarType(PrimitiveType.DECIMAL32) || isScalarType(PrimitiveType.DECIMAL64)
|| isScalarType(PrimitiveType.DECIMAL128);