- Notifications
You must be signed in to change notification settings - Fork15
Add MOC vs. other geometries casts#6
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
4b878b4 Fixing test expectation for updates in pg_sphere.test.sql
msdemlei97080b5 Adding documentation for the max_order function
msdemlei2bde2b1 Adding support of casting of circles and polygons to mocs
msdemlei9420a22 Enabling operator dropping in the moc-vs-geometry SQL.
msdemlei5e7ab4e Attempting to fix upgrade script for pg 9.x.
msdemleid2dc156 Merge branch 'postgrespro:master' into add-moc-casts
msdemleiFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -8,3 +8,4 @@ | ||
| regression.out | ||
| regression.diffs | ||
| tags | ||
| buildpod | ||
50 changes: 50 additions & 0 deletionsHACKING
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| SQL definitions | ||
| =============== | ||
| Long version: | ||
| <https://www.postgresql.org/docs/current/extend-extensions.html>. | ||
| If you're writing new features that require SQL support, pick some | ||
| descriptive name; let's say my_new_op. | ||
| Put your new code into a file called pgs_my_new_op.sql.in. The .in | ||
| extension here usually indicates "it's for copying stuff together"; | ||
| usally, not much processing is done on such files. | ||
| Then edit the Makefile. The PGS_SQL variable contains a list of the | ||
| SQL files eventually copied together, without the .in. Add your new | ||
| file there. | ||
| You will also need to create an upgrade file. In order to tell postgres | ||
| to execute it, increase PGSPHERE_VERSION as appropriate. As a | ||
| consequence, you will have to:: | ||
| git mv pg_sphere--<old version>.sql.in pg_sphere--<new version>.sql.in | ||
| and also to update the version in pg_sphere.control. | ||
| Then create a make rule:: | ||
| pg_sphere--<old version>--<new version>.sql: pgs_my_new_op.sql.in | ||
| cat $^ > $@ | ||
| (of course, this will extend to having multiple sql.in files). | ||
| Finally, add the target of that rule to the DATA_built variable. | ||
| Regression tests | ||
| ================ | ||
| Regressions tests are as per | ||
| <https://www.postgresql.org/docs/current/extend-pgxs.html>. | ||
| In short, write queries executing your new features into a file | ||
| sql/my_new_op.sql, and add "my_new_op" (without the extension or the | ||
| directory name) to both REGRESS and TESTS in the Makefile. | ||
| Then touch expected/my_new_op.out, run make test. This will of course | ||
| fail, because your tests hopefully will output something. But then you | ||
| can pick out the diff from | ||
| /var/lib/postgresql/pgsphere/regression.diffs, have another critical | ||
| look at it and generatoe your .out file from it. |
20 changes: 14 additions & 6 deletionsMakefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletionsdoc/functions.sgm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletionsdoc/gen_moccast.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| # A script to create the automatic casts for overlaps and intersects | ||
| # between MOCs and spolys/scircles. | ||
| # | ||
| # This has originally been used to create pg_sphere--1.2.0--1.2.1.sql. | ||
| # Before 1.2.1 is release, this can be fixed to improve that SQL. | ||
| # After the 1.2.1 release, this is just documentation on how MOC | ||
| # casts were generated that is perhaps just a bit more readable than | ||
| # that bunch of SQL. | ||
| import datetime | ||
| import re | ||
| import sys | ||
| OVERLAP_DEFS = [ | ||
| # func_stem, operator, commutator | ||
| ('subset', '<@', '@>'), | ||
| ('not_subset', '!<@', '!@>'), | ||
| ('superset', '@>', '<@'), | ||
| ('not_superset', '!@>', '!<@'), | ||
| ] | ||
| INTERSECT_DEFS = [ | ||
| # func_stem, operator, commutator | ||
| ('intersect', '&&', '&&'), | ||
| ('not_intersect', '!&&', '!&&'), | ||
| ] | ||
| GEO_TYPES = ["scircle", "spoly"] | ||
| OP_DEFS = OVERLAP_DEFS | ||
| class Accum: | ||
| """an accumulator for our output. | ||
| """ | ||
| def __init__(self): | ||
| self.parts = [] | ||
| @property | ||
| def content(self): | ||
| return "".join(self.parts) | ||
| def write(self, s): | ||
| self.parts.append(s) | ||
| def writeln(self, *strings): | ||
| self.parts.append("\n".join(strings)+"\n") | ||
| def replace_last(self, subs): | ||
| """replaces the last non-whitespace char with the string subs. | ||
| """ | ||
| for index, part in enumerate(reversed(self.parts)): | ||
| if part.strip(): | ||
| break | ||
| else: | ||
| # nothing to replace | ||
| return | ||
| index = -1-index | ||
| self.parts[index] = re.sub("[^\s](\s*)$", | ||
| lambda mat: subs+mat.group(1), | ||
| self.parts[index]) | ||
| def introduce_section(self, sec_name): | ||
| self.writeln() | ||
| self.writeln("-- #################################") | ||
| self.writeln(f"-- {sec_name}") | ||
| def emit_drop_code(accum): | ||
| accum.introduce_section("Cleanup") | ||
| accum.writeln("DROP OPERATOR IF EXISTS") | ||
| for _, op, _ in OP_DEFS: | ||
| for geo_type in GEO_TYPES: | ||
| accum.writeln(f" {op} (smoc, {geo_type}),") | ||
| accum.writeln(f" {op} ({geo_type}, smoc),") | ||
| accum.replace_last(";") | ||
| def make_negator(op): | ||
| if op.startswith("!"): | ||
| return op[1:] | ||
| else: | ||
| return "!"+op | ||
| def emit_op_def(accum, operator, leftarg, rightarg, procedure, commutator): | ||
| accum.writeln( | ||
| f"CREATE OPERATOR {operator} (", | ||
| f" LEFTARG = {leftarg},", | ||
| f" RIGHTARG = {rightarg},", | ||
| f" PROCEDURE = {procedure},", | ||
| f" COMMUTATOR = '{commutator}',", | ||
| f" NEGATOR = '{make_negator(operator)}',", | ||
| f" RESTRICT = contsel,", | ||
| f" JOIN = contjoinsel", | ||
| f");") | ||
| def emit_op_and_func(accum, op_def): | ||
| func_stem, operator, commutator = op_def | ||
| for geo_type in GEO_TYPES: | ||
| func_name = f"{geo_type}_{func_stem}_smoc" | ||
| accum.writeln( | ||
| f"CREATE OR REPLACE FUNCTION {func_name}(", | ||
| f" geo_arg {geo_type}, a_moc smoc) RETURNS BOOL AS $body$", | ||
| f" SELECT smoc(max_order(a_moc), geo_arg) {operator} a_moc", | ||
| f" $body$ LANGUAGE SQL STABLE;") | ||
| emit_op_def(accum, operator, | ||
| geo_type, "smoc", | ||
| func_name, | ||
| commutator) | ||
| accum.writeln() | ||
| func_name = f"smoc_{func_stem}_{geo_type}" | ||
| accum.writeln( | ||
| f"CREATE OR REPLACE FUNCTION {func_name}(", | ||
| f" a_moc smoc, geo_arg {geo_type}) RETURNS BOOL AS $body$", | ||
| f" SELECT a_moc {operator} smoc(max_order(a_moc), geo_arg)", | ||
| f" $body$ LANGUAGE SQL STABLE;") | ||
| emit_op_def(accum, operator, | ||
| "smoc", geo_type, | ||
| func_name, | ||
| commutator) | ||
| accum.writeln() | ||
| def main(): | ||
| accum = Accum() | ||
| accum.writeln("-- MOC/geometry automatic casts.") | ||
| accum.writeln(f"-- Generated {datetime.date.today()} by {sys.argv[0]}.") | ||
| accum.writeln(f"-- Re-generation needs to be triggered manually.") | ||
| accum.writeln() | ||
| emit_drop_code(accum) | ||
| accum.introduce_section(" smoc/geo OVERLAPS") | ||
| for op_def in OVERLAP_DEFS: | ||
| emit_op_and_func(accum, op_def) | ||
| accum.writeln() | ||
| accum.introduce_section(" smoc/geo INTERSECTS") | ||
| for op_def in INTERSECT_DEFS: | ||
| emit_op_and_func(accum, op_def) | ||
| accum.writeln() | ||
| print(accum.content) | ||
| if __name__=="__main__": | ||
| main() |
45 changes: 44 additions & 1 deletiondoc/operators.sgm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletionsexpected/init_test.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.