add tests

This commit is contained in:
Andr0901 2021-05-28 10:48:31 +03:00 committed by Nikita Mikhaylov
parent 12219391d6
commit 4d75450e54
18 changed files with 160 additions and 119 deletions

2
.gitmodules vendored
View File

@ -233,4 +233,4 @@
url = https://github.com/azadkuh/sqlite-amalgamation
[submodule "contrib/s2geometry"]
path = contrib/s2geometry
url = https://github.com/google/s2geometry
url = https://github.com/Andr0901/s2geometry

View File

@ -541,6 +541,7 @@ include (cmake/find/rocksdb.cmake)
include (cmake/find/libpqxx.cmake)
include (cmake/find/nuraft.cmake)
include (cmake/find/yaml-cpp.cmake)
include (cmake/find/s2.cmake)
if(NOT USE_INTERNAL_PARQUET_LIBRARY)
set (ENABLE_ORC OFF CACHE INTERNAL "")

2
cmake/find/s2.cmake Normal file
View File

@ -0,0 +1,2 @@
set(S2_LIBRARY s2)
set(S2_INCLUDE_DIR "${ClickHouse_INCLUDE_DIR}/contrib/s2geometry/src/s2")

1
contrib/s2geometry vendored Submodule

@ -0,0 +1 @@
Subproject commit edb633953802966aa04bb3805a9b106b4fe5dddc

View File

