Repository navigation
Three new simple but useful spatial functions - #144703
Conversation
* ST_Dimension (topological dimension) as in https://postgis.net/docs/ST_Dimension.html * ST_GeometryType (string name of geometry type) as in https://postgis.net/docs/ST_GeometryType.html * ST_IsEmpty (boolean) as in https://postgis.net/docs/ST_IsEmpty.html
|
Pinging @elastic/es-analytical-engine (Team:Analytics) |
|
Hi @craigtaverner, I've created a changelog YAML for you. |
ℹ️ Important: Docs version tagging👋 Thanks for updating the docs! Just a friendly reminder that our docs are now cumulative. This means all 9.x versions are documented on the same page and published off of the main branch, instead of creating separate pages for each minor version. We use applies_to tags to mark version-specific features and changes. Expand for a quick overviewWhen to use applies_to tags:✅ At the page level to indicate which products/deployments the content applies to (mandatory) What NOT to do:❌ Don't remove or replace information that applies to an older version 🤔 Need help?
|
…asticsearch into three_spatial_functions
This was previously a much larger change, based on double-checking that the constant block optimization actually made an improvement in macro benchmarks, which it did (a lot for ST_GEOMETRYTYPE and a small amount for ST_DIMENSION).
| - to: 'reference/query-languages/esql/functions-operators/spatial-functions/st_geometrytype.md' | ||
| anchors: {'esql-st_geometrytype'} | ||
| - to: 'reference/query-languages/esql/functions-operators/spatial-functions/st_dimension.md' | ||
| anchors: {'esql-st_dimension'} | ||
| - to: 'reference/query-languages/esql/functions-operators/spatial-functions/st_isempty.md' | ||
| anchors: {'esql-st_isempty'} |
There was a problem hiding this comment.
if these functions are new (e.g. docs content is not being moved from one location to another), then no redirects should be needed
There was a problem hiding this comment.
Thanks, removing them now.
ncordon
left a comment
There was a problem hiding this comment.
Left a few improvements but nothing major to correct
| for (Geometry geometry : collection) { | ||
| maxDimension = Math.max(maxDimension, geometry.visit(this)); | ||
| } |
There was a problem hiding this comment.
I think we could short circuit this is we are already at dimension 2?
if (maxDimension == 2) {
break;
}|
|
||
| @Override | ||
| public long baseRamBytesUsed() { | ||
| return field.baseRamBytesUsed(); |
There was a problem hiding this comment.
Shouldn't we include the shallow size here?
There was a problem hiding this comment.
Good catch. I've changed to to look more like what we see in StDimensionFromWKBEvaluator.
| case GEOMETRYCOLLECTION -> "ST_GeometryCollection"; | ||
| case LINEARRING -> "ST_LineString"; | ||
| case ENVELOPE -> "ST_Polygon"; | ||
| case CIRCLE -> "ST_Point"; |
There was a problem hiding this comment.
We discussed changing this to be a line (probably a St_Polygon?)
There was a problem hiding this comment.
Done! And I did a search for OGC compliance for the option of ST_Circle and that is not OGC compliant, so we stick with ST_Polygon.
| BytesRef wkb = wkbBlock.getBytesRef(firstValueIndex + i, scratch); | ||
| Geometry geometry = UNSPECIFIED.wkbToGeometry(wkb); | ||
| int dimension = geometry.visit(DIMENSION_VISITOR); | ||
| maxDimension = Math.max(maxDimension, dimension); |
There was a problem hiding this comment.
Same here, we could short circuit in the case we've reached the max dimension true?
There was a problem hiding this comment.
Great idea. I added an extra condition to the for loop a few lines above.
Three new simple but useful spatial functions, particularly when testing `ST_CENTROID_AGG` which takes topological dimension into account during aggregations: * `ST_Dimension` (topological dimension) * The topological dimension is 0 for points, 1 for lines and 2 for polygons. This is important in understanding how centroids are calculated in ST_CENTROID_AGG, where higher dimensions completely remove the contribution from lower ones. * See the PostGIS equivalent at https://postgis.net/docs/ST_Dimension.html * `ST_GeometryType` * A string name of the geometry type: ST_Point, ST_LineString, etc. * See the PostGIS equivalent at https://postgis.net/docs/ST_GeometryType.html * `ST_IsEmpty` * A boolean flag for whether the geometry is empty or not * See PostGIS equivalent at https://postgis.net/docs/ST_IsEmpty.html The `ST_GeometryType` and `ST_Dimension` functions also include a specific optimization for point types, since they will always return a constant values for all non-null results. This had a noticable effect on the macro-benchmarks results for the geopoint track: | Task | Without constant evaluator | With constant evaluator | Improvement | | --- | --- | --- | --- | | st-geometrytype-stats-esql | 462.121 | 98.4184 | 80% | | st-dimension-stats-esql | 159.484 | 150.169 | 6% | | st-isempty-stats-esql | 124.098 | 126.023 | 0% |
Three new simple but useful spatial functions, particularly when testing
ST_CENTROID_AGGwhich takes topological dimension into account during aggregations:ST_Dimension(topological dimension)ST_GeometryTypeST_IsEmptyThe
ST_GeometryTypeandST_Dimensionfunctions also include a specific optimization for point types, since they will always return a constant values for all non-null results. This had a noticable effect on the macro-benchmarks results for the geopoint track: