Skip to content
Snippets Groups Projects
Unverified Commit a39b710e authored by john-metabase's avatar john-metabase Committed by GitHub
Browse files

Improves consistency of substring in MBQL (#28067)


* Improves consistency of substring in MBQL

Standard SQL SUBSTRING() uses a 1-based start index, with various drivers
handling a 0 start index in different ways. To make the behavior of substring
consistent across drivers, we will always convert a 0 start index in MBQL
to a 1 in SQL. The ->honeysql implementation of substring has been generalized
and drivers can now override just the name of the substring function, or the
entire expression if necessary. SQL Server now calls the parent implementation.

Resolves #12445

* Fixes substring from 0 in Mongo

* Adds arg to substring parent call

* Fix docs and helper text for substring()

* Adds schema to require positive integer index for substring

* WIP, adds frontend validation for substring index arg

* Adds frontend test for substring arg validation

* Updates substring test to expect exception on index 0

* Update src/metabase/driver/sql/query_processor.clj

Co-authored-by: default avatarmetamben <103100869+metamben@users.noreply.github.com>

* Use s/if instead of s/conditional

* Fix substring call in mysql substring spec

* Reverts driver and sql.qp changes for substring index

* Reverts changes to dispatch-by-clause-name-or-class

* Fixes typeinferencer test substring index

* Adds test for canonicalizing substring

* Fixes substring canonicalization with extra args

* Updates string extracts test to account for substring canonicalization

* Rewrites resolver validation application

* Adds test case for frontend expression validation errors

* Fixes frontend compiler spec for new substring validation

---------

Co-authored-by: default avatarmetamben <103100869+metamben@users.noreply.github.com>
parent 30e731e3
No related branches found
No related tags found
No related merge requests found
Showing
with 67 additions and 9 deletions
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment