Does Datomic have location queries?
Code/data locality gets you really far
Datomic Pro can support advanced location queries without up-front support, due to the idea of code/data locality. To get code/data locality in RDBMS you have to write stored procedures. In Datomic, your application process gets code/data locality which means your application process can do strictly more than a stored procedure could do in RDBMS. Location queries exploit this property of Datomic.
In Datomic Pro, queries evaluate in your application process and have access to application functions and in-memory data structures. This is called "code/data locality" in Datomic Peer model.
DANIEL JOMPHE: 1.2.2 Locations can request the results of big queries that span over the entire, merged multi-location dataset.STUART HALLOWAY: Datomic should be very good at this, automatically caching the data needed based on usage patterns.
Location queries in Datomic will leverage code/data locality in two ways:
1) the query engine can call application functions and do math
BOBBY CALDERWOOD: Datomic's query engine supports the use of native functions within queries. So the use of (>, <, etc.) plus your own bounding-box and radius geometry functions on indexed long or float attributes would get you part of the way there.
VAL WAESELYNCK: You can't directly run a query like "find all \<point entities> within X miles of \<point>". However, you can have an external function (great-circle-distance lat1 lng1 lat2 lng2) that you call from Datalog. As an optimization, you can compute a rectangular bounding box, which Datalog should be able to optimize using range optimization.
2) the query engine can be passed a custom database index implementation, optimized for location
GARY JOHNSON: Although I could imagine even going so far as to replicate most of the geometry/raster functionality provided by PostGIS, the unfortunate missing ingredient in all of this is a native spatial index.
R-tree is the data structure for multi-dimensional indexes like lat/long coordinates. Datomic does not natively have this.
VAL WAESELYNCK: No, but there's not much to it. You would just build an in-memory specialized data structure prior to querying, then pass it as a parameter of your Datalog query and call it using regular function calls.
What about Datomic Cloud?
It's not clear yet, we will know more when Cloud is released. Cloud has architecture changes impacting the code/data locality story (it is not worse, it is just different). I spoke to Rich and Stu in depth at Conj '17, I'll publish those notes when Datomic Cloud is released.