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

builtins: add ST_RelatePattern #51858

Merged
merged 1 commit into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/generated/sql/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,8 @@ Negative azimuth values and values greater than 2π (360 degrees) are supported.
<tr><td><a name="st_relate"></a><code>st_relate(geometry_a: geometry, geometry_b: geometry, pattern: <a href="string.html">string</a>) &rarr; <a href="bool.html">bool</a></code></td><td><span class="funcdesc"><p>Returns whether the DE-9IM spatial relation between geometry_a and geometry_b matches the DE-9IM pattern.</p>
<p>This function utilizes the GEOS module.</p>
</span></td></tr>
<tr><td><a name="st_relatematch"></a><code>st_relatematch(intersection_matrix: <a href="string.html">string</a>, pattern: <a href="string.html">string</a>) &rarr; <a href="bool.html">bool</a></code></td><td><span class="funcdesc"><p>Returns whether the given DE-9IM intersection matrix satisfies the given pattern.</p>
</span></td></tr>
<tr><td><a name="st_segmentize"></a><code>st_segmentize(geography: geography, max_segment_length_meters: <a href="float.html">float</a>) &rarr; geography</code></td><td><span class="funcdesc"><p>Returns a modified Geography having no segment longer than the given max_segment_length meters.</p>
<p>The calculations are done on a sphere.</p>
<p>This function utilizes the S2 library for spherical calculations.</p>
Expand Down
11 changes: 11 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/geospatial
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,17 @@ SELECT ST_NPoints(ST_Buffer('SRID=4326;POINT(0 0)', 10.0))
33

# DE-9IM relations
query B
SELECT
ST_RelateMatch(m, pattern)
FROM ( VALUES
('101202FFF', 'TTTTTTFFF'),
('101202FTF', 'TTTTTTFFF')
) tbl(m, pattern)
----
true
false

query TTTB
SELECT
a.dsc,
Expand Down
24 changes: 24 additions & 0 deletions pkg/sql/sem/builtins/geo_builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -2421,6 +2421,30 @@ Note if geometries are the same, it will return the LineString with the minimum
Volatility: tree.VolatilityImmutable,
},
),
"st_relatematch": makeBuiltin(
defProps(),
tree.Overload{
Types: tree.ArgTypes{
{"intersection_matrix", types.String},
{"pattern", types.String},
},
Fn: func(ctx *tree.EvalContext, args tree.Datums) (tree.Datum, error) {
matrix := string(tree.MustBeDString(args[0]))
pattern := string(tree.MustBeDString(args[1]))

matches, err := geomfn.MatchesDE9IM(matrix, pattern)
if err != nil {
return nil, err
}
return tree.MakeDBool(tree.DBool(matches)), nil
},
ReturnType: tree.FixedReturnType(types.Bool),
Info: infoBuilder{
info: "Returns whether the given DE-9IM intersection matrix satisfies the given pattern.",
}.String(),
Volatility: tree.VolatilityImmutable,
},
),

//
// Validity checks
Expand Down