use of org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposer in project legend-engine by finos.
the class TestRelationalGrammarComposer method testMappingWithTestCSV.
@Test
public void testMappingWithTestCSV() throws Exception {
PureModelContextData context = objectMapper.readValue(Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream("mappingWithTestsCSV.json")), PureModelContextData.class);
PureGrammarComposer grammarTransformer = PureGrammarComposer.newInstance(PureGrammarComposerContext.Builder.newInstance().build());
String formatted = grammarTransformer.renderPureModelContextData(context);
String expected = "###Mapping\n" + "Mapping meta::pure::mapping::modelToModel::test::simple::simpleModelMapping\n" + "(\n" + " MappingTests\n" + " [\n" + " test2\n" + " (\n" + " query: |model::domain::Target.all()->graphFetchChecked(#{model::domain::Target{name}}#)->serialize(#{model::domain::Target{name}}#);\n" + " data:\n" + " [\n" + " <Relational, CSV, aa::db, \n" + " 'default\\n'+\n" + " 'PersonTable\\n'+\n" + " 'id,lastName\\n'+\n" + " '1,Doe;\\n'+\n" + " '2,Doe2\\n'+\n" + " '\\n\\n\\n'\n" + " >\n" + " ];\n" + " assert: '{\"defects\":[],\"value\":{\"name\":\"oneName 99\"},\"source\":{\"defects\":[],\"value\":{\"oneName\":\"oneName 99\"},\"source\":{\"number\":1,\"record\":\"{\\\"oneName\\\":\\\"oneName 99\\\",\\\"anotherName\\\":\\\"anotherName 17\\\",\\\"oneDate\\\":\\\"2020-04-13\\\",\\\"anotherDate\\\":\\\"2020-02-25\\\",\\\"oneNumber\\\":27,\\\"anotherNumber\\\":28}\"}}}';\n" + " )\n" + " ]\n" + ")\n";
Assert.assertEquals(expected, formatted);
}
use of org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposer in project legend-engine by finos.
the class TestRelationalGrammarComposer method TestMappingWithLeftOuterJoin.
@Test
public void TestMappingWithLeftOuterJoin() throws Exception {
PureModelContextData context = objectMapper.readValue(Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream("mappingWithLeftOuterJoin.json")), PureModelContextData.class);
PureGrammarComposer grammarTransformer = PureGrammarComposer.newInstance(PureGrammarComposerContext.Builder.newInstance().build());
String formatted = grammarTransformer.renderPureModelContextData(context);
String expected = "###Mapping\n" + "Mapping testDB::test\n" + "(\n" + " *meta::relational::tests::model::simple::Person[meta_relational_tests_model_simple_Person]: Relational\n" + " {\n" + " ~primaryKey\n" + " (\n" + " [meta::relational::tests::mapping::join::model::store::db]personTable.ID\n" + " )\n" + " ~mainTable [meta::relational::tests::mapping::join::model::store::db]personTable\n" + " firstName: [meta::relational::tests::mapping::join::model::store::db]personTable.FIRSTNAME,\n" + " lastName: [meta::relational::tests::mapping::join::model::store::db]personTable.LASTNAME,\n " + " age: [meta::relational::tests::mapping::join::model::store::db]@Person_MiddleTable > (OUTER) [meta::relational::tests::mapping::join::model::store::db]@MiddleTable_PersonExtension | [meta::relational::tests::mapping::join::model::store::db]personExtensionTable.AGE\n" + " }\n" + ")\n";
Assert.assertEquals(expected, formatted);
}
use of org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposer in project legend-engine by finos.
the class TestRelationalGrammarComposer method selfJoinTest.
@Test
public void selfJoinTest() throws Exception {
PureModelContextData context = objectMapper.readValue(Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream("selfJoinTest.json")), PureModelContextData.class);
PureGrammarComposer grammarTransformer = PureGrammarComposer.newInstance(PureGrammarComposerContext.Builder.newInstance().build());
String formatted = grammarTransformer.renderPureModelContextData(context);
// Test checks that we do not output schema name before {target} - the grammar round trip tests do not exercise this code path as the graph
// produced for the roundtrip always sets the schema name in the table alias to default.
// This is testing out a graph as would be produced by tools such as Studio and checking that syntactically valid Pure is produced for self-joins
String expected = "###Relational\n" + "Database test::db\n" + "(\n" + " Schema mySchema\n" + " (\n" + " Table table1\n" + " (\n" + " col1 CHAR(32) PRIMARY KEY,\n" + " col2 CHAR(32)\n" + " )\n" + " )\n" + "\n" + " Join selfJoin(mySchema.table1.col1 = {target}.col2)\n" + ")\n";
Assert.assertEquals(expected, formatted);
}
use of org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposer in project legend-engine by finos.
the class TestSectionRoundtrip method testGrammarRoundtripWithoutSectionIndex.
@Test
public void testGrammarRoundtripWithoutSectionIndex() {
ObjectMapper objectMapper = ObjectMapperFactory.getNewStandardObjectMapperWithPureProtocolExtensionSupports();
// NOTE: stress test to account for flakiness
for (int i = 0; i < 500; i++) {
StringBuilder code = new StringBuilder();
for (int t = 200; t > 0; t--) {
code.append("Class model::class").append(t).append("\n").append("{\n").append(" prop: String[1];\n").append("}\n");
if (t != 1) {
code.append("\n");
}
}
PureModelContextData modelData = null;
try {
modelData = PureGrammarParser.newInstance().parseModel(code.toString());
String json = objectMapper.writeValueAsString(modelData);
modelData = objectMapper.readValue(json, PureModelContextData.class);
List<PackageableElement> elements = ListIterate.select(modelData.getElements(), element -> !(element instanceof SectionIndex));
modelData = PureModelContextData.newPureModelContextData(modelData.getSerializer(), modelData.getOrigin(), elements);
} catch (IOException e) {
throw new RuntimeException(e);
}
PureGrammarComposer grammarTransformer = PureGrammarComposer.newInstance(PureGrammarComposerContext.Builder.newInstance().build());
Assert.assertEquals(code.toString(), grammarTransformer.renderPureModelContextData(modelData));
}
}
use of org.finos.legend.engine.language.pure.grammar.to.PureGrammarComposer in project legend-engine by finos.
the class TestGrammarParser method testFromJson.
public static void testFromJson(Class<?> _class, String path, String code) {
PureModelContextData modelData = null;
try {
String json = getJsonString(_class, path);
modelData = objectMapper.readValue(json, PureModelContextData.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
PureGrammarComposer grammarTransformer = PureGrammarComposer.newInstance(PureGrammarComposerContext.Builder.newInstance().build());
Assert.assertEquals(code, grammarTransformer.renderPureModelContextData(Objects.requireNonNull(modelData)));
}
Aggregations