Repository navigation
Description
GV005 (function-on-filter-column) fires for any function or calculation around a filtered column. That is right, but the fix text is one fixed sentence about timestamps, whatever the function is:
gulliver lint "select a from t where upper(name) like 'A%' limit 5"
# warn GV005 function-on-filter-column: The filter wraps name in a function or calculation, which blocks partition pruning and min/max skipping.
# fix: Compare the raw column to a constant range, e.g. ts >= '2024-01-01' AND ts < '2024-01-02' instead of DATE(ts) = '2024-01-01'.
gulliver lint "select a from t where amount * 1.2 > 100 limit 5"
# warn GV005 ...wraps amount in a function or calculation...
# fix: Compare the raw column to a constant range, e.g. ts >= '2024-01-01' AND ts < '2024-01-02' instead of DATE(ts) = '2024-01-01'.
gulliver lint "select a from t where coalesce(status, 'x') = 'x' limit 5"
# warn GV005 ...wraps status in a function or calculation...
# fix: Compare the raw column to a constant range, e.g. ts >= '2024-01-01' AND ts < '2024-01-02' instead of DATE(ts) = '2024-01-01'.The fix field is what an agent acts on. For a case-insensitive name match or a price calculation, "compare ts to a date range" names a column that is not in the query and a rewrite that does not apply; a small model either ignores the finding or rewrites the filter into something wrong.
Checked on current main (2bdae73): the text is a literal in the GV005 block of src/gulliver/lint.py (around lines 322-326).
What should happen
The finding (id, severity, message, where it fires) stays the same. Only the fix text depends on what wraps the column, and it names the real column:
| The filter wraps the column in | Example | fix says |
|---|---|---|
a date / time function or a cast to date (DATE, DATE_TRUNC, CAST(.. AS DATE), ::date, YEAR, EXTRACT, STRFTIME) |
DATE(ts) = '2024-01-01' |
today's text, with the real column name instead of ts |
arithmetic with constants (+ - * /) |
amount * 1.2 > 100 |
move the calculation to the constant side: amount > 100 / 1.2 |
a case or trim function (UPPER, LOWER, TRIM) |
UPPER(name) LIKE 'A%' |
store or compare a normalised value: a case-insensitive comparison (ILIKE where the engine has it) or a precomputed lower-case column; say that the function forces a full scan |
COALESCE / IFNULL / NVL |
COALESCE(status, 'x') = 'x' |
write the NULL case out: (status = 'x' OR status IS NULL) |
| anything else | SUBSTR(code, 1, 2) = 'NL' |
a neutral sentence: compare the raw column where possible, or filter on a partition / indexed column first |
No autofix is asked for here: the existing same-rows rewrite for dates stays as it is, and the new texts are advice only. (#131 asks for the same rule on join keys; the two do not overlap, but a helper that picks the advice text could be shared.)
Where to start
src/gulliver/lint.py: the GV005 block insidelint(...)(lines 309-327).operandis the wrapping expression (exp.Func,exp.Castorexp.Binary) andcols[0]the column; a small function_gv005_fix(operand, column_sql, dialect)that returns the text keeps the block readable. sqlglot class names to match on:exp.Upper,exp.Lower,exp.Trim,exp.Coalesce,exp.Add/exp.Sub/exp.Mul/exp.Div,exp.Cast/exp.TsOrDsToDate/exp.DateTrunc/exp.Extract(check what each dialect parses to;gulliver lint --dialect bigquery "..."is the quick way)src/gulliver/fixer.pyreads GV005 findings for the date rewrite; make sure it does not depend on the oldfixtextILIKEdoes not exist in BigQuery: either leave it out for that dialect or word the advice without it- Tests:
tests/test_lint.py; the README rule table (generated bygulliver rules --format markdown) only shows the rule description, so it changes only if you change that
How to test
gulliver lint "select a from t where upper(name) like 'A%' limit 5" # fix talks about case, names `name`
gulliver lint "select a from t where amount * 1.2 > 100 limit 5" # fix: move the calculation to the constant
gulliver lint "select a from t where date(ts) = '2024-01-01' limit 5" # fix: the date range, as today
pytest tests/test_lint.py tests/test_fixer.pyDone when
- The four kinds above each get their own
fixtext, with the column from the query in it, and everything else gets the neutral text - No GV005
fixmentionstsor a date unless the filter is about a date or time - Rule id, severity, message and the cases where GV005 fires are unchanged; the date autofix still works
- A test per kind, on at least
duckdbandbigquery - Leave CHANGELOG.md alone; the maintainer adds the entry with credit to you when it is merged
-
pytestandruff check .pass
Please comment with your plan before writing a lot of code, as CONTRIBUTING.md asks for bigger changes.
Comment here to claim it and you'll be assigned.
Activity
dianatofficial commentedon Nov 15, 2026
Hi! I would like to claim this issue. Here is my proposed plan:
Implementation Plan
Helper Function
_gv005_fix(operand, column_sql, dialect)insrc/gulliver/lint.py:exp.TsOrDsToDate,exp.DateTrunc,exp.Extract,exp.Strftime,exp.Year,exp.Date, orexp.Castwith DATE/TIMESTAMP target):Compare the raw column to a constant range, e.g. <col> >= '2024-01-01' AND <col> < '2024-01-02' instead of DATE(<col>) = '2024-01-01'.exp.Add,exp.Sub,exp.Mul,exp.Div):Move the calculation to the constant side (e.g. <col> > 100 / 1.2 instead of <col> * 1.2 > 100).exp.Upper,exp.Lower,exp.Trim):Store or compare a normalized value: a case-insensitive comparison (or precomputed lowercase column), as functions force a full scan.exp.Coalesce,exp.IfNull,exp.Nvl):Write the NULL case out explicitly: (<col> = 'x' OR <col> IS NULL).Compare the raw column where possible, or filter on a partition or indexed column first.Portability & Invariants:
GV005), severity (warn), and message remain identical.src/gulliver/fixer.py.Testing:
tests/test_lint.pychecking each category across DuckDB and BigQuery.CHANGELOG.mdunder## Unreleased -> ### Fixed.laaielichter commentedon Nov 15, 2026
Thanks @dianatofficial for the claim and the detailed plan. We keep a limit of 3 open issues per person, and you already hold #119 (PR #121), #112 (PR #115) and #152, which you claimed first today. So I can't assign #158 to you right now. As soon as one of those is merged you can claim another, and #158 stays free until then.
Generated by Claude Code
laaielichter commentedon Nov 15, 2026
#112, #154 and #155 are merged now, so you have free slots, @dianatofficial, and yours was the first claim here: #158 is assigned to you, with PR #174. One note on the plan: contributors no longer edit
CHANGELOG.md; we add the entry with credit when it is merged, so please leave that file out of #174.Generated by Claude Code
dianatofficial commentedon Nov 16, 2026
Implemented in PR #182 with CHANGELOG.md untouched per instructions. All 14 CI matrix checks are passing 100% green across Python 3.10, 3.12, 3.13 on Ubuntu, macOS, and Windows.
fix(lint): dynamic arithmetic operator inversion and coalesce default…
fix(lint): fallback for non-commutative and negative arithmetic, add …
fix(lint): fallback for nested arithmetic, non-binary comparisons, an…
feat(lint): provide contextual fix advice for GV005 (#158)