olavloite / spanner-jdbc

JDBC Driver for Google Cloud Spanner
MIT License
38 stars 10 forks source link

JSQLParser RegExp issue #135

Closed ghost closed 5 years ago

ghost commented 5 years ago

With version 1.1.4 there is an issue with RegExp in AbstractCloudSpannerStatement.sanitizeSQL method: // Remove @{FORCE_INDEX...} statements sql = sql.replaceAll("(?is)\\@\\{\\s*FORCE_INDEX.*\\}", "");

Example case: SQL 1: FROM tbl_a@{FORCE_INDEX=abc} LEFT JOIN@{JOIN_TYPE=LOOP_JOIN} tbl_b SQL 2: FROM tbl_a@{FORCE_INDEX=abc} LEFT JOIN@{FORCE_INDEX=xyz} tbl_b SQL 3: FROM tbl_a@{FORCE_INDEX=abc} LEFT JOIN tbl_b SQL 4: FROM tbl_a LEFT JOIN@{JOIN_TYPE=LOOP_JOIN} tbl_b

With that regex the output will be: SQL 1: FROM tbl_a tbl_b SQL 2: FROM tbl_a tbl_b SQL 3: FROM tbl_a LEFT JOIN tbl_b SQL 4: FROM tbl_a LEFT JOIN@{JOIN_TYPE=LOOP_JOIN} tbl_b

Possible to fix by update the regex a little bit: sql = sql.replaceAll("(?is)\\@\\{(FORCE_INDEX|JOIN_TYPE)([^}]+)\\}", "");

olavloite commented 5 years ago

Thanks for the detailed issue description. This issue has now been fixed and a new release (1.1.5) has just been published.