The min/max aggregators use aggregate_type_for comparators, and the aggregate_type_for<timeuuid> is regular uuid. But that yields wrong results; timeuuids should be compared as timestamps. Fix it by changing aggregate_type_for<timeuuid> from uuid to timeuuid, so aggregators can distinguish betwen the two. Then specialize the aggregation utilities for timeuuid. Add a cql-pytest and change some unit tests, which relied on naive uuid comparators. Fixes #7729. Tests: unit (dev, debug) Signed-off-by: Dejan Mircevski <dejan@scylladb.com> Closes #7910
37 lines
1.8 KiB
Python
37 lines
1.8 KiB
Python
# Copyright 2021 ScyllaDB
|
|
#
|
|
# This file is part of Scylla.
|
|
#
|
|
# Scylla is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Scylla is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#############################################################################
|
|
# Tests for min/max aggregate functions
|
|
#############################################################################
|
|
|
|
import pytest
|
|
from cassandra.protocol import SyntaxException, AlreadyExists, InvalidRequest, ConfigurationException, ReadFailure
|
|
from cassandra.util import Date
|
|
from util import unique_name, random_string, new_test_table, project
|
|
|
|
# Regression-test for #7729.
|
|
def test_timeuuid(cql, test_keyspace):
|
|
schema = "a int, b timeuuid, primary key (a,b)"
|
|
with new_test_table(cql, test_keyspace, schema) as table:
|
|
cql.execute(f'insert into {table} (a, b) values (0, 13814000-1dd2-11ff-8080-808080808080)')
|
|
cql.execute(f'insert into {table} (a, b) values (0, 6b1b3620-33fd-11eb-8080-808080808080)')
|
|
assert project('system_todate_system_min_b',
|
|
cql.execute(f'select todate(min(b)) from {table} where a = 0')) == [Date('2020-12-01')]
|
|
assert project('system_todate_system_max_b',
|
|
cql.execute(f'select todate(max(b)) from {table} where a = 0')) == [Date('2038-09-06')]
|