-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
geo: implement ST_Summary for Geography/Geometry #49738
Conversation
Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. I have added a few people who may be able to assist in reviewing:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for coming again and doing this!
few minor things :)
nit: title can just be geo: implement ST_Summary for Geography/Geometry
docs/generated/sql/functions.md
Outdated
@@ -1051,6 +1051,22 @@ has no relationship with the commit order of concurrent transactions.</p> | |||
</span></td></tr> | |||
<tr><td><a name="st_startpoint"></a><code>st_startpoint(geometry: geometry) → geometry</code></td><td><span class="funcdesc"><p>Returns the first point of a geometry which has shape LineString. Returns NULL if the geometry is not a LineString.</p> | |||
</span></td></tr> | |||
<tr><td><a name="st_summary"></a><code>st_summary(geography: geography) → <a href="string.html">string</a></code></td><td><span class="funcdesc"><p>Returns a text summary of the contents of the geography.</p> | |||
<p>Flags shown square brackets after the geometry type have the following meaning: | |||
M: has M coordinate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the generated text here will not look good in HTML.
if you add *
in front of these in the info string, these should appear as a HTML list, i.e.
* M: has M coordinate
* Z: has Z coordinate
* B: has a cached bounding box
* G: is geography
* S: has spatial reference system
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pkg/geo/summary.go
Outdated
// S: has spatial reference system | ||
func Summary(t geom.T, isGeography bool, offset int) (summary string, err error) { | ||
shape, err := geopbShape(t) | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we could pass in shape
from geometry.Shape()
or geography.Shape()
and avoid rechecking this again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pkg/geo/summary.go
Outdated
return "", err | ||
} | ||
|
||
f, err := flag(t, isGeography) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: flag name conflicts with package flag
and is a little vague. maybe summaryFlag
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pkg/geo/summary.go
Outdated
numLinearRings := t.NumLinearRings() | ||
|
||
summary += fmt.Sprintf("%s[%s] with %d ring", shape.String(), f, t.NumLinearRings()) | ||
if 1 < numLinearRings { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: easier to read this (and below) as numLinearRings > 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pkg/geo/summary.go
Outdated
|
||
for i := 0; i < numPoints; i++ { | ||
point := t.Point(i) | ||
tmp, err := Summary(point, isGeography, offset+2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the variable named tmp
here may be better named as line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pkg/geo/summary.go
Outdated
// B: has a cached bounding box | ||
// G: is geography | ||
// S: has spatial reference system | ||
func Summary(t geom.T, isGeography bool, offset int) (summary string, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: taking offset
as an initial argument for the public facing function makes the interface a little unfriendly as there is a dangling magic constant 0
.
Can we do something like:
func Summary(t geom.T, isGeography bool) (summary string, err error) {
return summary(t, isGeography, 0)
}
func summary(t geom.T, isGeography bool, spaceOffset int) (summary string, err error) {
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Thank you for updating your pull request. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
Thank you for the review!
Done. |
pkg/geo/summary.go
Outdated
|
||
return sum, nil | ||
default: | ||
return "", errors.Newf("unspport geom type: %T", t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've fixed this typo
pkg/geo/summary.go
Outdated
return summary(t, shape, isGeography, 0) | ||
} | ||
|
||
func summary(t geom.T, shape geopb.Shape, isGeography bool, offset int) (sum string, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed summaryLine
Fixes cockroachdb#48405, cockroachdb#49049 Release note (sql change): Implemented the geometry based builtins `ST_Summary`.
bors r+ |
Build succeeded |
Fixes #48405, #49049
Release note (sql change): Implemented the geometry based builtins
ST_Summary
.