RumbleDB / rumble

⛈️ RumbleDB 1.21.0 "Hawthorn blossom" 🌳 for Apache Spark | Run queries on your large-scale, messy JSON-like data (JSON, text, CSV, Parquet, ROOT, AVRO, SVM...) | No install required (just a jar to download) | Declarative Machine Learning and more
http://rumbledb.org/
Other
211 stars 82 forks source link

max and min not working on arrays #862

Open mstevan opened 3 years ago

mstevan commented 3 years ago

@mstevan test-set: max.xml, min.xml test-cases: fn-max-19 and fn-min-19

@team Seems that min and max function do not work on arrays

Input: min([1,2,3,4,5])

Output: ⚠️ ️There was an error.

Code: [XPTY0004] (this code can be looked up in the documentation and specifications).

Location information: file:/Users/mstevan/Documents/:LINE:1:COLUMN:0:

Invalid return type for function min. array cannot be promoted to type atomic?.

Expected output: 1

ghislainfourny commented 3 years ago

Thank you for looking into this.

That's because in JSONiq, arrays cannot be atomized, so the error is expected.

In XQuery they can so what happens is that [1,2,3,4,5] is converted to (1,2,3,4,5) and then min called.

ghislainfourny commented 3 years ago

In your implementation, what you can do is add an iterator for atomizing sequences, and in the translationvisitor for the XQuery 3.1 parser, you can insert that iterator in the middle between an argument and a function call iterator whenever the type is atomic with any arity.