diff --git a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-api/pom.xml b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-api/pom.xml index 340b2595cdc..67993ba8138 100644 --- a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-api/pom.xml +++ b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-api/pom.xml @@ -273,4 +273,4 @@ - \ No newline at end of file + diff --git a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-grammar/src/main/antlr4/org/finos/legend/engine/language/pure/grammar/from/antlr4/DataQualityParserGrammar.g4 b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-grammar/src/main/antlr4/org/finos/legend/engine/language/pure/grammar/from/antlr4/DataQualityParserGrammar.g4 index 1d365b951f7..2ada44f5d69 100644 --- a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-grammar/src/main/antlr4/org/finos/legend/engine/language/pure/grammar/from/antlr4/DataQualityParserGrammar.g4 +++ b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-grammar/src/main/antlr4/org/finos/legend/engine/language/pure/grammar/from/antlr4/DataQualityParserGrammar.g4 @@ -96,5 +96,5 @@ constraintList: LESS_THAN dqConstraintName (COMMA dqConstraintName)* GREATER_THAN ; -dqConstraintName: STRING | identifier +dqConstraintName: identifier ; \ No newline at end of file diff --git a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-grammar/src/main/java/org/finos/legend/engine/language/dataquality/grammar/from/DataQualityTreeWalker.java b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-grammar/src/main/java/org/finos/legend/engine/language/dataquality/grammar/from/DataQualityTreeWalker.java index 470e006256b..75a739558ee 100644 --- a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-grammar/src/main/java/org/finos/legend/engine/language/dataquality/grammar/from/DataQualityTreeWalker.java +++ b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-grammar/src/main/java/org/finos/legend/engine/language/dataquality/grammar/from/DataQualityTreeWalker.java @@ -124,12 +124,17 @@ private DataQualityRootGraphFetchTree visitRootGraphDefinition(DataQualityParser result.constraints = new ArrayList<>(); for (DataQualityParserGrammar.DqConstraintNameContext dqConstraintNameContext : validationDefinitionContext.constraintList().dqConstraintName()) { - result.constraints.add(dqConstraintNameContext.getText()); + result.constraints.add(visitConstraintName(dqConstraintNameContext)); } } return result; } + private String visitConstraintName(DataQualityParserGrammar.DqConstraintNameContext dqConstraintNameContext) + { + return PureGrammarParserUtility.fromIdentifier(dqConstraintNameContext.identifier()); + } + private PropertyGraphFetchTree visitGraphPathContext(DataQualityParserGrammar.GraphPathContext graphPathContext) { List subTrees = new ArrayList<>(); diff --git a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-grammar/src/main/java/org/finos/legend/engine/language/dataquality/grammar/to/DataQualityGrammarComposerExtension.java b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-grammar/src/main/java/org/finos/legend/engine/language/dataquality/grammar/to/DataQualityGrammarComposerExtension.java index f746fdd3644..51e18bf71d7 100644 --- a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-grammar/src/main/java/org/finos/legend/engine/language/dataquality/grammar/to/DataQualityGrammarComposerExtension.java +++ b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-grammar/src/main/java/org/finos/legend/engine/language/dataquality/grammar/to/DataQualityGrammarComposerExtension.java @@ -23,6 +23,7 @@ import org.finos.legend.engine.language.pure.grammar.to.DEPRECATED_PureGrammarComposerCore; import org.finos.legend.engine.language.pure.grammar.to.HelperValueSpecificationGrammarComposer; import org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposerContext; +import org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposerUtility; import org.finos.legend.engine.language.pure.grammar.to.extension.PureGrammarComposerExtension; import org.finos.legend.engine.protocol.dataquality.metamodel.DataQuality; import org.finos.legend.engine.protocol.dataquality.metamodel.DataQualityPropertyGraphFetchTree; @@ -124,7 +125,12 @@ private static String printConstraints(List constraints) { return ""; } - return "<" + String.join(", ", constraints) + ">"; + return "<" + constraints.stream().map(DataQualityGrammarComposerExtension::renderConstraintName).collect(Collectors.joining(", ")) + ">"; + } + + private static String renderConstraintName(String constraintName) + { + return PureGrammarComposerUtility.convertIdentifier(constraintName); } public static String printFullPath(String fullPath) diff --git a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-grammar/src/test/java/org/finos/legend/engine/language/dataquality/grammar/from/TestDataQualityParsing.java b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-grammar/src/test/java/org/finos/legend/engine/language/dataquality/grammar/from/TestDataQualityParsing.java index fc52bce2ee3..82eb07ccae4 100644 --- a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-grammar/src/test/java/org/finos/legend/engine/language/dataquality/grammar/from/TestDataQualityParsing.java +++ b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-grammar/src/test/java/org/finos/legend/engine/language/dataquality/grammar/from/TestDataQualityParsing.java @@ -118,8 +118,25 @@ public void testParserForValidGrammar() " ]$;\n" + " filter: p:Person[1] | p.age >= 18;\n" + "}"); + // whitespace chars in constraint names + test("###DataQualityValidation\n" + + "DataQualityValidation meta::external::dataquality::PersonDataQualityValidation\n" + + "{\n" + + " context: fromDataSpace(meta::external::dataquality::PersonDataSpace, 'Local_Context');\n" + + " validationTree: $[\n" + + " Person{\n" + + " lastName,\n" + + " name,\n" + + " addresses{\n" + + " addressId\n" + + " }\n" + + " }\n" + + " ]$;\n" + + " filter: p:Person[1] | p.age >= 18;\n" + + "}"); + } -} \ No newline at end of file +} diff --git a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-grammar/src/test/java/org/finos/legend/engine/language/dataquality/grammar/to/TestDataQualityRoundtrip.java b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-grammar/src/test/java/org/finos/legend/engine/language/dataquality/grammar/to/TestDataQualityRoundtrip.java index aef7835a3eb..614c585ffd4 100644 --- a/legend-engine-xts-dataquality/legend-engine-xt-dataquality-grammar/src/test/java/org/finos/legend/engine/language/dataquality/grammar/to/TestDataQualityRoundtrip.java +++ b/legend-engine-xts-dataquality/legend-engine-xt-dataquality-grammar/src/test/java/org/finos/legend/engine/language/dataquality/grammar/to/TestDataQualityRoundtrip.java @@ -100,5 +100,23 @@ public void testDataQuality_withOnlyStructuralConstraints() "}\n"); } + @Test + public void testParserForValidGrammar_whiteSpaceCharsInConstraintNames() + { + test("###DataQualityValidation\n" + + "DataQualityValidation meta::external::dataquality::PersonDataQualityValidation\n" + + "{\n" + + " context: fromDataSpace(meta::external::dataquality::PersonDataSpace, 'Local_Context');\n" + + " validationTree: $[\n" + + " Person{\n" + + " lastName,\n" + + " name,\n" + + " addresses{\n" + + " addressId\n" + + " }\n" + + " }\n" + + " ]$;\n" + + "}\n"); + } }