Skip to content

Commit

Permalink
Geospatial queries for points (#6562)
Browse files Browse the repository at this point in the history
* Add s2geometry sources for geo queries support from mongodb repo as is

* s2: cleanup/remove unneeded files

* s2: add to build

* Add basic test for s2geometry link

* Object store Geospatial mappings

* starting queries

* s2: cleanup tests related functions

* Fix build due to removed error categories

* Replace std exceptions with realm specific

* Move geo query tests to separate test file for future expansion

* Add init types for polygon and center sphere

* Add basic geo_within support for Polygon and CenterSphere

* Fix windows build

* Style: rename geo constants

* Fix MacOS compatibility build issue

* More win/mac build fixes

* Add s2geometry library for swift package build

* Suppress s2 warnings for gcc

* fix clang-format complaint

* Trim down unnecessary S2 sources (#6456)

* integrate Realm logging and assertions

* remove some string utilities

* remove encoder/decoder

* remove some base files

* remove hash

* fix header search path for s2 swift builds

* Fix include of external when built as subproject of sdk

* Use modern language features (#6466)

* scoped_ptr -> std::unique_ptr

* use std type_traits

* Replace deprecated is_pod with is_trivial

---------

Co-authored-by: Kirill Burtsev <kirill.burtsev@mongodb.com>

* Use radians for CenterSphere to be unit-neutral (#6496)

* Don't use optional for sphere radius to reduce the size of Geospatial

* Use radians for CenterSphere radius, expose constant

* Add comments about points in Box and Polygon

* Don't construct optional needlessly on Geospatial comparison

* Geospatial RQL (#6352)

* geospatial query parser support WIP

* some error handling

* RQL geoSphere

* RQL geoPolygon

* query geospatial arguments

* C-API geospatial in mixed

* add a Geospatial type checking API

* format

* fix warnings on Windows

* Alternative syntax definition

* API changes from feedback and testing

* remove type_GeoPoint as Geospatial is an umbrella for this

* additional tests

* fix an unused warning

* review feedback

* Use NaN for GeoPoint (#6490)

* Use NaN for altitude, expose to public

* Check for NaN for lat/lon

---------

Co-authored-by: James Stone <james.stone@mongodb.com>

* formatting

* remove GeospatialRef and use Geospatial* remove wrong C-API implementation (#6518)

---------

Co-authored-by: Jørgen Edelbo <jorgen.edelbo@mongodb.com>
Co-authored-by: Kirill Burtsev <kirill.burtsev@mongodb.com>

* Add REALM_ENABLE_GEOSPATIAL cmake option to disable feature (#6525)

* Allow to disable compilation of whole geospatial support
* Turn on the geo feature for swift build by default

* Remove non-compiling hash_value function (#6533)

* Geospatial Polygons support holes (#6529)

* Geospatial uses a variant polygon has holes

* support holes in polygons in RQL

* touch ups

* Add REALM_ENABLE_GEOSPATIAL to config.h

* add missing include

* Fix test build for geo feature, optimize copying (#6550)

* Fix build without geospatial

* Don't force to copy primitives on get<>

* Allow less curly braces for GeoPolygon on init

* format

---------

Co-authored-by: Jørgen Edelbo <jorgen.edelbo@mongodb.com>
Co-authored-by: Kirill Burtsev <kirill.burtsev@mongodb.com>

* changelog and test without geospatial on CI

* disable geospatial by default for cocoa builds, review feedback

* turn off geospatial in swift builds for now

* formatting

---------

Co-authored-by: Kirill Burtsev <kirill.burtsev@mongodb.com>
Co-authored-by: Jørgen Edelbo <jorgen.edelbo@mongodb.com>
Co-authored-by: Nikola Irinchev <irinchev@me.com>
  • Loading branch information
4 people committed May 8, 2023
1 parent a546bd4 commit a4ff1b0
Show file tree
Hide file tree
Showing 104 changed files with 21,861 additions and 1,076 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# NEXT RELEASE

### Enhancements
* <New feature description> (PR [#????](https://github.com/realm/realm-core/pull/????))
* None.
* The query engine now supports `geowithin` queries on points. Points are embedded objects conforming to the geoJSON format, trying to use a geospatial query on data in the incorrect format produces a run time exception. Example RQL query: `location geoWithin geoPolygon({{-178.0, 10.0}, {178.0, 10.0}, {178.0, -10.0}, {-178.0, -10.0}, {-178.0, 10.0}})`. For SDKs who do not wish to add this yet, the feature can be compiled out by adding `-DREALM_ENABLE_GEOSPATIAL=OFF` to the cmake config. ([#6562](https://github.com/realm/realm-core/issues/6562))

### Fixed
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
Expand Down
20 changes: 14 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ elseif(APPLE)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
endif()

# Sets/clears the {FLAG} variable if the compiler flag is supported or not
# The compiler flag check is only performed once and the value is cached as the out variable name
function(check_if_cxx_compiler_flag_supported flag out_var)
if(flag MATCHES "^-Wno-")
# Compilers ignore unknown -Wno-foo flags, so look for -Wfoo instead.
Expand All @@ -58,8 +56,8 @@ function(check_if_cxx_compiler_flag_supported flag out_var)
endfunction()

function(add_cxx_flag_if_supported flag)
check_if_cxx_compiler_flag_supported(${flag} HAVE${flag})
if(HAVE${flag})
check_if_cxx_compiler_flag_supported(${flag} HAVE_${flag})
if(HAVE_${flag})
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:${flag}>)
endif()
endfunction()
Expand Down Expand Up @@ -91,6 +89,15 @@ function(append_source_file_compile_options)
endforeach()
endfunction()

function(add_target_option_if_supported target option_scope)
foreach(option ${ARGN})
check_if_cxx_compiler_flag_supported(${option} HAVE_${option})
if(HAVE_${option})
target_compile_options(${target} ${option_scope} ${option})
endif()
endforeach()
endfunction()

function(use_faster_linker)
# If a linker has already been set, don't override.
if ("${CMAKE_EXE_LINKER_FLAGS}" MATCHES "-fuse-ld=")
Expand Down Expand Up @@ -125,7 +132,7 @@ else()
if(ANDROID)
add_compile_options(-Wno-uninitialized)
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES ".*[Cc]lang")
# FIXME: Re-introduce -Wold-style-cast
# FIXME: Re-introduce -Wold-style-cast
add_compile_options(-Wunreachable-code -Wshorten-64-to-32 -Wconditional-uninitialized -Wextra-semi -Wno-nested-anon-types -Wdocumentation -Wthread-safety -Wthread-safety-negative -Wmissing-prototypes)
endif()

Expand Down Expand Up @@ -162,7 +169,7 @@ if(ANDROID)
# - `-fomit-frame-pointer` is inherited from NDK r10e.
# - On some architectures char is unsigned by default. Make it signed
# - Compile with -Oz in Release because on Android we favor code size over performance
#
#
add_compile_options(-fdata-sections -ffunction-sections -fomit-frame-pointer -fsigned-char -fstrict-aliasing -funwind-tables -no-canonical-prefixes $<$<CONFIG:Release>:-Oz>)
endif()

Expand Down Expand Up @@ -248,6 +255,7 @@ option(REALM_METRICS "Enable various metric tracking" ON)
option(REALM_INCLUDE_CERTS "Include a list of trust certificates in the build for SSL certificate verification" ${REALM_INCLUDE_CERTS_DEFAULT})
option(REALM_ENABLE_SYNC_MULTIPLEXING "Enables sync session multi-plexing by default")
set(REALM_MAX_BPNODE_SIZE "1000" CACHE STRING "Max B+ tree node size.")
option(REALM_ENABLE_GEOSPATIAL "Enable geospatial types and queries." ON)

# Find dependencies
set(THREADS_PREFER_PTHREAD_FLAG ON)
Expand Down
15 changes: 14 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var cxxSettings: [CXXSetting] = [
.define("REALM_ENABLE_ASSERTIONS", to: "1"),
.define("REALM_ENABLE_ENCRYPTION", to: "1"),
.define("REALM_ENABLE_SYNC", to: "1"),
.define("REALM_ENABLE_GEOSPATIAL", to: "0"),

.define("REALM_VERSION_MAJOR", to: String(versionCompontents[0])),
.define("REALM_VERSION_MINOR", to: String(versionCompontents[1])),
Expand Down Expand Up @@ -386,6 +387,14 @@ let package = Package(
exclude: bidExcludes,
publicHeadersPath: "."
),
.target(
name: "s2geometry",
path: "src/external/s2",
publicHeadersPath: ".",
cxxSettings: ([
.headerSearchPath(".."),
.headerSearchPath("../.."),
] + cxxSettings) as [CXXSetting]),
.target(
name: "RealmCore",
dependencies: ["Bid"],
Expand All @@ -395,6 +404,7 @@ let package = Package(
"external",
"realm/CMakeLists.txt",
"realm/exec",
"realm/geospatial.cpp",
"realm/metrics",
"realm/object-store/CMakeLists.txt",
"realm/object-store/c_api",
Expand All @@ -410,7 +420,9 @@ let package = Package(
"win32",
] + syncExcludes + syncServerSources) as [String],
publicHeadersPath: ".",
cxxSettings: cxxSettings,
cxxSettings: ([
.headerSearchPath("external"),
] + cxxSettings) as [CXXSetting],
linkerSettings: [
.linkedLibrary("compression"),
.linkedLibrary("z"),
Expand Down Expand Up @@ -515,6 +527,7 @@ let package = Package(
"backup.cpp",
"benchmarks",
"c_api",
"geospatial.cpp",
"notifications-fuzzer",
"query.json",
"sync-metadata-v4.realm",
Expand Down
3 changes: 2 additions & 1 deletion evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ buildvariants:
run_tests_against_baas: On
c_compiler: "./clang_binaries/bin/clang"
cxx_compiler: "./clang_binaries/bin/clang++"
extra_flags: -DREALM_ENABLE_GEOSPATIAL=OFF # can be removed once SDKs pick this feature up
tasks:
- name: compile_test

Expand Down Expand Up @@ -1245,7 +1246,7 @@ buildvariants:
max_jobs: $(sysctl -n hw.logicalcpu)
run_tests_against_baas: On
xcode_developer_dir: /Applications/Xcode13.1.app/Contents/Developer
extra_flags: -DCMAKE_SYSTEM_NAME=Darwin -DCMAKE_OSX_ARCHITECTURES=arm64
extra_flags: -DCMAKE_SYSTEM_NAME=Darwin -DCMAKE_OSX_ARCHITECTURES=arm64 -DREALM_ENABLE_GEOSPATIAL=OFF
tasks:
- name: compile_test
distros:
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
add_subdirectory(realm)
add_subdirectory(external/IntelRDFPMathLib20U2)

if (REALM_ENABLE_GEOSPATIAL)
add_subdirectory(external/s2)
endif()

if(CMAKE_SYSTEM_NAME MATCHES "^Windows")
add_subdirectory(win32)
endif()
Expand Down
60 changes: 60 additions & 0 deletions src/external/s2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
cmake_minimum_required(VERSION 3.15)

project(s2geometry)

set(S2_SOURCES
s1angle.cc
s2.cc
s2cellid.cc
s2latlng.cc
s1interval.cc
s2cap.cc
s2cell.cc
s2cellunion.cc
s2edgeindex.cc
s2edgeutil.cc
s2latlngrect.cc
s2loop.cc
s2pointregion.cc
s2polygon.cc
s2polygonbuilder.cc
s2polyline.cc
s2r2rect.cc
s2region.cc
s2regioncoverer.cc
s2regionintersection.cc
s2regionunion.cc
)

set(S2_UTIL_MATH_SOURCES
util/math/mathutil.cc
util/math/mathlimits.cc
)

add_library(s2geometry OBJECT
${S2_SOURCES}
${S2_UTIL_MATH_SOURCES}
)

target_include_directories(s2geometry PRIVATE "." "..")

# suppress s2 specific warnings (lib is very noisy)
target_compile_options(s2geometry PRIVATE
$<$<CXX_COMPILER_ID:MSVC>: /wd4068 /wd4244 /wd4267 /wd4305>
)
if (NOT MSVC)
set(CMAKE_REQUIRED_QUIET ON)
add_target_option_if_supported(s2geometry PRIVATE
-Wno-deprecated-declarations
-Wno-ignored-qualifiers
-Wno-macro-redefined
-Wno-missing-prototypes
-Wno-shorten-64-to-32
-Wno-undefined-var-template
-Wno-unknown-pragmas
-Wno-unused-const-variable
-Wno-unused-function
-Wno-unused-local-typedefs
-Wno-unused-parameter
)
endif()
Loading

0 comments on commit a4ff1b0

Please sign in to comment.