Repository navigation
Fix 500 from coalesce, mvappend, array and percentile_approx types on short, byte and float values - #5874
Fix 500 from coalesce, mvappend, array and percentile_approx types on short, byte and float values#5874cnoramut wants to merge 1 commit into
Conversation
Four functions built a result whose Java class did not match the class Calcite casts it to for the declared type. coalesce built an Integer for SMALLINT and TINYINT and a Float for Calcite FLOAT. mvappend and array built Float elements for Calcite FLOAT. percentile_approx, which median also uses, returned a Double for SMALLINT, TINYINT and REAL and a Float for FLOAT. The cast threw, so the query returned 500 with a ClassCastException. Build each value with the class Calcite expects. Calcite's FLOAT is double precision and REAL is single precision, so FLOAT now shares the DOUBLE arm and REAL keeps the float. Signed-off-by: Chayanin Noramuttha <cnoramut@amazon.com>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
Codecov Report❌ Patch coverage is ❌ Your project check has failed because the head coverage (63.86%) is below the target coverage (99.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #5874 +/- ##
============================================
+ Coverage 63.80% 63.86% +0.06%
- Complexity 9070 9088 +18
============================================
Files 962 962
Lines 40989 41034 +45
Branches 4660 4668 +8
============================================
+ Hits 26152 26206 +54
+ Misses 13960 13950 -10
- Partials 877 878 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
coalesce,mvappend,arrayandpercentile_approxreturn HTTP 500 with aClassCastExceptionfor some numeric types.coalesce(s)on ashortorbytefield fails, and so does any of the first three with a float literal such as2.5F.percentile_approxandmedianfail in memory onshort,byte,floatandhalf_floatfields.Root cause. Each function hands its result to Calcite as an
Object, and Calcite casts it to the Java class of the declared type. That class isShortforSMALLINT,ByteforTINYINT,FloatforREALandDoubleforFLOAT, since Calcite'sFLOATis double precision per its data types. Each function built the wrong class for some of these.mvappendandarraybuiltFloatelements forFLOATin the same way.percentile_approx.resultreturned adoubleforSMALLINT,TINYINTandREALand afloatforFLOAT. Afloatfield is typedREAL, so it reachesFLOATonly next to a literal such as2.5F.Fix. Each switch now builds the class Calcite expects.
SMALLINTandTINYINTbuild a short and a byte,FLOATjoinsDOUBLE, andREALkeeps the float.Before and after. HTTP status on one index with
smappedshort,bmappedbyteandfmappedfloat, onmainat00262797cand on this branch.eval x = coalesce(s)Integercannot be cast toShortsmallinteval x = coalesce(b)Integercannot be cast toBytetinyinteval x = coalesce(f, 2.5F)Floatcannot be cast toDoublefloateval x = mvappend(f, 2.5F)Floatcannot be cast toDoublearrayeval x = array(f, 2.5F)Floatcannot be cast toDoublearraystats percentile_approx(s, 50), max(lower(host))Doublecannot be cast toShortsmallintstats median(s), max(lower(host))Doublecannot be cast toShortsmallintstats percentile_approx(f, 50), max(lower(host))Doublecannot be cast toFloatfloateval x = coalesce(f)floatfloatA matrix crossed every numeric field type with each literal kind and every field pair. On
main, 33 of 126coalescecalls failed, 15 of 108mvappendcalls, 16 float-literalarraycalls and 10 of 24percentile_approxcalls. On this branch each of those returns 200, apart fromcoalescecalls onunsigned_long, which PPL does not support and which fail the same way onmain. The fixed values match the first present argument forcoalesce, the elements formvappendandarray, and the pushed-down result forpercentile_approx.Notes
issues/5873.ymladds 15 cases. The casts happen in generated code and in Avatica, so a plan-level unit test cannot reach them and a YAML REST test can.ArrayFunctionImplTestpinned the oldFloatresult forFLOAT, so it now expects doubles.FLOATsits withDOUBLE- It looks like a typo next toREAL, but it matches Calcite's own mapping, whichExprSqlTypealready copies ascase DOUBLE, FLOAT. Each switch carries a one-line comment, since regroupingFLOATwithREALwould bring the 500 back. A float field widened toFLOATshows float noise, so 0.1 becomes 0.10000000149011612, the same asifnullreturns.Related Issues
Resolves #5873
Testing
issues/5873.yml, 15 cases. Without the fix, every case except thecoalesce(f)andcoalesce(s, 0)controls fails with HTTP 500. Reverting one function's hunk fails only that function's cases.:core:testran 5334 tests and:ppl:testran 2145, both with 0 failures.mainand of this branch.Check List
--signoffor-s.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.