Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions fe/src/main/java/org/apache/doris/load/Load.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.doris.load;

import org.apache.doris.catalog.AggregateType;
import org.apache.doris.analysis.BinaryPredicate;
import org.apache.doris.analysis.CancelLoadStmt;
import org.apache.doris.analysis.ColumnSeparator;
Expand Down Expand Up @@ -734,6 +735,15 @@ public static void checkAndCreateSource(Database db, DataDescription dataDescrip
throw new DdlException("Column has no default value. column: " + columnName);
}

// check negative for sum aggreate type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (dataDescriptior.isNegative()) {
}

if (dataDescription.isNegative()) {
for (Column column : tableSchema) {
if (!column.isKey() && column.getAggregationType() != AggregateType.SUM) {
throw new DdlException("Column is not SUM AggreateType. column:" + column.getName());
}
}
}

// check hll
for (Column column : tableSchema) {
if (column.getDataType() == PrimitiveType.HLL) {
Expand Down
8 changes: 8 additions & 0 deletions fe/src/main/java/org/apache/doris/planner/BrokerScanNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@

package org.apache.doris.planner;

import org.apache.doris.catalog.AggregateType;
import org.apache.doris.analysis.Analyzer;
import org.apache.doris.analysis.ArithmeticExpr;
import org.apache.doris.analysis.BinaryPredicate;
import org.apache.doris.analysis.BrokerDesc;
import org.apache.doris.analysis.Expr;
import org.apache.doris.analysis.ExprSubstitutionMap;
import org.apache.doris.analysis.FunctionCallExpr;
import org.apache.doris.analysis.FunctionName;
import org.apache.doris.analysis.FunctionParams;
import org.apache.doris.analysis.IntLiteral;
import org.apache.doris.analysis.NullLiteral;
import org.apache.doris.analysis.SlotDescriptor;
import org.apache.doris.analysis.SlotRef;
Expand Down Expand Up @@ -381,6 +384,7 @@ private void finalizeParams(ParamCreateContext context) throws UserException, An
}
}

boolean isNegative = context.fileGroup.isNegative();
for (SlotDescriptor destSlotDesc : desc.getSlots()) {
if (!destSlotDesc.isMaterialized()) {
continue;
Expand Down Expand Up @@ -412,6 +416,10 @@ private void finalizeParams(ParamCreateContext context) throws UserException, An
}
}

if (isNegative && destSlotDesc.getColumn().getAggregationType() == AggregateType.SUM) {
expr = new ArithmeticExpr(ArithmeticExpr.Operator.MULTIPLY, expr, new IntLiteral(-1));
expr.analyze(analyzer);
}
expr = castToSlot(destSlotDesc, expr);
context.params.putToExpr_of_dest_slot(destSlotDesc.getId().asInt(), expr.treeToThrift());
}
Expand Down