Fix GIS grammars for cross-version compatibility and update documentation - #425
Fix GIS grammars for cross-version compatibility and update documentation#425vinperothas wants to merge 1 commit into
Conversation
…tion
- Update gis.yy and linestring.yy to use ST_ prefix for all spatial
functions, ensuring compatibility across MySQL versions.
- Standardize CAST(... AS SIGNED) across all GIS grammars to resolve
syntax errors in newer MySQL parsers.
- Explicitly set SRID 0 in geometry constructors (ST_GeomFromText, etc.)
to allow the optimizer to utilize spatial indexes in 8.0+.
- Improve README.md with detailed setup and execution steps for:
* gis_functional.yy (via wkt2sql.pl and --post-gendata-sql)
* gis.yy (self-contained stress testing)
* linestring.yy (via osm_to_sql.py for real-world topology)
|
Thanks Vin for the changes. Few points:
|
| parser.add_argument("city", help="Name of the city (e.g., 'San Francisco')") | ||
| parser.add_argument("output", help="Output SQL file") | ||
| parser.add_argument("--table", default="linestring", help="Table name") | ||
| parser.add_argument("--mysql-version", choices=["5.7", "8.0"], default="8.0") |
There was a problem hiding this comment.
Please check and add 8.4 as well
| --vardir=$VARDIR \ | ||
| --post-gendata-sql=conf/gis/linestring.sql \ | ||
| --grammar=conf/gis/linestring.yy \ | ||
| --threads=2 \ |
| --basedir=$BASEDIR \ | ||
| --vardir=$VARDIR \ | ||
| --grammar=conf/gis/gis.yy \ | ||
| --threads=2 \ |
There was a problem hiding this comment.
id recommend to keep the example with --threads=1, since we dont have good mutithreaded analysis (automatic yet), so keeping in 1 can be still debugged fairy easily in the case of a crash.
There was a problem hiding this comment.
Pull request overview
This PR updates the RQG GIS grammars and supporting assets to improve cross-MySQL-version compatibility (ST_ function usage, SIGNED casts) and adds documentation + helper tooling to run GIS-focused workloads.
Changes:
- Updated GIS grammars to prefer
ST_-prefixed functions and standardized numeric casts toCAST(... AS SIGNED). - Added runnable GIS setup artifacts (schema/data samples) plus an OSM-to-SQL generator script.
- Expanded
randgen/conf/gis/READMEwith execution steps for functional, linestring (OSM-driven), and stress grammars.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| randgen/conf/gis/schema.sql | Adds a minimal GIS schema + seed rows for quick functional runs. |
| randgen/conf/gis/sample_wkt.txt | Adds sample WKT inputs for quick testing. |
| randgen/conf/gis/README | Reworks documentation with setup/execution instructions for the GIS grammars and tooling. |
| randgen/conf/gis/osm_to_sql.py | Adds a script to fetch OSM data via Overpass and generate MySQL spatial inserts. |
| randgen/conf/gis/linestring.yy | Updates the linestring grammar to use ST_-prefixed functions and SRID 0 for constructed polygons/lines. |
| randgen/conf/gis/linestring.sql | Adds a sample dataset/DDL for the linestring grammar. |
| randgen/conf/gis/gis.yy | Updates the main GIS stress grammar to use ST_-prefixed functions and standardized numeric casts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| INSERT INTO t_geom (id, g) VALUES | ||
| (1, ST_GeomFromText('POINT(0 0)')), | ||
| (2, ST_GeomFromText('POINT(10 10)')), | ||
| (3, ST_GeomFromText('LINESTRING(0 0, 10 10)')); |
| ST_Intersects(g, ST_GeomFromText($wkt)) | | ||
| ST_Contains(ST_GeomFromText($wkt), g) | | ||
| ST_Distance(g, ST_PointFromText($point)) < 5 | |
| ST_POINTFROMTEXT(' point_wkt ') | | ||
| ST_POINTFROMTEXT(' point_wkt ') | | ||
| ST_POINTFROMTEXT(' point_wkt ') | |
| ST_MPOINTFROMTEXT(' multipoint_wkt ') ; | ||
|
|
||
| linestring: | ||
| /*executor1 LINESTRINGFROMTEXT(' */ /*executor2 ST_LINEFROMTEXT(' */ linestring_wkt ') | | ||
| /*executor1 LINESTRINGFROMTEXT(' */ /*executor2 ST_LINEFROMTEXT(' */ linestring_wkt ') | | ||
| /*executor1 EXTERIORRING( */ /*executor2 ST_EXTERIORRING( */ polygon ) | | ||
| /*executor1 INTERIORRINGN( */ /*executor2 ST_INTERIORRINGN( */ polygon , returns_integer ) ; | ||
| ST_LINEFROMTEXT(' linestring_wkt ') | | ||
| ST_LINEFROMTEXT(' linestring_wkt ') | |
| geometry_1d | geometry_2d | | ||
| /*executor1 GEOMETRYFROMTEXT(' */ /*executor2 ST_GEOMETRYFROMTEXT(' */ geometry_wkt ') | | ||
| /*executor1 GEOMETRYN( */ /*executor2 ST_GEOMETRYN( */ geometry_collection , returns_integer ) | | ||
| ST_GEOMETRYFROMTEXT(' geometry_wkt ') | |
| @@ -0,0 +1,3 @@ | |||
| DROP TABLE IF EXISTS linestring; | |||
| CREATE TABLE linestring (pk INTEGER NOT NULL PRIMARY KEY, linestring_key GEOMETRY NOT NULL, linestring_nokey GEOMETRY NOT NULL, SPATIAL INDEX(linestring_key), SPATIAL INDEX(linestring_nokey)) ENGINE=InnoDB; | |||
| INSERT INTO linestring (pk, linestring_key, linestring_nokey) VALUES (1, GeomFromText('LINESTRING(77.5369751 8.105712, 77.5369103 8.1059789, 77.5369228 8.1059976, 77.53695 8.106012, 77.5371559 8.1060579)'), GeomFromText('LINESTRING(77.5369751 8.105712, 77.5369103 8.1059789, 77.5369228 8.1059976, 77.53695 8.106012, 77.5371559 8.1060579)')); | |||
| def generate_insert_statement(pk: int, wkt: str, table_name: str, use_st_prefix: bool) -> str: | ||
| func_name = "ST_GeomFromText" if use_st_prefix else "GeomFromText" | ||
| return ( | ||
| f"INSERT INTO {table_name} (pk, linestring_key, linestring_nokey) " | ||
| f"VALUES ({pk}, {func_name}('{wkt}'), {func_name}('{wkt}'));" | ||
| ) |
| print(f"Querying Overpass API for city: {city_name}...", file=sys.stderr) | ||
|
|
||
| # Send as POST data, not as URL parameters | ||
| response = requests.post(overpass_url, data={'data': query}, headers=headers) |
| --basedir=$BASEDIR \ | ||
| --vardir=$VARDIR \ | ||
| --post-gendata-sql=conf/gis/linestring.sql \ | ||
| --grammar=conf/gis/linestring.yy \ | ||
| --threads=2 \ |
| Use the osm_to_sql.py script to fetch data from OpenStreetMap for any city. | ||
| python3 osm_to_sql.py "Kanyakumari" linestring.sql --mysql-version 5.7 | ||
|
|
5b2863f to
b523a13
Compare
Fix GIS grammars for cross-version compatibility and update documentation
https://perconadev.atlassian.net/browse/PS-10475