Skip to content

TRQL function tests and fixes#3076

Open
matt-aitken wants to merge 6 commits intomainfrom
query-date-fn-fix
Open

TRQL function tests and fixes#3076
matt-aitken wants to merge 6 commits intomainfrom
query-date-fn-fix

Conversation

@matt-aitken
Copy link
Member

@matt-aitken matt-aitken commented Feb 17, 2026

What changed

  • Fixed some functions like dateAdd, toString, ifNotFinite
  • Removed all functions that accept lambdas as they're not supported (yet)
  • Added tests for all TRQL functions that use ClickHouse

dateAdd() wasn’t being converted correctly to ClickHouse. We were getting a syntax error
@changeset-bot
Copy link

changeset-bot bot commented Feb 17, 2026

⚠️ No Changeset found

Latest commit: ab19467

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 17, 2026

Walkthrough

Adds a new comprehensive ClickHouse TSQL function smoke-test suite that runs many categorized TSQL queries against a task_runs test schema with helpers to seed data and assert execution. Introduces unit tests validating date/time functions emit interval units as bare keywords. Updates printer logic to extract and emit interval-unit keywords for certain date functions via a new call-argument printing flow. Updates function lookup logic and exposed function listings in the TSQL functions module.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Technical details

Files modified: 4

Key changes:

  • internal-packages/clickhouse/src/tsqlFunctions.test.ts: +830 lines — new comprehensive TSQL function smoke-test suite, schema/task run mapping, setup helpers, and many categorized test cases.
  • internal-packages/tsql/src/query/printer.test.ts: +89 lines — new tests covering date functions with interval units, underscore-style names, case-insensitivity, and sub-second interval precision.
  • internal-packages/tsql/src/query/printer.ts: +82/-2 — adds INTERVAL_UNITS and DATE_FUNCTIONS_WITH_INTERVAL_UNIT sets, introduces visitCallArgs() flow and extractIntervalUnit() to emit bare interval unit keywords for supported date functions, and adjusts argument emission control flow.
  • internal-packages/tsql/src/query/functions.ts: +33/-24 — refactors function lookup to use lowercase prototype-safe maps, adjusts exposed ClickHouse function set (removals and additions for array functions), widens ifNotFinite arity, and adds getAllExposedFunctionNames() export.
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is largely incomplete compared to the template. It lacks proper structure, missing issue reference, checklist completion, testing details, and changelog formatting. Use the provided template with sections for issue reference, completed checklist, testing steps, and changelog description to provide complete context for reviewers.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'TRQL function tests and fixes' directly summarizes the main changes: adding comprehensive tests for TRQL functions and fixing several function implementations (dateAdd, toString, ifNotFinite).
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch query-date-fn-fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
internal-packages/clickhouse/src/tsqlFunctions.test.ts (1)

110-121: Each test block re-inserts data into a fresh container — consider sharing setup.

Every clickhouseTest callback calls setupClient, which inserts defaultTaskRun into a new container. If the clickhouseTest fixture already provides a shared container per describe block (or can be configured to), you could insert once and reuse across all test blocks, reducing test suite runtime significantly.

