Skip to content

Fix GIS grammars for cross-version compatibility and update documentation - #425

Open
vinperothas wants to merge 1 commit into
masterfrom
gis
Open

Fix GIS grammars for cross-version compatibility and update documentation#425
vinperothas wants to merge 1 commit into
masterfrom
gis

Conversation

@vinperothas

@vinperothas vinperothas commented Mar 26, 2026

Copy link
Copy Markdown
Collaborator

Fix GIS grammars for cross-version compatibility and update documentation

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

https://perconadev.atlassian.net/browse/PS-10475

…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)
@vinperothas vinperothas changed the title Add a sample GIS testing grammar and runner Fix GIS grammars for cross-version compatibility and update documentation Apr 30, 2026
@vinperothas
vinperothas requested a review from Grishma123-Eng May 4, 2026 04:28
@mchawla16

Copy link
Copy Markdown
Contributor

Thanks Vin for the changes.

Few points:

  1. Should we create a gendata zz file instead of using post-gendata-sql since for gis the default data generated is not very useful?
  2. Does the linestring.sql have sufficient data, or do we need more data in it?

@saikumar-vs saikumar-vs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks Vin for working on adding support for latest linestring.sql file to usage/readme and ensuring compatibility with 5.7 and 8.0. Couple of comments to take care, it dosent block the PR but good to have stuff.

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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please check and add 8.4 as well

Comment thread randgen/conf/gis/README
  --vardir=$VARDIR \
  --post-gendata-sql=conf/gis/linestring.sql \
  --grammar=conf/gis/linestring.yy \
  --threads=2 \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same as below

Comment thread randgen/conf/gis/README
--basedir=$BASEDIR \
--vardir=$VARDIR \
--grammar=conf/gis/gis.yy \
--threads=2 \

@saikumar-vs saikumar-vs Jun 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 to CAST(... AS SIGNED).
  • Added runnable GIS setup artifacts (schema/data samples) plus an OSM-to-SQL generator script.
  • Expanded randgen/conf/gis/README with 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.

Comment on lines +12 to +15
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)'));
Comment on lines +11 to +13
ST_Intersects(g, ST_GeomFromText($wkt)) |
ST_Contains(ST_GeomFromText($wkt), g) |
ST_Distance(g, ST_PointFromText($point)) < 5 |
Comment thread randgen/conf/gis/gis.yy
Comment on lines +49 to +51
ST_POINTFROMTEXT(' point_wkt ') |
ST_POINTFROMTEXT(' point_wkt ') |
ST_POINTFROMTEXT(' point_wkt ') |
Comment thread randgen/conf/gis/gis.yy
Comment on lines +57 to +61
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 ') |
Comment thread randgen/conf/gis/gis.yy
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)'));
Comment on lines +36 to +41
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)
Comment thread randgen/conf/gis/README
Comment on lines +46 to +50
  --basedir=$BASEDIR \
  --vardir=$VARDIR \
  --post-gendata-sql=conf/gis/linestring.sql \
  --grammar=conf/gis/linestring.yy \
  --threads=2 \
Comment thread randgen/conf/gis/README
Comment on lines +42 to +44
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

@mohitj1988
mohitj1988 force-pushed the master branch 2 times, most recently from 5b2863f to b523a13 Compare June 30, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants