From d42a7e5f8fa11e2e6656caef54c283756b61608d Mon Sep 17 00:00:00 2001 From: yariks5s Date: Fri, 12 Jan 2024 23:46:50 +0000 Subject: [PATCH] init --- src/Dictionaries/PolygonDictionaryUtils.cpp | 2 +- src/Dictionaries/PolygonDictionaryUtils.h | 2 ++ .../02960_polygon_bound_bug.reference | 1 + .../0_stateless/02960_polygon_bound_bug.sh | 10 ++++++++++ .../data_parquet/02960_polygon_bound_bug.parquet | Bin 0 -> 1021 bytes 5 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/queries/0_stateless/02960_polygon_bound_bug.reference create mode 100755 tests/queries/0_stateless/02960_polygon_bound_bug.sh create mode 100644 tests/queries/0_stateless/data_parquet/02960_polygon_bound_bug.parquet diff --git a/src/Dictionaries/PolygonDictionaryUtils.cpp b/src/Dictionaries/PolygonDictionaryUtils.cpp index c28c7c15aa7..2af97d3fc6f 100644 --- a/src/Dictionaries/PolygonDictionaryUtils.cpp +++ b/src/Dictionaries/PolygonDictionaryUtils.cpp @@ -267,7 +267,7 @@ bool SlabsPolygonIndex::find(const Point & point, size_t & id) const Coord y = point.y(); /** Not in bounding box */ - if (x < sorted_x[0] || x > sorted_x.back()) + if (x < sorted_x.front() || x > sorted_x.back()) return false; bool found = false; diff --git a/src/Dictionaries/PolygonDictionaryUtils.h b/src/Dictionaries/PolygonDictionaryUtils.h index 63d97e9dabd..62143316479 100644 --- a/src/Dictionaries/PolygonDictionaryUtils.h +++ b/src/Dictionaries/PolygonDictionaryUtils.h @@ -157,6 +157,8 @@ public: auto y_ratio = y * kSplit; auto x_bin = static_cast(x_ratio); auto y_bin = static_cast(y_ratio); + x_bin = x_bin == kSplit ? x_bin - 1 : x_bin; // In case if we have a lot of values and argument is very close to max_x (max_y) so x_ratio (y_ratio) = 1 + y_bin = y_bin == kSplit ? y_bin - 1 : y_bin; // => x_bin (y_bin) will be 4, which can lead to wrong vector access return children[y_bin + x_bin * kSplit]->find(x_ratio - x_bin, y_ratio - y_bin); } diff --git a/tests/queries/0_stateless/02960_polygon_bound_bug.reference b/tests/queries/0_stateless/02960_polygon_bound_bug.reference new file mode 100644 index 00000000000..573541ac970 --- /dev/null +++ b/tests/queries/0_stateless/02960_polygon_bound_bug.reference @@ -0,0 +1 @@ +0 diff --git a/tests/queries/0_stateless/02960_polygon_bound_bug.sh b/tests/queries/0_stateless/02960_polygon_bound_bug.sh new file mode 100755 index 00000000000..c778b14357e --- /dev/null +++ b/tests/queries/0_stateless/02960_polygon_bound_bug.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CURDIR"/../shell_config.sh + +$CLICKHOUSE_LOCAL -nm -q "CREATE TABLE test_table (geom MultiPolygon) engine=MergeTree ORDER BY geom; +INSERT INTO test_table SELECT * FROM file('$CURDIR/data_parquet/02960_polygon_bound_bug.parquet'); +CREATE DICTIONARY test_dict (geom MultiPolygon) PRIMARY KEY geom SOURCE (CLICKHOUSE(TABLE 'test_table')) LIFETIME(MIN 0 MAX 0) LAYOUT(POLYGON(STORE_POLYGON_KEY_COLUMN 1)); +SELECT dictHas(test_dict,(174.84729269276494,-36.99524960275426));" diff --git a/tests/queries/0_stateless/data_parquet/02960_polygon_bound_bug.parquet b/tests/queries/0_stateless/data_parquet/02960_polygon_bound_bug.parquet new file mode 100644 index 0000000000000000000000000000000000000000..b4aedb8f964f8130bf77da17a75017bba651cb61 GIT binary patch literal 1021 zcmWG=3^EjD5p@uC@e$<^We{Ru_#pV0`%BWQeaQzR5<WZ2MD=t;MMMQe*+ki7BsgF)5*#qSVhkEsL>Yj_v#|n6)<2*58JK_!5jG~) zfEU~hY7>}bM7bnQ8Q26QJ6O_F^K)5pGK)*tQ*%;tQ}ar2a~KUp`NTxT8kod7nA9@V zI7o4gqz=&Q45Ca7KtcdWF)*M9#j&a7HqSjx9jcNR&31?~bts<}yX4DSmjma&YDb(~ z>T&=xC}1ijIACf)L4hfXJt#zea51PYVPviaBmePGHW0gf4v9FqhrvM7{hVG!j~WsqPrgwjR~Vl0v} zk~)JVi42&?918#d literal 0 HcmV?d00001