Skip to content

Lint GV005: the fix advice is always the date-range example, also for UPPER(name) LIKE ..., amount * 1.2 > 100 and COALESCE(status, 'x') = 'x' #158

Closed

Description

@laaielichter

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 inside lint(...) (lines 309-327). operand is the wrapping expression (exp.Func, exp.Cast or exp.Binary) and cols[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.py reads GV005 findings for the date rewrite; make sure it does not depend on the old fix text
  • ILIKE does 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 by gulliver 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.py

Done when

  • The four kinds above each get their own fix text, with the column from the query in it, and everything else gets the neutral text
  • No GV005 fix mentions ts or 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 duckdb and bigquery
  • Leave CHANGELOG.md alone; the maintainer adds the entry with credit to you when it is merged
  • pytest and ruff 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

  1. dianatofficial commented on Nov 15, 2026

    @dianatofficial
    Contributor

    Hi! I would like to claim this issue. Here is my proposed plan:

    Implementation Plan

    1. Helper Function _gv005_fix(operand, column_sql, dialect) in src/gulliver/lint.py:

      • Date/Time & Date Casts (exp.TsOrDsToDate, exp.DateTrunc, exp.Extract, exp.Strftime, exp.Year, exp.Date, or exp.Cast with 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'.
      • Arithmetic with Constants (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).
      • Case & Trim Functions (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.
      • Coalesce / Null Handling (exp.Coalesce, exp.IfNull, exp.Nvl):
        Write the NULL case out explicitly: (<col> = 'x' OR <col> IS NULL).
      • General / Other Functions:
        Compare the raw column where possible, or filter on a partition or indexed column first.
    2. Portability & Invariants:

      • Rule ID (GV005), severity (warn), and message remain identical.
      • Preserves date autofix functionality in src/gulliver/fixer.py.
      • Dialect-safe across DuckDB, Postgres, and BigQuery.
    3. Testing:

      • Add unit tests in tests/test_lint.py checking each category across DuckDB and BigQuery.
      • Update CHANGELOG.md under ## Unreleased -> ### Fixed.
  2. laaielichter commented on Nov 15, 2026

    @laaielichter
    OwnerAuthor

    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

  3. laaielichter commented on Nov 15, 2026

    @laaielichter
    OwnerAuthor

    #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

  4. dianatofficial commented on Nov 16, 2026

    @dianatofficial
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions