Repository navigation
Conversation
…nts (opensearch-project#5898) Signed-off-by: Tanvir Hossain <1593367+tanvir4se@users.noreply.github.com>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
Decision LogRoot cause. Approach. The Alternatives rejected. A custom Calling Calcite's full Mapping the run-time RFC #4146 describes converting the elements to text. The Pitfalls. When a type checker rejects the call, Date, time and timestamp user-defined types report
Things to watch. On the analytics-engine route,
|
I am keeping
A bare |
I am leaving this check as it is. Calcite documents The suggested change would let an element with a null type name pass analysis instead of rejecting it. |
Description
mvjoin, andnomv(which rewrites tomvjoin), returned HTTP 500 while running the query when the array's elements were not strings, for examplemvjoin(array(n), ',')on a number field. They now return HTTP 400 while analyzing, as themvjoindocs already say ("Only string arrays are supported").Root cause.
MVJOINis registered as Calcite'sARRAY_JOIN. The PPL wrapper around its type checker compares only the operand count and each operand's family, soARRAY<BIGINT>passed asARRAY, andSqlFunctions.arrayToStringthrewIllegalStateExceptionat run time.Fix. The
MVJOINimplementation checks the array's element type before building the call. Strings and the string-backed date, time and timestamp types pass. Other known element types throw, whichresolve()reports as anExpressionEvaluationException(400). The check sits in the implementation, not the type checker, because the coercion fallback seesARRAY<BIGINT>andARRAY<ANY>as the sameARRAYand would build the call anyway.Behaviour change.
nomvon an array of a number field whose values are all null returned 200 with""and now returns 400, because the element type decides. The affected tests now cast to string.Known limitation. Arrays typed
ARRAY<ANY>, from a barenomvon a nested field or a mixedmvappend('a', n), are still accepted during analysis and still return 500 at run time. No follow-up issue is filed yet.Before and after
mvjoin(array(k)),nomvonarray(k)(keyword)t(text)d(date), result2024-01-01 00:00:00i(integer),l(long),db(double),bo(boolean)executinganalyzingip,gp(geo_point),o(object),ne(nested)executinganalyzingmvjoin(l, ',')(scalar)MVJOIN function expects ...mvjoin(array('a', l), ',')a,3a,3mvjoin(array(cast(l as string)), ',')33nomv ne(ARRAY, known limitation)mvjoin(mvappend('a', l), ',')(ARRAY, known limitation)Example after-fix message:
Cannot resolve function: MVJOIN, arguments: [ARRAY,STRING], caused by: MVJOIN only supports string arrays, but got an array of LONG.Open questions
These are still open on the issue. The PR uses the defaults below.
mvjoinwork. @ahkcs, please say if you would rather convert elements to text.MVJOINimplementation, withMVJOIN only supports string arrays, but got an array of <TYPE>. Happy to move it to a custom type checker, or to change the wording.ARRAY<ANY>stays out of scope. Default: yes. Barenomvon a nested field andmvjoin(mvappend('a', n), ',')still return 500. I can open a follow-up issue.Related Issues
Resolves #5898
Check List
--signoffor-s.Could a maintainer please add the
bugFixlabel?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.