|
| 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 | +# Tests for Run-End Encoded (REE) array support in aggregations |
| 19 | +# This tests that REE arrays can be used as GROUP BY keys (requires proper hashing support) |
| 20 | + |
| 21 | +# Create a table with REE-encoded sensor IDs using arrow_cast |
| 22 | +# First create primitive arrays, then cast to REE in a second step |
| 23 | +statement ok |
| 24 | +CREATE TABLE sensor_readings AS |
| 25 | +WITH raw_data AS ( |
| 26 | + SELECT * FROM ( |
| 27 | + VALUES |
| 28 | + ('sensor_A', 22), |
| 29 | + ('sensor_A', 23), |
| 30 | + ('sensor_B', 20), |
| 31 | + ('sensor_A', 24) |
| 32 | + ) AS t(sensor_id, temperature) |
| 33 | +) |
| 34 | +SELECT |
| 35 | + arrow_cast(sensor_id, 'RunEndEncoded("run_ends": non-null Int32, "values": Utf8)') AS sensor_id, |
| 36 | + temperature |
| 37 | +FROM raw_data; |
| 38 | + |
| 39 | +# Test basic aggregation with REE column as GROUP BY key |
| 40 | +query ?RI rowsort |
| 41 | +SELECT |
| 42 | + sensor_id, |
| 43 | + AVG(temperature) AS avg_temp, |
| 44 | + COUNT(*) AS reading_count |
| 45 | +FROM sensor_readings |
| 46 | +GROUP BY sensor_id; |
| 47 | +---- |
| 48 | +sensor_A 23 3 |
| 49 | +sensor_B 20 1 |
| 50 | + |
| 51 | +# Test DISTINCT with REE column |
| 52 | +query ? rowsort |
| 53 | +SELECT DISTINCT sensor_id |
| 54 | +FROM sensor_readings; |
| 55 | +---- |
| 56 | +sensor_A |
| 57 | +sensor_B |
0 commit comments