Repository navigation
HIVE-30136 Fix vectorized LEAD/LAG literal defaults for DOUBLE/DECIMAL - #6952
Open
rapidgithub wants to merge 1 commit into
Open
rapidgithub wants to merge 1 commit into
rapidgithub wants to merge 1 commit into
Conversation
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What changes were proposed in this pull request?
This PR fixes an issue where vectorized execution of
LAGandLEADwindow functions returns0.0(or0) instead of the specified default literal value when aDOUBLEorDECIMALliteral default is provided.Specifically:
VectorPTFEvaluatorAbstractLeadLag.initDefaultValue():cve.getIsNullValue()) sodefaultValueproperly evaluates tonull.ConstantVectorExpression.getLongValue()withcve.getValue(), reading the literal according to its actual type.type:Type.DOUBLE: ConvertsNumber(doubleValue()),HiveDecimal,HiveDecimalWritable, or String.Type.DECIMAL: Produces aHiveDecimalWritableviasetFromDouble(),setFromLong(),HiveDecimal, or String.Type.LONG: ConvertsNumber(longValue()),HiveDecimal,HiveDecimalWritable, or String."for lag function"to"for lead/lag function"(as bothLAGandLEADshare this base evaluator).TestVectorPTFEvaluatorLeadLag.javaverifyingDOUBLE,DECIMAL,LONG, andNULLdefaults for bothVectorPTFEvaluatorLagandVectorPTFEvaluatorLead.vector_ptf_lead_lag.qto test literal defaults with both vectorized execution disabled and enabled.Why are the changes needed?
In
VectorPTFEvaluatorAbstractLeadLag.initDefaultValue(), the constant default value expression was previously initialized using:In
ConstantVectorExpression, constants are stored by type: double/float literals are stored indoubleValue, and decimal literals are stored indecimalValue(whilelongValueremains0).Because
getLongValue()was always read:Type.DOUBLE,Double.valueOf(0)produced0.0.Type.DECIMAL,new HiveDecimalWritable(0)produced0.NULLconstant literals,longValuewas also read, returning0.0/0instead ofnull.This caused a divergence between non-vectorized and vectorized execution: non-vectorized execution returned the expected literal default (e.g.
2.5), while vectorized execution returned0.0or0.Does this PR introduce any user-facing change?
Yes. Fixes incorrect query results when vectorized execution is enabled for queries using
LAG(...)orLEAD(...)with a non-integer literal default.Repro Example:
0.0foreast/1andwest/1.2.5foreast/1andwest/1(matching non-vectorized execution).How was this patch tested?
Unit tests added in
TestVectorPTFEvaluatorLeadLag.java:testLagDoubleLiteralDefault: validatesLAGwith double literal default (e.g.2.5).testLeadDoubleLiteralDefault: validatesLEADwith double literal default.testLagDecimalLiteralDefault: validatesLAGwith decimal literal default.testLeadDecimalLiteralDefault: validatesLEADwith decimal literal default.testLagDecimalFromDoubleDefault: validates double literal default on a decimal column.testLagLongLiteralDefault: validates long literal default.testLagNullConstantDefault: validates null constant default.testLagNullExpressionDefault: validates null expression default.Command:
mvn test -pl ql -Dtest=TestVectorPTFEvaluatorLeadLagIntegration Q-test:
ql/src/test/queries/clientpositive/vector_ptf_lead_lag.qcomparing non-vectorized and vectorized results forvector_ptf_lead_lag_doubleandvector_ptf_lead_lag_decimal.