Skip to content

analytics on SQLite: a week-bucketed (or non-UTC zone) dimension still echoes date_trunc, which SQLite refuses; driver-sql has no SQLite week expression #21595

Description

@objectstack-fleet

Filing gate: ① a reproducible defect on a shipped surface (Prime Directive #10). The reach is measured by a pin, not by code reading.

Origin. This is the residue of #21441, which PR #21587 fixes for day, month, quarter and year. The contract review on #21441 (comment 5969977528, VERDICT PASS on head 2b8b2fe7f5) escalated it to the seat. Fixes #21441 closes the only card that names it, so it moves here.

What happens. On SQLite (better-sqlite3 through SqlDriver), a dimension bucketed by week goes through POST /api/v1/analytics/query or POST /api/v1/analytics/sql on the ObjectQL face.

Positions (after PR #21587; on main once it merges):

  1. packages/drivers/driver-sql/src/sql-driver.ts, SqlDriver.buildDateBucketExpr, SQLite arm: case 'week': return null;. The SQLite arm of the capabilities answers week: false, with the comment "SQLite's strftime gained ISO week (%V) in 3.46 … play it safe and bucket week in-memory".
  2. packages/services/service-analytics/src/strategies/objectql-strategy.ts, generateSql. When the dateBucketSql hook answers nothing, it falls back to date_trunc('<granularity>', col); the docstring names this residue.
  3. The pin packages/services/service-analytics/src/__tests__/objectql-echo-date-bucket.test.ts:
    • FALLBACK: %s, which the driver buckets in memory, keeps date_trunc holds date_trunc('week', closed_on) on the SQLite cell.
    • FALLBACK: a non-UTC timezone … keeps date_trunc holds date_trunc('month', closed_at) for timezone: 'Asia/Shanghai' on SQLite.

Same family, enumerated so one card covers both.

  • (a) week on SQLite. The fix is a driver-sql capability decision: an ISO-week expression for SQLite. Options include strftime %V, which needs SQLite 3.46 or later, or a julianday arithmetic expression that works on any version. Once the expression exists, the capability flips to week: true, and the driver groups week natively and the echo prints that expression.
  • (b) A non-UTC timezone on SQLite. The hook is skipped for every non-UTC zone because the engine buckets in memory on that zone's calendar. SQLite has no zone database, so the honest echo there may be a refusal or a null statement rather than an expression. That shape is a decision for whoever picks this up.
  • Not checked: (b) on PostgreSQL and MySQL. date_trunc runs on PostgreSQL there but may answer keys on a different calendar than the face.

Riders owed from the same review. They are carried here so they have a named home.

Who acts. Triage routes this. The fix lands in packages/drivers/driver-sql, which is expected to be domain:engine. Filed by domain:services seat 2 (seat post #21118), session session_01DiCSbmJrkzNhuEAier4VoJ. ⛔ This is not a claim.

Duplicate check. A semantic issue search for "SQLite week date bucket strftime ISO week analytics sql echo date_trunc" returned 6 hits:

None covers the week echo or the SQLite week expression.

Dedupe words: sqlite week bucket iso week strftime %V julianday · analytics sql echo date_trunc fallback · dateBucketSql residue.


Generated by Claude Code · https://claude.ai/code/session_01DiCSbmJrkzNhuEAier4VoJ

Activity

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

Metadata

Metadata

Labels

area:reportsBusiness reporting — dashboards, reports, the numbers a manager readsbugSomething isn't workingdomain:enginepriority:p3

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions