Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geospatial queries for points #6562

Merged
merged 43 commits into from
May 8, 2023
Merged

Conversation

ironage
Copy link
Contributor

@ironage ironage commented May 2, 2023

Initial implementation of geospatial queries for points. Most of the code additions come from adding the s2 library to our code base. Other changes have been reviewed in separate PRs previously.

☑️ ToDos

  • 📝 Changelog update
  • 🚦 Tests (or not relevant)

kiburtse and others added 30 commits February 1, 2023 14:47
…ort_for_geowithin

Geospatial Polygon and CenterSphere support for geowithin operator
* 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
* 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>
kiburtse and others added 7 commits April 13, 2023 17:07
* 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 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>
* Allow to disable compilation of whole geospatial support
* Turn on the geo feature for swift build by default
* 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>
@kiburtse
Copy link
Contributor

kiburtse commented May 3, 2023

We should exclude somehow s2 from CodeFactor, right?

Copy link
Contributor

@jedelbo jedelbo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@nicola-cab nicola-cab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice.

@@ -152,6 +153,9 @@ static constexpr DataType type_OldDateTime = DataType{7};
static_assert(!type_OldTable.is_valid());
static_assert(!type_OldDateTime.is_valid());
static constexpr DataType type_TypeOfValue = DataType{18};
#if REALM_ENABLE_GEOSPATIAL
static constexpr DataType type_Geospatial = DataType{19};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will collide with nested collections, whoever gets first into master will have to adjust this value (nested collections are using 19,20,21) ... maybe we can agree to leave 19 free or whatever, also if we intend to keep this behind the GEOSPATIAL macro maybe it is better if we reserve the slot 22.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the heads up. The geospatial type is not part of the file format so its value doesn't really matter yet. I changed it to 22 so it doesn't conflict with nested collections.

src/realm/geospatial.hpp Outdated Show resolved Hide resolved
{
return !(*this == other);
}
bool operator>(const Geospatial&) const = delete;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to delete the operators? Is this done for better compiler error messages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we don't want to allow these kinds of comparisons and by deleting them we make sure that they aren't being used anywhere in the query system or elsewhere.

src/realm/util/file_mapper.cpp Outdated Show resolved Hide resolved
src/realm/util/serializer.hpp Show resolved Hide resolved
src/realm/utilities.hpp Outdated Show resolved Hide resolved
return true;
}

Geospatial Geospatial::from_obj(const Obj& obj, ColKey type_col, ColKey coords_col)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So a Geospatial type is a Obj which has a list of points (doubles) and a string to identify if it is longitude or latitude? Am I right? When it will come to deal with polygons, will you flatten a matrix into a list?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string is to identify what type of geometry is in this Geospatial type (polygon, line), but for now it's just 'point' which is supported. Second question is an open one. It remains to be seen how this is going to be implemented. Scope is yet to come for discussion.

Package.swift Outdated
@@ -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: "1"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the intention is to have this disabled until we expose it in the SDK then it needs to be set to 0 here (and in tools/build-cocoa.sh).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes thanks. I updated both places to disable it by default for cocoa builds.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there was such intention, we just added it this way to check that we can optionally disable whole geospatial if only through configure flag. Most of current implementation is useable without any work in sdks like rql queries on local data. Default was set to allow straight forward experimentation without official release of this feature.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cocoa does not use the core query parser.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right... @ironage i think that would need a bit more work to properly disable in in Package.swift. It's not just this define.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's a reason to disable it by default. It doesn't upgrade the file format and the feature existing wouldn't impact Cocoa users besides a slight binary size increase. Whether we increase the binary size today or in a month when we add support for the feature is most likely inconsequential for the majority of our users.

@ironage
Copy link
Contributor Author

ironage commented May 3, 2023

We should exclude somehow s2 from CodeFactor, right?

I updated the project settings over at codefactor.io to ignore src/external/** and src/realm/parser/generated/**

@nicola-cab nicola-cab self-requested a review May 5, 2023 17:41
@ironage ironage merged commit a4ff1b0 into master May 8, 2023
2 checks passed
@ironage ironage deleted the feature/geospatial_queries_for_points branch May 8, 2023 16:48
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants