Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public enum Level {
public static final String DIALECT_TABLEAU = "TABLEAU";
public static final String DIALECT_ANSI_SQL = "ANSI_SQL";

// Expression syntax. "Tua" is the only syntax type the Salesforce semantic model API
// accepts; the dialect names above say how an expression was authored, not its syntax.
public static final String SYNTAX = "syntax";
public static final String SYNTAX_TUA = "Tua";

// Relationship properties
public static final String CRITERIA = "criteria";
public static final String RELATIONSHIPS = "relationships";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,7 @@ private Map<String, Object> createSemanticCalculatedDimension(
calcDim.put(LABEL, label);
}

// Set syntax for Tableau expressions
calcDim.put("syntax", DIALECT_TABLEAU);
calcDim.put(SYNTAX, SYNTAX_TUA);

return calcDim;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private void unwrapExpressions(List<Object> ossieMetrics, List<Object> sfMetrics
// Exact Salesforce dataType restored from custom_extensions (e.g. "Currency")
// wins over the Tua compiler's derived type.
sfMetric.putIfAbsent(DATA_TYPE, translated.dataType());
sfMetric.put("syntax", "Tua");
sfMetric.put(SYNTAX, SYNTAX_TUA);
sfMetric.put("aggregationType", "UserAgg");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,34 @@ void testCalculatedDimensionLabelDefaultsToApiName() throws Exception {
"a calculated dimension with no Ossie label should default its label to apiName");
}

@Test
void testCalculatedDimensionDeclaresTuaSyntax() throws Exception {
// Normalize line endings first: the fixture file may check out with CRLF depending on
// the platform's autocrlf setting, but the substitution below is written with LF.
// Tua is the only expression syntax the Salesforce semantic model API accepts; sending
// the dialect name rejects the whole model with "Invalid Expression Syntax Type".
String yamlWithTableauCalcDim = ossieYaml.replace("\r\n", "\n")
.replace(" - dialect: ANSI_SQL\n"
+ " expression: YEAR([Orders].[order_date])\n",
" - dialect: TABLEAU\n"
+ " expression: YEAR([Orders].[order_date])\n");
assertTrue(yamlWithTableauCalcDim.contains("dialect: TABLEAU"), "fixture text substitution did not match");

List<String> results = converter.convert(yamlWithTableauCalcDim);
Map<String, Object> sfModel = jsonMapper.readValue(results.get(0), new TypeReference<Map<String, Object>>() {});

List<Map<String, Object>> calcDimensions =
(List<Map<String, Object>>) sfModel.get("semanticCalculatedDimensions");
assertNotNull(calcDimensions, "the Tableau dialect should produce a semanticCalculatedDimension");
Map<String, Object> orderYear = calcDimensions.stream()
.filter(d -> "order_year".equals(d.get("apiName")))
.findFirst()
.orElse(null);
assertNotNull(orderYear);
assertEquals("Tua", orderYear.get("syntax"),
"a calculated dimension must declare the Tua expression syntax");
}

@Test
void testMetricsConvertedToSemanticCalculatedMeasurements() throws Exception {
List<String> results = converter.convert(ossieYaml);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,4 +415,25 @@ void testConverterImplExtractModelNameFromOssieFormat() throws Exception {

assertEquals("Customer_Orders_Model", ossieRoot.get("name"));
}

@Test
void testCalculatedDimensionSyntaxSurvivesRoundTrip() throws Exception {
// A calculated dimension imported from Salesforce comes back as a Tableau-dialect field,
// so re-exporting it must still declare the Tua syntax the Salesforce API accepts.
String ossieYaml = converter.convert(salesforceJson).get(0);

Converter exporter = ConverterFactory.getConverter(ConversionDirection.OSSIE_TO_SALESFORCE);
Map<String, Object> sfModel = new ObjectMapper().readValue(exporter.convert(ossieYaml).get(0), Map.class);

List<Map<String, Object>> calcDimensions =
(List<Map<String, Object>>) sfModel.get("semanticCalculatedDimensions");
assertNotNull(calcDimensions);
Map<String, Object> orderYear = calcDimensions.stream()
.filter(d -> "order_year".equals(d.get("apiName")))
.findFirst()
.orElse(null);
assertNotNull(orderYear);
assertEquals("Tua", orderYear.get("syntax"),
"the re-exported calculated dimension must declare the Tua expression syntax");
}
}
Loading