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

geo: implement ST_Summary for Geography/Geometry #49738

Merged
merged 1 commit into from
Jun 1, 2020

Conversation

hueypark
Copy link
Contributor

@hueypark hueypark commented May 31, 2020

Fixes #48405, #49049

Release note (sql change): Implemented the geometry based builtins ST_Summary.

@blathers-crl
Copy link

blathers-crl bot commented May 31, 2020

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.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@blathers-crl blathers-crl bot added O-community Originated from the community X-blathers-triaged blathers was able to find an owner labels May 31, 2020
@blathers-crl blathers-crl bot requested a review from otan May 31, 2020 13:56
Copy link
Contributor

@otan otan left a 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

@@ -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) &rarr; 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) &rarr; <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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// 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 {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

return "", err
}

f, err := flag(t, isGeography)
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

numLinearRings := t.NumLinearRings()

summary += fmt.Sprintf("%s[%s] with %d ring", shape.String(), f, t.NumLinearRings())
if 1 < numLinearRings {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


for i := 0; i < numPoints; i++ {
point := t.Point(i)
tmp, err := Summary(point, isGeography, offset+2)
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// 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) {
Copy link
Contributor

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) {
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@hueypark hueypark changed the title geo/geo*fn: implement ST_Summary({geography}), implement ST_Summary({… geo: implement ST_Summary for Geography/Geometry Jun 1, 2020
@blathers-crl blathers-crl bot requested a review from otan June 1, 2020 12:42
@blathers-crl
Copy link

blathers-crl bot commented Jun 1, 2020

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.

@hueypark
Copy link
Contributor Author

hueypark commented Jun 1, 2020

Thank you for the review!

nit: title can just be geo: implement ST_Summary for Geography/Geometry

Done.


return sum, nil
default:
return "", errors.Newf("unspport geom type: %T", t)
Copy link
Contributor

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

return summary(t, shape, isGeography, 0)
}

func summary(t geom.T, shape geopb.Shape, isGeography bool, offset int) (sum string, err error) {
Copy link
Contributor

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`.
@otan
Copy link
Contributor

otan commented Jun 1, 2020

bors r+

@craig
Copy link
Contributor

craig bot commented Jun 1, 2020

Build succeeded

@craig craig bot merged commit e43d665 into cockroachdb:master Jun 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-community Originated from the community X-blathers-triaged blathers was able to find an owner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

geo/geogfn: implement ST_Summary({geography})
3 participants