|
| 1 | +-- Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +-- or more contributor license agreements. See the NOTICE file |
| 3 | +-- distributed with this work for additional information |
| 4 | +-- regarding copyright ownership. The ASF licenses this file |
| 5 | +-- to you under the Apache License, Version 2.0 (the |
| 6 | +-- "License"); you may not use this file except in compliance |
| 7 | +-- with the License. You may obtain a copy of the License at |
| 8 | +-- |
| 9 | +-- http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +-- |
| 11 | +-- Unless required by applicable law or agreed to in writing, |
| 12 | +-- software distributed under the License is distributed on an |
| 13 | +-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +-- KIND, either express or implied. See the License for the |
| 15 | +-- specific language governing permissions and limitations |
| 16 | +-- under the License. |
| 17 | + |
| 18 | +-- Strict floating-point mode and sort or window keys that nest floats in arrays and structs. |
| 19 | +-- nested_float_order_keys.sql checks that Comet normalizes those floats to match Spark. Strict |
| 20 | +-- mode still declines a key whose type can hold a null element or field, because Spark orders |
| 21 | +-- such a null below every value whatever the key's null order, the native sort places it by the |
| 22 | +-- null order (#6476), and a RANGE window frame orders it above every value (#6477). A key whose |
| 23 | +-- type cannot hold a null stays native. |
| 24 | +-- |
| 25 | +-- The test harness admits incompatible sort orders by default, so turn that off to check the |
| 26 | +-- shipped policy. |
| 27 | +-- Config: spark.comet.exec.strictFloatingPoint=true |
| 28 | +-- Config: spark.comet.expression.SortOrder.allowIncompatible=false |
| 29 | + |
| 30 | +statement |
| 31 | +CREATE TABLE nested_float_strict(id INT, g INT, d DOUBLE, f FLOAT, s BOOLEAN) USING parquet |
| 32 | + |
| 33 | +statement |
| 34 | +INSERT INTO nested_float_strict VALUES |
| 35 | + (1, 1, 0.0D, float('0.0'), true), |
| 36 | + (2, 1, 0.0D, float('0.0'), false), |
| 37 | + (3, 1, 1.0D, float('1.0'), false), |
| 38 | + (4, 2, double('NaN'), float('NaN'), false), |
| 39 | + (5, 2, double('NaN'), float('NaN'), true), |
| 40 | + (6, 2, double('Infinity'), float('Infinity'), false), |
| 41 | + (7, 2, -1.0D, float('-1.0'), false), |
| 42 | + (8, 1, NULL, NULL, false), |
| 43 | + (9, 2, double('-Infinity'), float('-Infinity'), false) |
| 44 | + |
| 45 | +-- Keys over the nullable columns can hold a null element or field, whether or not any row does, |
| 46 | +-- so they fall back, and Spark's answers come back. Row 8 holds one. Native, ORDER BY array(d) |
| 47 | +-- NULLS LAST puts row 8 last, where Spark puts it first, and the running sum spans the whole |
| 48 | +-- partition on row 8 and every row after it. |
| 49 | +query expect_fallback(can hold a null element or field) |
| 50 | +SELECT id FROM nested_float_strict ORDER BY array(d) NULLS LAST, id |
| 51 | + |
| 52 | +query expect_fallback(can hold a null element or field) |
| 53 | +SELECT id, SUM(id) OVER (ORDER BY array(d)) AS running FROM nested_float_strict |
| 54 | + |
| 55 | +query expect_fallback(can hold a null element or field) |
| 56 | +SELECT id FROM nested_float_strict ORDER BY named_struct('x', f) DESC NULLS FIRST, id |
| 57 | + |
| 58 | +query expect_fallback(can hold a null element or field) |
| 59 | +SELECT id FROM nested_float_strict ORDER BY array(IF(s, -d, d)), id LIMIT 4 |
| 60 | + |
| 61 | +query expect_fallback(can hold a null element or field) |
| 62 | +SELECT id, |
| 63 | + RANK() OVER (PARTITION BY g ORDER BY named_struct('x', IF(s, -d, d))) AS r, |
| 64 | + DENSE_RANK() OVER (ORDER BY array(IF(s, -f, f)) DESC) AS dr |
| 65 | +FROM nested_float_strict |
| 66 | + |
| 67 | +query expect_fallback(can hold a null element or field) |
| 68 | +SELECT id FROM ( |
| 69 | + SELECT id, RANK() OVER (ORDER BY array(IF(s, -d, d))) AS r FROM nested_float_strict |
| 70 | +) WHERE r <= 3 |
| 71 | + |
| 72 | +-- coalesce with a literal is never null, so an array or struct of it cannot hold a null, and |
| 73 | +-- these keys stay native. Row 8 becomes a third zero. Each ORDER BY ends with a unique |
| 74 | +-- tiebreaker, so peers come out in its order, and the running sums need no null row to leave out. |
| 75 | +query |
| 76 | +SELECT id FROM nested_float_strict ORDER BY array(coalesce(IF(s, -d, d), 0.0D)), id DESC |
| 77 | + |
| 78 | +query |
| 79 | +SELECT id FROM nested_float_strict ORDER BY named_struct('x', coalesce(IF(s, -f, f), 0.0F)) DESC, id |
| 80 | + |
| 81 | +query |
| 82 | +SELECT id FROM nested_float_strict ORDER BY array(coalesce(IF(s, -d, d), 0.0D)) DESC, id LIMIT 4 |
| 83 | + |
| 84 | +query |
| 85 | +SELECT id, |
| 86 | + RANK() OVER (ORDER BY array(coalesce(IF(s, -d, d), 0.0D))) AS r, |
| 87 | + SUM(id) OVER (ORDER BY array(coalesce(IF(s, -d, d), 0.0D))) AS running, |
| 88 | + DENSE_RANK() OVER (PARTITION BY g ORDER BY named_struct('x', coalesce(IF(s, -f, f), 0.0F)) DESC) AS dr |
| 89 | +FROM nested_float_strict |
| 90 | + |
| 91 | +-- A rank limit keeps every peer of the last rank it admits |
| 92 | +query |
| 93 | +SELECT id FROM ( |
| 94 | + SELECT id, RANK() OVER (ORDER BY array(coalesce(IF(s, -d, d), 0.0D))) AS r |
| 95 | + FROM nested_float_strict |
| 96 | +) WHERE r <= 3 |
| 97 | + |
| 98 | +query |
| 99 | +SELECT id FROM ( |
| 100 | + SELECT id, |
| 101 | + DENSE_RANK() OVER (PARTITION BY g ORDER BY named_struct('x', coalesce(IF(s, -f, f), 0.0F)) DESC) AS r |
| 102 | + FROM nested_float_strict |
| 103 | +) WHERE r <= 1 |
0 commit comments