From 0b45e3042bec9873fbf15fafc28b74b8d4d4719d Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Mon, 2 Oct 2017 11:47:56 +0100 Subject: [PATCH] MCOL-944 Fix aggregate type switch Aggregates could switch from unsigned to signed prior to execution. This causes issues with NULL values since signed and unsigned NULLs are different. --- dbcon/joblist/tupleaggregatestep.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/dbcon/joblist/tupleaggregatestep.cpp b/dbcon/joblist/tupleaggregatestep.cpp index b7e69db56..c04573475 100755 --- a/dbcon/joblist/tupleaggregatestep.cpp +++ b/dbcon/joblist/tupleaggregatestep.cpp @@ -3445,13 +3445,21 @@ void TupleAggregateStep::prep2PhasesDistinctAggregate( if (typeProj[colProj] != CalpontSystemCatalog::DOUBLE && typeProj[colProj] != CalpontSystemCatalog::FLOAT) { - typeAggPm.push_back(CalpontSystemCatalog::BIGINT); + if (isUnsigned(typeProj[colProj])) + { + typeAggPm.push_back(CalpontSystemCatalog::UBIGINT); + precisionAggPm.push_back(20); + } + else + { + typeAggPm.push_back(CalpontSystemCatalog::BIGINT); + precisionAggPm.push_back(19); + } uint32_t scale = scaleProj[colProj]; // for int average, FE expects a decimal if (aggOp == ROWAGG_AVG) scale = jobInfo.scaleOfAvg[aggKey]; // scale += 4; scaleAggPm.push_back(scale); - precisionAggPm.push_back(19); widthAggPm.push_back(bigIntWidth); } else