Skip to content

fix(salesforce): restore metric custom_extensions, default label, respect restored dataType - #512

Merged
jbonofre merged 2 commits into
apache:mainfrom
Ashfaqbs:fix/restore-metric-custom-extensions
Oct 4, 2026
Merged

jbonofre merged 2 commits into
apache:mainfrom
Ashfaqbs:fix/restore-metric-custom-extensions

Conversation

@Ashfaqbs

@Ashfaqbs Ashfaqbs commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Implemented with Claude Code (model: Claude Sonnet 5, autonomous mode); comment/commit fully AI-drafted.

Supersedes #402, which was based on MetricMappingHandler before #404 rewrote unwrapExpressions() into a full JSqlParser-backed Tua expression compiler. Rebasing #402 directly produced conflicts in the same file, and most of its TABLEAU-only enforcement logic is now obsolete (the new compiler already supports TABLEAU/SNOWFLAKE/ANSI_SQL dialects properly). This PR re-derives just the part of #402 that is still a real, unaddressed gap on current main, carrying forward @jbonofre's review feedback from #402:

  • mapOssieToSalesforce() is the only one of the four array-level handlers (datasets, relationships, semantic model, metrics) that never called CustomExtensionHandler.restoreCustomExtensionsAtLevel() for its own level, even though Level.METRICS has existed in that switch since the mechanism was added. A metric's custom_extensions were silently dropped on Ossie -> Salesforce export.
  • Ossie metrics have no label field, so every exported semanticCalculatedMeasurement had none unless custom_extensions restored one. Defaulted it to apiName, matching DatasetMappingHandler/SemanticModelMappingHandler.
  • The Tua compiler's dataType assignment now uses putIfAbsent, so an exact Salesforce dataType restored from custom_extensions (e.g. Currency) isn't clobbered by the derived type.

Restore runs before unwrapExpressions(), since restoreSalesforceCustomExtension only fills keys that are still absent.

Added testMetricCustomExtensionsRestoredBeforeExpressionCompilation covering: a metric with custom_extensions (label + dataType) gets both restored without disturbing its compiled Tua expression/syntax, while a metric without custom_extensions still gets its label defaulted to apiName and keeps its derived dataType.

Test plan

  • mvn test in converters/salesforce: 285 tests, 0 failures, 0 errors.

MetricMappingHandler.mapOssieToSalesforce() is the only one of the four
array-level handlers (datasets, relationships, semantic model, metrics)
that never called CustomExtensionHandler.restoreCustomExtensionsAtLevel()
for its own level, even though the METRICS case in that switch has
existed since the custom-extensions mechanism was added. A metric's
custom_extensions (e.g. a Salesforce-specific label) were silently
dropped on Ossie -> Salesforce export.

Wire the same restore call used by DatasetMappingHandler and
RelationshipMappingHandler, placed before the expression is compiled so
it only fills in properties the generic mapping didn't already produce.

Signed-off-by: Ashfaq <105435085+Ashfaqbs@users.noreply.github.com>
Ossie metrics have no label field, so every exported
semanticCalculatedMeasurement had none unless custom_extensions
restored one. Default it to apiName, matching
DatasetMappingHandler/SemanticModelMappingHandler's existing pattern.

Also switch the Tua compiler's dataType assignment to putIfAbsent, so
an exact Salesforce dataType restored from custom_extensions (e.g.
Currency) is not clobbered by the derived type.

Signed-off-by: Ashfaq <105435085+Ashfaqbs@users.noreply.github.com>

@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!

Thanks @Ashfaqbs for cleanly re-deriving this on top of #404.

  • Metric custom_extensions restoration at Level.METRICS aligns with the other array handlers.
  • Defaulting label to apiName follows the pattern in DatasetMappingHandler/SemanticModelMappingHandler.
  • putIfAbsent preserves exact types (like Currency) without disturbing expression compilation.
  • I verified cleanly against main with all test passing.

@jbonofre
jbonofre merged commit 9e87fa3 into apache:main Oct 4, 2026
6 checks passed
RyutoYoda added a commit to RyutoYoda/ossie that referenced this pull request Oct 6, 2026
An Ossie field's label is optional and the schema puts no minLength on
it, so an exported semanticDimension, semanticMeasurement or
semanticCalculatedDimension could carry no label, an empty one, or a
null restored from custom_extensions. Salesforce requires MasterLabel on
every field and rejects all three the same way on create:

  RequiredFieldException: [MasterLabel]

Fall back to the apiName in applyFieldDefaults, which already runs after
custom extensions so a restored exact Salesforce label still wins. This
matches DatasetMappingHandler, SemanticModelMappingHandler and the metric
fix in apache#512; FieldMappingHandler was the one handler left without it.
jbonofre pushed a commit that referenced this pull request Oct 6, 2026
An Ossie field's label is optional and the schema puts no minLength on
it, so an exported semanticDimension, semanticMeasurement or
semanticCalculatedDimension could carry no label, an empty one, or a
null restored from custom_extensions. Salesforce requires MasterLabel on
every field and rejects all three the same way on create:

  RequiredFieldException: [MasterLabel]

Fall back to the apiName in applyFieldDefaults, which already runs after
custom extensions so a restored exact Salesforce label still wins. This
matches DatasetMappingHandler, SemanticModelMappingHandler and the metric
fix in #512; FieldMappingHandler was the one handler left without it.
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.

2 participants