@ -0,0 +1,123 @@
set(S2_SOURCE_DIR "${ClickHouse_SOURCE_DIR}/contrib/s2geometry/src/s2")
set(S2_BINARY_DIR "${ClickHouse_SOURCE_DIR}/contrib/s2geometry/src/s2")
set(S2_SRCS
"${S2_SOURCE_DIR}/base/stringprintf.cc"
"${S2_SOURCE_DIR}/base/strtoint.cc"
"${S2_SOURCE_DIR}/encoded_s2cell_id_vector.cc"
"${S2_SOURCE_DIR}/encoded_s2point_vector.cc"
"${S2_SOURCE_DIR}/encoded_s2shape_index.cc"
"${S2_SOURCE_DIR}/encoded_string_vector.cc"
"${S2_SOURCE_DIR}/id_set_lexicon.cc"
"${S2_SOURCE_DIR}/mutable_s2shape_index.cc"
"${S2_SOURCE_DIR}/r2rect.cc"
"${S2_SOURCE_DIR}/s1angle.cc"
"${S2_SOURCE_DIR}/s1chord_angle.cc"
"${S2_SOURCE_DIR}/s1interval.cc"
"${S2_SOURCE_DIR}/s2boolean_operation.cc"
"${S2_SOURCE_DIR}/s2builder.cc"
"${S2_SOURCE_DIR}/s2builder_graph.cc"
"${S2_SOURCE_DIR}/s2builderutil_closed_set_normalizer.cc"
"${S2_SOURCE_DIR}/s2builderutil_find_polygon_degeneracies.cc"
"${S2_SOURCE_DIR}/s2builderutil_lax_polygon_layer.cc"
"${S2_SOURCE_DIR}/s2builderutil_s2point_vector_layer.cc"
"${S2_SOURCE_DIR}/s2builderutil_s2polygon_layer.cc"
"${S2_SOURCE_DIR}/s2builderutil_s2polyline_layer.cc"
"${S2_SOURCE_DIR}/s2builderutil_s2polyline_vector_layer.cc"
"${S2_SOURCE_DIR}/s2builderutil_snap_functions.cc"
"${S2_SOURCE_DIR}/s2cap.cc"
"${S2_SOURCE_DIR}/s2cell.cc"
"${S2_SOURCE_DIR}/s2cell_id.cc"
"${S2_SOURCE_DIR}/s2cell_index.cc"
"${S2_SOURCE_DIR}/s2cell_union.cc"
"${S2_SOURCE_DIR}/s2centroids.cc"
"${S2_SOURCE_DIR}/s2closest_cell_query.cc"
"${S2_SOURCE_DIR}/s2closest_edge_query.cc"
"${S2_SOURCE_DIR}/s2closest_point_query.cc"
"${S2_SOURCE_DIR}/s2contains_vertex_query.cc"
"${S2_SOURCE_DIR}/s2convex_hull_query.cc"
"${S2_SOURCE_DIR}/s2coords.cc"
"${S2_SOURCE_DIR}/s2crossing_edge_query.cc"
"${S2_SOURCE_DIR}/s2debug.cc"
"${S2_SOURCE_DIR}/s2earth.cc"
"${S2_SOURCE_DIR}/s2edge_clipping.cc"
"${S2_SOURCE_DIR}/s2edge_crosser.cc"
"${S2_SOURCE_DIR}/s2edge_crossings.cc"
"${S2_SOURCE_DIR}/s2edge_distances.cc"
"${S2_SOURCE_DIR}/s2edge_tessellator.cc"
"${S2_SOURCE_DIR}/s2error.cc"
"${S2_SOURCE_DIR}/s2furthest_edge_query.cc"
"${S2_SOURCE_DIR}/s2latlng.cc"
"${S2_SOURCE_DIR}/s2latlng_rect.cc"
"${S2_SOURCE_DIR}/s2latlng_rect_bounder.cc"
"${S2_SOURCE_DIR}/s2lax_loop_shape.cc"
"${S2_SOURCE_DIR}/s2lax_polygon_shape.cc"
"${S2_SOURCE_DIR}/s2lax_polyline_shape.cc"
"${S2_SOURCE_DIR}/s2loop.cc"
"${S2_SOURCE_DIR}/s2loop_measures.cc"
"${S2_SOURCE_DIR}/s2measures.cc"
"${S2_SOURCE_DIR}/s2metrics.cc"
"${S2_SOURCE_DIR}/s2max_distance_targets.cc"
"${S2_SOURCE_DIR}/s2min_distance_targets.cc"
"${S2_SOURCE_DIR}/s2padded_cell.cc"
"${S2_SOURCE_DIR}/s2point_compression.cc"
"${S2_SOURCE_DIR}/s2point_region.cc"
"${S2_SOURCE_DIR}/s2pointutil.cc"
"${S2_SOURCE_DIR}/s2polygon.cc"
"${S2_SOURCE_DIR}/s2polyline.cc"
"${S2_SOURCE_DIR}/s2polyline_alignment.cc"
"${S2_SOURCE_DIR}/s2polyline_measures.cc"
"${S2_SOURCE_DIR}/s2polyline_simplifier.cc"
"${S2_SOURCE_DIR}/s2predicates.cc"
"${S2_SOURCE_DIR}/s2projections.cc"
"${S2_SOURCE_DIR}/s2r2rect.cc"
"${S2_SOURCE_DIR}/s2region.cc"
"${S2_SOURCE_DIR}/s2region_term_indexer.cc"
"${S2_SOURCE_DIR}/s2region_coverer.cc"
"${S2_SOURCE_DIR}/s2region_intersection.cc"
"${S2_SOURCE_DIR}/s2region_union.cc"
"${S2_SOURCE_DIR}/s2shape_index.cc"
"${S2_SOURCE_DIR}/s2shape_index_buffered_region.cc"
"${S2_SOURCE_DIR}/s2shape_index_measures.cc"
"${S2_SOURCE_DIR}/s2shape_measures.cc"
"${S2_SOURCE_DIR}/s2shapeutil_build_polygon_boundaries.cc"
"${S2_SOURCE_DIR}/s2shapeutil_coding.cc"
"${S2_SOURCE_DIR}/s2shapeutil_contains_brute_force.cc"
"${S2_SOURCE_DIR}/s2shapeutil_edge_iterator.cc"
"${S2_SOURCE_DIR}/s2shapeutil_get_reference_point.cc"
"${S2_SOURCE_DIR}/s2shapeutil_range_iterator.cc"
"${S2_SOURCE_DIR}/s2shapeutil_visit_crossing_edge_pairs.cc"
"${S2_SOURCE_DIR}/s2text_format.cc"
"${S2_SOURCE_DIR}/s2wedge_relations.cc"
"${S2_SOURCE_DIR}/strings/ostringstream.cc"
"${S2_SOURCE_DIR}/strings/serialize.cc"
"${S2_SOURCE_DIR}/third_party/absl/base/dynamic_annotations.cc"
"${S2_SOURCE_DIR}/third_party/absl/base/internal/raw_logging.cc"
"${S2_SOURCE_DIR}/third_party/absl/base/internal/throw_delegate.cc"
"${S2_SOURCE_DIR}/third_party/absl/numeric/int128.cc"
"${S2_SOURCE_DIR}/third_party/absl/strings/ascii.cc"
"${S2_SOURCE_DIR}/third_party/absl/strings/match.cc"
"${S2_SOURCE_DIR}/third_party/absl/strings/numbers.cc"
"${S2_SOURCE_DIR}/third_party/absl/strings/str_cat.cc"
"${S2_SOURCE_DIR}/third_party/absl/strings/str_split.cc"
"${S2_SOURCE_DIR}/third_party/absl/strings/string_view.cc"
"${S2_SOURCE_DIR}/third_party/absl/strings/strip.cc"
"${S2_SOURCE_DIR}/third_party/absl/strings/internal/memutil.cc"
"${S2_SOURCE_DIR}/util/bits/bit-interleave.cc"
"${S2_SOURCE_DIR}/util/bits/bits.cc"
"${S2_SOURCE_DIR}/util/coding/coder.cc"
"${S2_SOURCE_DIR}/util/coding/varint.cc"
"${S2_SOURCE_DIR}/util/math/exactfloat/exactfloat.cc"
"${S2_SOURCE_DIR}/util/math/mathutil.cc"
"${S2_SOURCE_DIR}/util/units/length-units.cc"
)
add_library(s2 ${S2_SRCS})
target_include_directories(s2 SYSTEM PUBLIC "${S2_SOURCE_DIR}/")
target_include_directories(s2 SYSTEM PUBLIC "${S2_SOURCE_DIR}/")
if(M_LIBRARY)
target_link_libraries(s2 PRIVATE ${M_LIBRARY})
endif()

