Skip to content

chore(c/validation): add RewriteSql quirk to override test queries#4496

Open
fornwall wants to merge 2 commits into
apache:mainfrom
fornwall:validation/rewrite-sql-quirk
Open

chore(c/validation): add RewriteSql quirk to override test queries#4496
fornwall wants to merge 2 commits into
apache:mainfrom
fornwall:validation/rewrite-sql-quirk

Conversation

@fornwall

@fornwall fornwall commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

TestSqlQueryFloats and TestSqlSchemaFloats hardcoded SELECT CAST(1.5 AS FLOAT), whose FLOAT type name is not valid in every SQL dialect (GoogleSQL in BigQuery accepts only FLOAT64 - Spanner also FLOAT32).

Add a generic DriverQuirks::RewriteSql(query_id, default_sql) hook. It is keyed by a stable query id of the form <test>::<description> (e.g. StatementTest::TestSqlQueryFloats::cast-1.5-as-float) so driver overrides switch on the id, and takes the default query as an argument so the base method just returns it.

Drivers whose dialect differs can override the whole query. Wire it into the two float-cast select tests to start with to fix the FLOAT issue - it can be inserted into other tests on demand.

TestSqlQueryFloats and TestSqlSchemaFloats hardcoded SELECT CAST(1.5 AS
FLOAT), whose FLOAT type name is not valid in every SQL dialect (GoogleSQL
in BigQuery accepts only FLOAT64 - Spanner also FLOAT32).

Add a generic DriverQuirks::RewriteSql(query_id, default_sql) hook. It is
keyed by a stable query id of the form <test>::<description> (e.g.
StatementTest::TestSqlQueryFloats::cast-1.5-as-float) so driver overrides
switch on the id rather than matching literal query text, and takes the
default query as an argument so the base method just returns it - existing
drivers run byte-identical SQL. Drivers whose dialect differs can override
the whole query. Wire it into the two float-cast select tests to start
with; the assertions only check that the result is an Arrow float or double
equal to 1.5, which is unaffected.

Signed-off-by: Fredrik Fornwall <fredrik@fornwall.net>
@fornwall fornwall requested a review from lidavidm as a code owner July 9, 2026 22:51
@fornwall

fornwall commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

This is another approach compared to #4492 for the C++ validation suite requring FLOAT as a type, after this suggestion:

I'd prefer a hook that lets you override entire queries, or just saying that you should override the test, rather than providing a hook just for this one test and driver.

@lidavidm What do you think of this approach?

Comment on lines +165 to +168
virtual std::string RewriteSql(std::string_view query_id,
std::string_view default_sql) const {
return std::string(default_sql);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: should probably just take default_sql as std::string

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Did that in 25a7fd2

@fornwall fornwall requested a review from lidavidm July 10, 2026 08:07
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.

2 participants