Repository navigation
fix(salesforce): keep fields whose column name is a SQL keyword - #532
Conversation
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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
jbonofre
left a comment
There was a problem hiding this comment.
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.
Summary
isCalculatedExpressionscans the whole expression for SQL keywords, so a directreference to a column named
DATE,MONTHorCOUNTis classified ascalculated. For any non-Tableau dialect
processFieldsForDatasetthen skips itwith no log line, and two things follow:
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:
Verification
mvn -B -DrequireSalesforceSchema=true clean verify: 295 tests, 0 failures,0 errors, 0 skipped.
mainis 293, so this adds two tests and breaks nothing.apache-rat:checkclean.mainand this branch: only thekeyword-named direct references change bucket. Function calls,
CASE,operators, casts and
DISTINCTare classified exactly as before, in both theTABLEAUand non-Tableau paths.CURRENT_DATEand other_-joined names werenever affected, since the keyword scan is
\b-bounded.SNOWFLAKE-dialect model whose dimensionmaps to a column named
DATE. Onmainthe dimension never reaches theexport, the POST returns
201, and the created model is quietly missing it. Onthis 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
maintogether build green (298 tests).Checklist
Sections this change does not touch (Specification, Ontology, Validation,
Documentation, Examples) are omitted rather than left unchecked.
Converters
Tests
Compliance