View File

@ -1,116 +0,0 @@
set(S2_LIBRARY_DIR "${ClickHouse_SOURCE_DIR}/contrib/s2geometry/src/s2")
set(S2_SRCS
"${S2_LIBRARY_DIR}/base/stringprintf.cc"
"${S2_LIBRARY_DIR}/base/strtoint.cc"
"${S2_LIBRARY_DIR}/encoded_s2cell_id_vector.cc"
"${S2_LIBRARY_DIR}/encoded_s2point_vector.cc"
"${S2_LIBRARY_DIR}/encoded_s2shape_index.cc"
"${S2_LIBRARY_DIR}/encoded_string_vector.cc"
"${S2_LIBRARY_DIR}/id_set_lexicon.cc"
"${S2_LIBRARY_DIR}/mutable_s2shape_index.cc"
"${S2_LIBRARY_DIR}/r2rect.cc"
"${S2_LIBRARY_DIR}/s1angle.cc"
"${S2_LIBRARY_DIR}/s1chord_angle.cc"
"${S2_LIBRARY_DIR}/s1interval.cc"
"${S2_LIBRARY_DIR}/s2boolean_operation.cc"
"${S2_LIBRARY_DIR}/s2builder.cc"
"${S2_LIBRARY_DIR}/s2builder_graph.cc"
"${S2_LIBRARY_DIR}/s2builderutil_closed_set_normalizer.cc"
"${S2_LIBRARY_DIR}/s2builderutil_find_polygon_degeneracies.cc"
"${S2_LIBRARY_DIR}/s2builderutil_lax_polygon_layer.cc"
"${S2_LIBRARY_DIR}/s2builderutil_s2point_vector_layer.cc"
"${S2_LIBRARY_DIR}/s2builderutil_s2polygon_layer.cc"
"${S2_LIBRARY_DIR}/s2builderutil_s2polyline_layer.cc"
"${S2_LIBRARY_DIR}/s2builderutil_s2polyline_vector_layer.cc"
"${S2_LIBRARY_DIR}/s2builderutil_snap_functions.cc"
"${S2_LIBRARY_DIR}/s2cap.cc"
"${S2_LIBRARY_DIR}/s2cell.cc"
"${S2_LIBRARY_DIR}/s2cell_id.cc"
"${S2_LIBRARY_DIR}/s2cell_index.cc"
"${S2_LIBRARY_DIR}/s2cell_union.cc"
"${S2_LIBRARY_DIR}/s2centroids.cc"
"${S2_LIBRARY_DIR}/s2closest_cell_query.cc"
"${S2_LIBRARY_DIR}/s2closest_edge_query.cc"
"${S2_LIBRARY_DIR}/s2closest_point_query.cc"
"${S2_LIBRARY_DIR}/s2contains_vertex_query.cc"
"${S2_LIBRARY_DIR}/s2convex_hull_query.cc"
"${S2_LIBRARY_DIR}/s2coords.cc"
"${S2_LIBRARY_DIR}/s2crossing_edge_query.cc"
"${S2_LIBRARY_DIR}/s2debug.cc"
"${S2_LIBRARY_DIR}/s2earth.cc"
"${S2_LIBRARY_DIR}/s2edge_clipping.cc"
"${S2_LIBRARY_DIR}/s2edge_crosser.cc"
"${S2_LIBRARY_DIR}/s2edge_crossings.cc"
"${S2_LIBRARY_DIR}/s2edge_distances.cc"
"${S2_LIBRARY_DIR}/s2edge_tessellator.cc"
"${S2_LIBRARY_DIR}/s2error.cc"
"${S2_LIBRARY_DIR}/s2furthest_edge_query.cc"
"${S2_LIBRARY_DIR}/s2latlng.cc"
"${S2_LIBRARY_DIR}/s2latlng_rect.cc"
"${S2_LIBRARY_DIR}/s2latlng_rect_bounder.cc"
"${S2_LIBRARY_DIR}/s2lax_loop_shape.cc"
"${S2_LIBRARY_DIR}/s2lax_polygon_shape.cc"
"${S2_LIBRARY_DIR}/s2lax_polyline_shape.cc"
"${S2_LIBRARY_DIR}/s2loop.cc"
"${S2_LIBRARY_DIR}/s2loop_measures.cc"
"${S2_LIBRARY_DIR}/s2measures.cc"
"${S2_LIBRARY_DIR}/s2metrics.cc"
"${S2_LIBRARY_DIR}/s2max_distance_targets.cc"
"${S2_LIBRARY_DIR}/s2min_distance_targets.cc"
"${S2_LIBRARY_DIR}/s2padded_cell.cc"
"${S2_LIBRARY_DIR}/s2point_compression.cc"
"${S2_LIBRARY_DIR}/s2point_region.cc"
"${S2_LIBRARY_DIR}/s2pointutil.cc"
"${S2_LIBRARY_DIR}/s2polygon.cc"
"${S2_LIBRARY_DIR}/s2polyline.cc"
"${S2_LIBRARY_DIR}/s2polyline_alignment.cc"
"${S2_LIBRARY_DIR}/s2polyline_measures.cc"
"${S2_LIBRARY_DIR}/s2polyline_simplifier.cc"
"${S2_LIBRARY_DIR}/s2predicates.cc"
"${S2_LIBRARY_DIR}/s2projections.cc"
"${S2_LIBRARY_DIR}/s2r2rect.cc"
"${S2_LIBRARY_DIR}/s2region.cc"
"${S2_LIBRARY_DIR}/s2region_term_indexer.cc"
"${S2_LIBRARY_DIR}/s2region_coverer.cc"
"${S2_LIBRARY_DIR}/s2region_intersection.cc"
"${S2_LIBRARY_DIR}/s2region_union.cc"
"${S2_LIBRARY_DIR}/s2shape_index.cc"
"${S2_LIBRARY_DIR}/s2shape_index_buffered_region.cc"
"${S2_LIBRARY_DIR}/s2shape_index_measures.cc"
"${S2_LIBRARY_DIR}/s2shape_measures.cc"
"${S2_LIBRARY_DIR}/s2shapeutil_build_polygon_boundaries.cc"
"${S2_LIBRARY_DIR}/s2shapeutil_coding.cc"
"${S2_LIBRARY_DIR}/s2shapeutil_contains_brute_force.cc"
"${S2_LIBRARY_DIR}/s2shapeutil_edge_iterator.cc"
"${S2_LIBRARY_DIR}/s2shapeutil_get_reference_point.cc"
"${S2_LIBRARY_DIR}/s2shapeutil_range_iterator.cc"
"${S2_LIBRARY_DIR}/s2shapeutil_visit_crossing_edge_pairs.cc"
"${S2_LIBRARY_DIR}/s2text_format.cc"
"${S2_LIBRARY_DIR}/s2wedge_relations.cc"
"${S2_LIBRARY_DIR}/strings/ostringstream.cc"
"${S2_LIBRARY_DIR}/strings/serialize.cc"
"${S2_LIBRARY_DIR}/third_party/absl/base/dynamic_annotations.cc"
"${S2_LIBRARY_DIR}/third_party/absl/base/internal/raw_logging.cc"
"${S2_LIBRARY_DIR}/third_party/absl/base/internal/throw_delegate.cc"
"${S2_LIBRARY_DIR}/third_party/absl/numeric/int128.cc"
"${S2_LIBRARY_DIR}/third_party/absl/strings/ascii.cc"
"${S2_LIBRARY_DIR}/third_party/absl/strings/match.cc"
"${S2_LIBRARY_DIR}/third_party/absl/strings/numbers.cc"
"${S2_LIBRARY_DIR}/third_party/absl/strings/str_cat.cc"
"${S2_LIBRARY_DIR}/third_party/absl/strings/str_split.cc"
"${S2_LIBRARY_DIR}/third_party/absl/strings/string_view.cc"
"${S2_LIBRARY_DIR}/third_party/absl/strings/strip.cc"
"${S2_LIBRARY_DIR}/third_party/absl/strings/internal/memutil.cc"
"${S2_LIBRARY_DIR}/util/bits/bit-interleave.cc"
"${S2_LIBRARY_DIR}/util/bits/bits.cc"
"${S2_LIBRARY_DIR}/util/coding/coder.cc"
"${S2_LIBRARY_DIR}/util/coding/varint.cc"
"${S2_LIBRARY_DIR}/util/math/exactfloat/exactfloat.cc"
"${S2_LIBRARY_DIR}/util/math/mathutil.cc"
"${S2_LIBRARY_DIR}/util/units/length-units.cc"
)
add_library(s2 ${S2_SRCS})
target_include_directories(s2 SYSTEM PUBLIC "${S2_SOURCE_DIR}/")

