Skip to content

Commit

Permalink
fixes whitespace char handling in constraint name in dataquality trees (
Browse files Browse the repository at this point in the history
  • Loading branch information
keenkeystrokes authored Jul 30, 2024
1 parent c9f892e commit 9185ff3
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,4 @@
</dependency>

</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ constraintList: LESS_THAN
dqConstraintName (COMMA dqConstraintName)*
GREATER_THAN
;
dqConstraintName: STRING | identifier
dqConstraintName: identifier
;
Original file line number Diff line number Diff line change
Expand Up @@ -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<GraphFetchTree> subTrees = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -124,7 +125,12 @@ private static String printConstraints(List<String> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ageMustBePositive, 'nameMust \\r\\nNotBeBlank'>{\n" +
" lastName,\n" +
" name,\n" +
" addresses{\n" +
" addressId\n" +
" }\n" +
" }\n" +
" ]$;\n" +
" filter: p:Person[1] | p.age >= 18;\n" +
"}");

}



}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ageMustBePositive, 'nameMust \\r\\nNotBeBlank'>{\n" +
" lastName,\n" +
" name,\n" +
" addresses<streetMustNotBeBlank>{\n" +
" addressId\n" +
" }\n" +
" }\n" +
" ]$;\n" +
"}\n");
}

}

0 comments on commit 9185ff3

Please sign in to comment.