Skip to content

fix(dbt): fix 3 buggy starrocks__ cross-db macro variants#2401

Open
blarghmatey wants to merge 1 commit into
mainfrom
tmacey/fix-starrocks-macro-bugs
Open

fix(dbt): fix 3 buggy starrocks__ cross-db macro variants#2401
blarghmatey wants to merge 1 commit into
mainfrom
tmacey/fix-starrocks-macro-bugs

Conversation

@blarghmatey

Copy link
Copy Markdown
Member

What are the relevant tickets?

Closes #2397

Description (What does it do?)

Fixes 3 correctness bugs in the starrocks__ dispatch variants of macros/cross_db_functions.sql, doc-verified against docs.starrocks.io as part of the dbt warehouse semantic-accuracy audit's StarRocks cross-database macro epic:

  1. starrocks__json_extract_value used json_extract(), which does not exist in StarRocks. Switched to json_query(parse_json(x), path).
  2. starrocks__from_iso8601_timestamp did a bare cast(x as datetime). StarRocks DATETIME is zone-less, so any string with a trailing Z or ±HH:MM offset made the cast silently return NULL. Now strips a trailing zone suffix and normalizes the T separator to a space before casting. Non-UTC offsets are dropped rather than applied — acceptable since this project's data is UTC/naive.
  3. starrocks__array_join silently dropped the null_replacement argument even though StarRocks' array_join supports the same 3-arg null_replace_str signature as Trino (per StarRocks docs: array_join([1,3,5,null],'_','NULL')). Mirrored the default__ (Trino) branch structure.

How can this be tested?

  • dbt parse against the dev_local DuckDB target succeeds (verified) — these macros aren't dispatched today since no model targets StarRocks yet, so this is Jinja-syntax + doc-verification, not a live StarRocks run.
  • Once a StarRocks target/profile exists, exercise each macro directly, e.g.:
    • select {{ json_extract_value("'{\"a\":1}'", "'$.a'") }}
    • select {{ from_iso8601_timestamp("'2024-01-01T00:00:00Z'") }}
    • select {{ array_join('array(1,3,5,null)', '_', 'NULL') }}
      against a live StarRocks warehouse and confirm non-NULL, correctly-formatted results.

Additional Context

Part of tk-epic-starrocks-support-for-cross-database-dbt-ma-968247 in the dbt warehouse audit — a sibling task (tk-implement-18-missing-starrocks-macro-variants-do-57059b) tracks implementing the 18 currently-missing starrocks__ macro variants; not addressed here.

🤖 Generated with Claude Code

Doc-verified against docs.starrocks.io:

- starrocks__json_extract_value used json_extract, which does not exist
  in StarRocks; switched to json_query(parse_json(x), path).
- starrocks__from_iso8601_timestamp did a bare cast(x as datetime),
  which returns NULL for strings with a trailing 'Z' or '+HH:MM'/'-HH:MM'
  offset since StarRocks DATETIME is zone-less; strip the offset suffix
  and 'T' separator before casting.
- starrocks__array_join silently dropped the null_replacement argument,
  even though StarRocks' array_join supports the same 3-arg
  null_replace_str signature as Trino; mirrored the default__ branch
  structure.

Closes #2397

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 6, 2026 19:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the StarRocks-dispatched variants of existing cross-database dbt macros in src/ol_dbt/macros/cross_db_functions.sql to align with StarRocks function availability and parsing behavior, improving semantic correctness for a future StarRocks target.

Changes:

  • Fix starrocks__json_extract_value to use json_query(parse_json(...), path) instead of a non-existent json_extract.
  • Fix starrocks__from_iso8601_timestamp to strip timezone suffixes and normalize the T separator before casting to StarRocks DATETIME.
  • Fix starrocks__array_join to correctly pass the optional null_replacement (3rd argument) when provided.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +76 to +81
{#
StarRocks: DATETIME is zone-less, and a bare cast() returns NULL for strings with
a trailing 'Z' or '+HH:MM'/'-HH:MM' offset. Strip any such suffix and the 'T'
separator before casting. Non-UTC offsets are dropped rather than applied, which
is acceptable since this project's source data is UTC/naive.
#}
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.

Fix 3 buggy starrocks__ macro variants (json_extract_value, from_iso8601_timestamp, array_join)

2 participants