View File

@ -125,4 +125,6 @@ endif()
# Signed integer overflow on user-provided data inside boost::geometry - ignore.
set_source_files_properties("pointInPolygon.cpp" PROPERTIES COMPILE_FLAGS -fno-sanitize=signed-integer-overflow)
target_link_libraries(clickhouse_functions PRIVATE ${S2_SOURCE_DIR})
# target_link_libraries(clickhouse_functions PRIVATE ${S2_LIBRARY})
target_include_directories(clickhouse_functions SYSTEM PRIVATE ${S2_INCLUDE_DIR})

View File

@ -90,7 +90,7 @@ public:
S2Point point = cell_id.ToPoint();
S2LatLng ll(point);
vec_res_first[row] = ll.lat().degrees();
vec_res_first[row] = ll.lng().degrees();
vec_res_second[row] = ll.lat().degrees();
}

View File

@ -0,0 +1,4 @@
4573520603753569857
4573517609713934091
4035225266123964415
936559659395828129

View File

@ -0,0 +1,4 @@
select degreesToS2(55.77922738, 37.63098076);
select degreesToS2(55.76324100, 37.66018300);
select degreesToS2(90, 45);
select degreesToS2(-12, 34);

View File

@ -0,0 +1,4 @@
4573520603753570041
4573517609713934377
4035225266123964527
936559659395827967

View File

@ -0,0 +1,4 @@
select radiansToS2(0.97353117, 0.65678451)
select radiansToS2(0.97325215, 0.65729419)
select radiansToS2(1.57079632, 0.78539816)
select radiansToS2(-0.20943951, 0.59341194)

View File

@ -0,0 +1,4 @@
(55.7792274, 37.6309808)
(55.7632410, 37.6601830)
(90.0000000, 45.0000000)
(34.0000000, -12.0000000)

View File

@ -0,0 +1,2 @@
select S2ToGeo(4573520603753570041)
select S2ToGeo(4573517609713934091)

View File

@ -0,0 +1 @@
[5074766987100422144,5074766712222515200,5074767536856236032,5074767261978329088]

View File

@ -0,0 +1 @@
select S2GetNeigbors(5074766849661468672)

View File

@ -0,0 +1,2 @@
1
0

View File

@ -0,0 +1,2 @@
select S2CellsIntersect(9926595209846587392, 9926594385212866560)
select S2CellsIntersect(9926595209846587392, 9937259648002293760)