If containers are already pooled/shared by the fixture, the repeated inserts are still redundant work. A beforeAll-style setup inserting once would be cleaner.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal-packages/clickhouse/src/tsqlFunctions.test.ts` around lines 110 -
121, Tests repeatedly call setupClient which inserts defaultTaskRun into a new
container for every clickhouseTest; instead, move the insert to a shared setup
so it runs once per describe (or reuse the fixture's pooled container). Modify
the test suite to perform the insert of defaultTaskRun in a beforeAll (or
equivalent shared fixture) and have setupClient only construct and return the
ClickhouseClient without inserting; reference the setupClient function,
clickhouseTest callbacks, and defaultTaskRun to locate where to remove the
per-test insert and where to add the shared beforeAll insertion.
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 27611ef and ab19467.

📒 Files selected for processing (3)
  • internal-packages/clickhouse/src/tsqlFunctions.test.ts
  • internal-packages/tsql/src/query/functions.ts
  • internal-packages/tsql/src/query/printer.ts
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx}: Use types over interfaces for TypeScript
Avoid using enums; prefer string unions or const objects instead

**/*.{ts,tsx}: Always import tasks from @trigger.dev/sdk, never use @trigger.dev/sdk/v3 or deprecated client.defineJob pattern
Every Trigger.dev task must be exported and have a unique id property with no timeouts in the run function

Files:

  • internal-packages/clickhouse/src/tsqlFunctions.test.ts
  • internal-packages/tsql/src/query/printer.ts
  • internal-packages/tsql/src/query/functions.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use function declarations instead of default exports

Import from @trigger.dev/core using subpaths only, never import from root

Files:

  • internal-packages/clickhouse/src/tsqlFunctions.test.ts
  • internal-packages/tsql/src/query/printer.ts
  • internal-packages/tsql/src/query/functions.ts
**/*.{test,spec}.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use vitest for all tests in the Trigger.dev repository

Files:

  • internal-packages/clickhouse/src/tsqlFunctions.test.ts
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/otel-metrics.mdc)

**/*.ts: When creating or editing OTEL metrics (counters, histograms, gauges), ensure metric attributes have low cardinality by using only enums, booleans, bounded error codes, or bounded shard IDs
Do not use high-cardinality attributes in OTEL metrics such as UUIDs/IDs (envId, userId, runId, projectId, organizationId), unbounded integers (itemCount, batchSize, retryCount), timestamps (createdAt, startTime), or free-form strings (errorMessage, taskName, queueName)
When exporting OTEL metrics via OTLP to Prometheus, be aware that the exporter automatically adds unit suffixes to metric names (e.g., 'my_duration_ms' becomes 'my_duration_ms_milliseconds', 'my_counter' becomes 'my_counter_total'). Account for these transformations when writing Grafana dashboards or Prometheus queries

Files:

  • internal-packages/clickhouse/src/tsqlFunctions.test.ts
  • internal-packages/tsql/src/query/printer.ts
  • internal-packages/tsql/src/query/functions.ts
**/*.{js,ts,jsx,tsx,json,md,yaml,yml}

📄 CodeRabbit inference engine (AGENTS.md)

Format code using Prettier before committing

Files:

  • internal-packages/clickhouse/src/tsqlFunctions.test.ts
  • internal-packages/tsql/src/query/printer.ts
  • internal-packages/tsql/src/query/functions.ts
**/*.test.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.test.{ts,tsx,js,jsx}: Test files should live beside the files under test and use descriptive describe and it blocks
Tests should avoid mocks or stubs and use the helpers from @internal/testcontainers when Redis or Postgres are needed
Use vitest for running unit tests

**/*.test.{ts,tsx,js,jsx}: Use vitest exclusively for testing and never mock anything - use testcontainers instead
Place test files next to source files with naming pattern: source file (e.g., MyService.ts) → MyService.test.ts

Files:

  • internal-packages/clickhouse/src/tsqlFunctions.test.ts
**/*.test.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use testcontainers helpers (redisTest, postgresTest, containerTest) from @internal/testcontainers for Redis/PostgreSQL testing instead of mocks

Files:

  • internal-packages/clickhouse/src/tsqlFunctions.test.ts
🧬 Code graph analysis (3)
internal-packages/clickhouse/src/tsqlFunctions.test.ts (2)
internal-packages/clickhouse/src/taskRuns.ts (1)
  • insertTaskRuns (199-210)
internal-packages/testcontainers/src/index.ts (1)
  • clickhouseTest (219-223)
internal-packages/tsql/src/query/printer.ts (2)
internal-packages/tsql/src/query/functions.ts (1)
  • TSQL_COMPARISON_MAPPING (33-46)
internal-packages/tsql/src/query/ast.ts (2)
  • Constant (463-466)
  • Field (468-472)
internal-packages/tsql/src/query/functions.ts (1)
internal-packages/tsql/src/index.ts (4)
  • TSQLFunctionMeta (78-78)
  • TSQL_CLICKHOUSE_FUNCTIONS (76-76)
  • TSQL_AGGREGATIONS (75-75)
  • findTSQLFunction (73-73)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (27)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (6, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (5, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (4, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (2, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (1, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (8, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (6, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (2, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (7, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (7, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (1, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (4, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (3, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (8, 8)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (3, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (5, 8)
  • GitHub Check: sdk-compat / Cloudflare Workers
  • GitHub Check: sdk-compat / Deno Runtime
  • GitHub Check: units / packages / 🧪 Unit Tests: Packages (1, 1)
  • GitHub Check: sdk-compat / Node.js 20.20 (ubuntu-latest)
  • GitHub Check: sdk-compat / Node.js 22.12 (ubuntu-latest)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: sdk-compat / Bun Runtime
🔇 Additional comments (5)
internal-packages/tsql/src/query/printer.ts (2)

2811-2811: Good fix for prototype pollution in comparison mapping lookup.

Using Object.prototype.hasOwnProperty.call() instead of the in operator correctly prevents matching inherited properties like toString, constructor, etc. from Object.prototype.


2868-2946: Well-structured interval unit handling for date functions.

The implementation cleanly separates concerns: INTERVAL_UNITS defines the valid keywords, DATE_FUNCTIONS_WITH_INTERVAL_UNIT scopes which functions need special treatment, visitCallArgs orchestrates the dispatch, and extractIntervalUnit handles both constant strings and bare field identifiers. The inclusion of sub-second units (nanosecond, microsecond, millisecond) correctly supports dateDiff's broader unit vocabulary.

internal-packages/clickhouse/src/tsqlFunctions.test.ts (1)

147-830: Comprehensive smoke test coverage — looks good.

The test suite methodically covers all major TSQL function categories with real ClickHouse execution, which is a strong regression safety net for the printer and function mapping changes.

internal-packages/tsql/src/query/functions.ts (2)

437-437: Correct fix for ifNotFinite arity.

ClickHouse's ifNotFinite(x, y) requires exactly 2 arguments. The previous minArgs: 1 would have allowed invalid single-argument calls.


553-612: Clean refactor of function lookup with null-prototype maps.

Using Object.create(null) for the lowercase map eliminates prototype pollution entirely, and the pre-computed maps avoid repeated lowercasing on every lookup. The two-tier lookup (exact match → case-insensitive fallback with caseSensitive guard) is well-structured.

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@internal-packages/clickhouse/src/tsqlFunctions.test.ts`:
- Around line 110-121: Tests repeatedly call setupClient which inserts
defaultTaskRun into a new container for every clickhouseTest; instead, move the
insert to a shared setup so it runs once per describe (or reuse the fixture's
pooled container). Modify the test suite to perform the insert of defaultTaskRun
in a beforeAll (or equivalent shared fixture) and have setupClient only
construct and return the ClickhouseClient without inserting; reference the
setupClient function, clickhouseTest callbacks, and defaultTaskRun to locate
where to remove the per-test insert and where to add the shared beforeAll
insertion.

@matt-aitken matt-aitken marked this pull request as ready for review February 17, 2026 16:08
Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 6 additional findings.

Open in Devin Review

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.

1 participant