Skip to content

fix(salesforce): keep fields whose column name is a SQL keyword - #532

Merged
jbonofre merged 3 commits into
apache:mainfrom
RyutoYoda:fix/salesforce-keyword-named-fields
Oct 7, 2026
Merged

jbonofre merged 3 commits into
apache:mainfrom
RyutoYoda:fix/salesforce-keyword-named-fields

Conversation

@RyutoYoda

@RyutoYoda RyutoYoda commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

isCalculatedExpression scans the whole expression for SQL keywords, so a direct
reference to a column named DATE, MONTH or COUNT is classified as
calculated. For any non-Tableau dialect processFieldsForDataset then skips it
with no log line, and two things follow:

  • the field is silently absent from the exported data object;
  • a metric referencing it fails the whole conversion with
    Declared field ... was not exported as a direct Salesforce semantic field.

Those names are legal identifiers in Snowflake, BigQuery and Postgres and are
common in warehouse schemas, so this is reachable from a plain model.

A bare identifier path is now recognised as a direct reference before the keyword
scan, which is what the method's javadoc already describes:

A direct reference is a simple column name (possibly table-qualified):
customer_name / customers.customer_name / schema.table.column

Verification

  • mvn -B -DrequireSalesforceSchema=true clean verify: 295 tests, 0 failures,
    0 errors, 0 skipped. main is 293, so this adds two tests and breaks nothing.
    apache-rat:check clean.
  • Both new tests fail when the main-code change is reverted, and only those two.
  • A 20-expression matrix run through main and this branch: only the
    keyword-named direct references change bucket. Function calls, CASE,
    operators, casts and DISTINCT are classified exactly as before, in both the
    TABLEAU and non-Tableau paths. CURRENT_DATE and other _-joined names were
    never affected, since the keyword scan is \b-bounded.
  • End to end against a live org, with a SNOWFLAKE-dialect model whose dimension
    maps to a column named DATE. On main the dimension never reaches the
    export, the POST returns 201, and the created model is quietly missing it. On
    this branch the dimension is exported and the API validates it against the data
    object — in my org that column does not exist there, so the API answers
    400 ... The referenced Data Cloud fields ([DATE]) could not be found ....
    Either way the author now learns the truth instead of losing the field.

Related Issues

No existing issue covers this. Independent of #526: no shared main-code file, and
both branches merged onto main together build green (298 tests).

Checklist

Sections this change does not touch (Specification, Ontology, Validation,
Documentation, Examples) are omitted rather than left unchecked.

Converters

  • Converter logic updated
  • Tests live under the converter's test directory

Tests

  • All existing tests pass: 295 passed, 0 skipped locally; green on the CI profile
  • New behaviour is covered by tests that fail without the fix

Compliance

  • ASF license headers present (no new files added)
  • No third-party dependencies added

A field's expression was classified as calculated whenever it contained a
SQL keyword anywhere, so a direct reference to a column named DATE, MONTH
or COUNT matched. For any non-Tableau dialect such a field was then skipped
with no log line, dropping it from the exported data object.

Treat a bare identifier path as a direct reference before the keyword scan,
which is what the method already documents it should do.
A metric referencing a field whose column is keyword-named failed the whole
conversion, not just the data object export; lock that with a test.

Compose the identifier path from a named SQL_IDENTIFIER constant instead of
spelling the same alternation twice.

@kayemkim kayemkim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ran this merged onto current main (891f007) through the salesforce workflow on JDK 21: 295 tests, 15 skipped without the Salesforce schema, two more tests than main. With the handler change backed out the new field test fails on the DATE dimension being absent, so it does pin the bug. I also pushed the pattern through the shapes I could think of: customers.customer_name, "My Column", t."DATE" and "a.b".c all take the direct-reference branch, while [Date], SUM(amount) and customer-id fall through to the existing checks exactly as before, and CURRENT_DATE or NULL were already direct references since the keyword scan never matched them. The Actions runs are still waiting for approval here, so the numbers above are from the local run. Nothing else from me.

@jbonofre jbonofre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In addition of identifiers, it would be great to add a Tableau-dialect test with a quoted literal such as "Not Available", asserting it is still classified as a calculated expression.

return false;
}

// A bare identifier path is always a direct reference, even when a segment spells a

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This early return treats any single double-quoted string as a bare identifier, because SQL_IDENTIFIER includes "[^"]+". isCalculatedExpression is also called for Tableau-dialect expression, and in Tableau double quotes delimit string literals, not identifiers.

A calculated field whose expression is "Not Available", "N/A" or "Year to Date" used to hit the operator and keyword checks (NOT, /, YEAR/DATE) and become a semanticCalculatedDimension. With this change it returns false. It is then exported as a plain data-object field whose dataObjectFieldName is the literal text, and that column doesn't exist in Salesforce.

Could you apply the quoted-identifier shortcut only for non-Tableau dialects, or drop the "[^"]+" alternative from the bypass when the dialect is Tableau?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks — you are right. Fixed in 4a72d98: the quoted form is accepted only outside the TABLEAU dialect, so "Not Available" stays a calculated dimension while a SQL "Customer Name" is still a direct reference.

Covered by testTableauQuotedLiteralIsStillCalculated, which fails without the dialect check and passes on main.

Double quotes delimit an identifier in SQL but a string literal in
Tableau, so the identifier-path check now accepts a quoted segment only
outside the TABLEAU dialect. A Tableau expression such as "Not
Available" stays a calculated dimension.
@RyutoYoda
RyutoYoda requested review from jbonofre and kayemkim October 7, 2026 14:13

@jbonofre jbonofre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

Treating a bare or quoted identifier path as a direct field reference fixes the case where a column named like a keyword (e.g. "Order Date") was wrongly classified as a calculated expression. Excluding quoted identifiers for the Tableau dialect is correct, since double quotes are string literals here.

Note: in non-Tableau dialects a lone reserved word such as END, CASE or NOT is now a direct reference rather than a calculated expression. It looks right to me, since those are not meaningful standalone expressions and a real column can have such a name.

@jbonofre
jbonofre merged commit eb6a8a6 into apache:main Oct 7, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants