[Chore](agg-state) adjust AggStateType constructor check input (#31401)

adjust AggStateType constructor check input
This commit is contained in:
Pxl
2024-02-28 15:23:27 +08:00
committed by yiguolei
parent 586217bf73
commit 6737fdea64
7 changed files with 36 additions and 132 deletions

View File

@ -37,8 +37,6 @@ import org.apache.logging.log4j.Logger;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;
// Column definition which is generated by SQL syntax parser
// Syntax:
@ -172,8 +170,6 @@ public class ColumnDef {
private String name;
private TypeDef typeDef;
private AggregateType aggregateType;
private String genericAggregationName;
private List<TypeDef> genericAggregationArguments;
private boolean isKey;
private boolean isAllowNull;
@ -273,18 +269,6 @@ public class ColumnDef {
this.aggregateType = aggregateType;
}
public void setGenericAggregationName(String genericAggregationName) {
this.genericAggregationName = genericAggregationName;
}
public void setGenericAggregationName(AggregateType aggregateType) {
this.genericAggregationName = aggregateType.name().toLowerCase();
}
public void setGenericAggregationArguments(List<TypeDef> genericAggregationArguments) {
this.genericAggregationArguments = genericAggregationArguments;
}
public boolean isKey() {
return isKey;
}
@ -421,21 +405,6 @@ public class ColumnDef {
}
}
if (type.getPrimitiveType() == PrimitiveType.AGG_STATE && genericAggregationName != null) {
if (isKey()) {
throw new AnalysisException("AGG_STATE type should not be used in key column[" + getName()
+ "].");
}
for (TypeDef def : genericAggregationArguments) {
def.analyze(null);
}
} else if (type.getPrimitiveType() == PrimitiveType.AGG_STATE) {
throw new AnalysisException("AGG_STATE type need generic aggregation in column[" + getName()
+ "].");
} else if (genericAggregationName != null) {
throw new AnalysisException("generic aggregation need AGG_STATE type in column[" + getName()
+ "].");
}
// If aggregate type is REPLACE_IF_NOT_NULL, we set it nullable.
// If default value is not set, we set it NULL
@ -586,17 +555,7 @@ public class ColumnDef {
}
public Column toColumn() {
List<Type> typeList = null;
List<Boolean> nullableList = null;
Type type = typeDef.getType();
if (genericAggregationArguments != null) {
typeList = genericAggregationArguments.stream().map(TypeDef::getType).collect(Collectors.toList());
nullableList = genericAggregationArguments.stream().map(TypeDef::getNullable).collect(Collectors.toList());
type = Expr.createAggStateType(genericAggregationName, typeList, nullableList);
}
return new Column(name, type, isKey, aggregateType, isAllowNull, autoIncInitValue, defaultValue.value, comment,
visible, defaultValue.defaultValueExprDef, Column.COLUMN_UNIQUE_ID_INIT_VALUE, defaultValue.getValue(),
clusterKeyId);

View File

@ -72,6 +72,7 @@ import java.util.ListIterator;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
/**
* Root of the expr node hierarchy.
@ -465,7 +466,7 @@ public abstract class Expr extends TreeNode<Expr> implements ParseNode, Cloneabl
setSelectivity();
}
analysisDone();
if (type.isAggStateType() && !(this instanceof SlotRef) && ((AggStateType) type).getSubTypes() == null) {
if (type.isAggStateType() && !(this instanceof SlotRef) && !children.get(0).getType().isAggStateType()) {
type = createAggStateType(((AggStateType) type), Arrays.asList(collectChildReturnTypes()),
Arrays.asList(collectChildReturnNullables()));
}
@ -1045,10 +1046,6 @@ public abstract class Expr extends TreeNode<Expr> implements ParseNode, Cloneabl
// Append a flattened version of this expr, including all children, to 'container'.
protected void treeToThriftHelper(TExpr container) {
TExprNode msg = new TExprNode();
if (type.isAggStateType() && ((AggStateType) type).getSubTypes() == null) {
type = createAggStateType(((AggStateType) type), Arrays.asList(collectChildReturnTypes()),
Arrays.asList(collectChildReturnNullables()));
}
msg.type = type.toThrift();
msg.num_children = children.size();
if (fn != null) {
@ -1964,9 +1961,6 @@ public abstract class Expr extends TreeNode<Expr> implements ParseNode, Cloneabl
throw new AnalysisException("merge/union function must input one agg_state");
}
AggStateType aggState = (AggStateType) argList.get(0);
if (aggState.getSubTypes() == null) {
throw new AnalysisException("agg_state's subTypes is null");
}
nestedArgList = aggState.getSubTypes();
}
@ -1979,7 +1973,9 @@ public abstract class Expr extends TreeNode<Expr> implements ParseNode, Cloneabl
if (isState) {
f = new ScalarFunction(new FunctionName(name + AGG_STATE_SUFFIX), Arrays.asList(f.getArgs()),
Expr.createAggStateType(name, null, null), f.hasVarArgs(), f.isUserVisible());
Expr.createAggStateType(name, nestedArgList,
nestedArgList.stream().map(e -> true).collect(Collectors.toList())),
f.hasVarArgs(), f.isUserVisible());
f.setNullableMode(NullableMode.ALWAYS_NOT_NULLABLE);
} else {
Function original = f;

View File

@ -58,7 +58,7 @@ public class ColumnStatistic {
.build();
public static final Set<Type> UNSUPPORTED_TYPE = Sets.newHashSet(
Type.HLL, Type.BITMAP, Type.ARRAY, Type.STRUCT, Type.MAP, Type.QUANTILE_STATE, Type.AGG_STATE, Type.JSONB,
Type.HLL, Type.BITMAP, Type.ARRAY, Type.STRUCT, Type.MAP, Type.QUANTILE_STATE, Type.JSONB,
Type.VARIANT, Type.TIME, Type.TIMEV2, Type.LAMBDA_FUNCTION
);