diff --git a/.gs-project.yml b/.gs-project.yml index 395a8ca8cd5..8d30db88b9c 100644 --- a/.gs-project.yml +++ b/.gs-project.yml @@ -1 +1 @@ -productGuid: "product::315850" +productGuid: "product::776807" diff --git a/legend-engine-config/legend-engine-repl/legend-engine-repl-client/src/main/java/org/finos/legend/engine/repl/autocomplete/parser/ParserFixer.java b/legend-engine-config/legend-engine-repl/legend-engine-repl-client/src/main/java/org/finos/legend/engine/repl/autocomplete/parser/ParserFixer.java index 1ac326a2042..45edea5187e 100644 --- a/legend-engine-config/legend-engine-repl/legend-engine-repl-client/src/main/java/org/finos/legend/engine/repl/autocomplete/parser/ParserFixer.java +++ b/legend-engine-config/legend-engine-repl/legend-engine-repl-client/src/main/java/org/finos/legend/engine/repl/autocomplete/parser/ParserFixer.java @@ -207,13 +207,13 @@ else if (buffer) } if (content.contains("{") && !content.contains("}")) { - return value + "}#"; + return (value.contains(magicToken) ? value : value + magicToken) + "}#"; } if (content.contains("{") && content.contains("}")) { return value + "#"; } - return value + "{}#"; + return value + "{" + magicToken + "}#"; } return value; diff --git a/legend-engine-config/legend-engine-repl/legend-engine-repl-client/src/test/java/org/finos/legend/engine/repl/TestParserFixer.java b/legend-engine-config/legend-engine-repl/legend-engine-repl-client/src/test/java/org/finos/legend/engine/repl/TestParserFixer.java index 35066224fa1..1d391b727f7 100644 --- a/legend-engine-config/legend-engine-repl/legend-engine-repl-client/src/test/java/org/finos/legend/engine/repl/TestParserFixer.java +++ b/legend-engine-config/legend-engine-repl/legend-engine-repl-client/src/test/java/org/finos/legend/engine/repl/TestParserFixer.java @@ -37,11 +37,11 @@ public void testArithmetic() public void testIsland() { Assert.assertEquals("#MaGiCToKeN{}#", fixCode("#")); - Assert.assertEquals("#>{}#", fixCode("#>")); - Assert.assertEquals("#>{}#", fixCode("#>{")); + Assert.assertEquals("#>{MaGiCToKeN}#", fixCode("#>")); + Assert.assertEquals("#>{MaGiCToKeN}#", fixCode("#>{")); Assert.assertEquals("#>{}#", fixCode("#>{}")); Assert.assertEquals("#>{a::A.t}#->fil()", fixCode("#>{a::A.t}#->fil")); - Assert.assertEquals("#>{a::A.t}#->x(#>{}#)", fixCode("#>{a::A.t}#->x(#>")); + Assert.assertEquals("#>{a::A.t}#->x(#>{MaGiCToKeN}#)", fixCode("#>{a::A.t}#->x(#>")); Assert.assertEquals("#>{a::A.t}#->x(#>{a::A.MaGiCToKeN}#)", fixCode("#>{a::A.t}#->x(#>{a::A.")); } diff --git a/legend-engine-config/legend-engine-repl/legend-engine-repl-relational/pom.xml b/legend-engine-config/legend-engine-repl/legend-engine-repl-relational/pom.xml index 51a4476a61a..6cde9e43bda 100644 --- a/legend-engine-config/legend-engine-repl/legend-engine-repl-relational/pom.xml +++ b/legend-engine-config/legend-engine-repl/legend-engine-repl-relational/pom.xml @@ -31,11 +31,7 @@ org.finos.legend.engine legend-engine-repl-client - - - org.finos.legend.pure - legend-pure-m4 - + org.finos.legend.pure legend-pure-m3-core @@ -151,5 +147,13 @@ junit test + + org.finos.legend.engine + legend-engine-protocol + + + org.finos.legend.engine + legend-engine-xt-relationalStore-grammar + diff --git a/legend-engine-config/legend-engine-repl/legend-engine-repl-relational/src/main/java/org/finos/legend/engine/repl/relational/autocomplete/RelationalCompleterExtension.java b/legend-engine-config/legend-engine-repl/legend-engine-repl-relational/src/main/java/org/finos/legend/engine/repl/relational/autocomplete/RelationalCompleterExtension.java index cd545909f91..d137949a496 100644 --- a/legend-engine-config/legend-engine-repl/legend-engine-repl-relational/src/main/java/org/finos/legend/engine/repl/relational/autocomplete/RelationalCompleterExtension.java +++ b/legend-engine-config/legend-engine-repl/legend-engine-repl-relational/src/main/java/org/finos/legend/engine/repl/relational/autocomplete/RelationalCompleterExtension.java @@ -15,9 +15,12 @@ package org.finos.legend.engine.repl.relational.autocomplete; import org.eclipse.collections.api.list.MutableList; +import org.eclipse.collections.api.set.SetIterable; import org.eclipse.collections.impl.factory.Lists; import org.eclipse.collections.impl.utility.ListIterate; +import org.finos.legend.engine.language.pure.compiler.toPureGraph.HelperRelationalBuilder; import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel; +import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation; import org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.classInstance.relation.RelationStoreAccessor; import org.finos.legend.engine.repl.autocomplete.CompleterExtension; import org.finos.legend.engine.repl.autocomplete.CompletionItem; @@ -25,6 +28,9 @@ import org.finos.legend.engine.repl.autocomplete.parser.ParserFixer; import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement; import org.finos.legend.pure.m3.coreinstance.meta.pure.store.Store; +import org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Database; +import org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Schema; +import org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.relation.Table; public class RelationalCompleterExtension implements CompleterExtension { @@ -33,32 +39,57 @@ public CompletionResult extraClassInstanceProcessor(Object islandExpr, PureModel { if (islandExpr instanceof RelationStoreAccessor) { - MutableList path = Lists.mutable.withAll(((RelationStoreAccessor) islandExpr).path); - String writtenPath = path.makeString("::").replace(ParserFixer.magicToken, ""); - MutableList elements = pureModel.getAllStores().select(c -> nameMatch(c, writtenPath)).toList(); - if (elements.size() == 1 && - writtenPath.startsWith(org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.getUserPathForPackageableElement(elements.get(0))) && - !writtenPath.equals(org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.getUserPathForPackageableElement(elements.get(0))) - ) + RelationStoreAccessor relationStoreAccessor = (RelationStoreAccessor) islandExpr; + MutableList path = Lists.adapt(relationStoreAccessor.path); + + if (path.anySatisfy(x -> x.isEmpty() || x.contains(ParserFixer.magicToken))) { - org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Database db = (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Database) elements.get(0); - String tableName = writtenPath.replace(org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.getUserPathForPackageableElement(db), "").replace("::", ""); - MutableList tables = db._schemas().isEmpty() ? Lists.mutable.empty() : db._schemas().getFirst()._tables().toList(); - MutableList foundTables = tables.select(c -> c._name().startsWith(tableName)); - if ((foundTables.size() == 1 && foundTables.get(0)._name().equals(path.getLast()))) + String writtenPath = path.get(0).replace(ParserFixer.magicToken, ""); + MutableList elements = pureModel.getAllStores().select(c -> nameMatch(c, writtenPath)).toList(); + + MutableList completionItems = Lists.mutable.empty(); + + if (elements.size() == 1 && path.size() > 1) { - return new CompletionResult(Lists.mutable.empty()); + org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Database db = (org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Database) elements.get(0); + + if (path.size() < 3) + { + String tableOrSchema = path.get(1).replace(ParserFixer.magicToken, "").replace("::", ""); + completionItems.addAll(getTableSuggestions(db, "default", tableOrSchema)); + completionItems.addAll(getSchemaSuggestions(db, tableOrSchema)); + } + else + { + String schema = path.get(1); + String tableName = path.get(2).replace(ParserFixer.magicToken, "").replace("::", ""); + completionItems.addAll(getTableSuggestions(db, schema, tableName)); + } } else { - return new CompletionResult(foundTables.collect(c -> new CompletionItem(c._name(), c._name() + "}"))); + ListIterate.collect(elements, c -> new CompletionItem(org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.getUserPathForPackageableElement(c), ">{" + org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.getUserPathForPackageableElement(c) + '.'), completionItems); } + + return new CompletionResult(completionItems); } - return new CompletionResult(ListIterate.collect(elements, c -> new CompletionItem(org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.getUserPathForPackageableElement(c), ">{" + org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.getUserPathForPackageableElement(c))).toList()); } return null; } + private static MutableList getSchemaSuggestions(Database db, String schemaName) + { + MutableList foundSchemas = db._schemas().select(schema -> !schema._name().equals("default") && schema._name().startsWith(schemaName)).toSortedListBy(Schema::_name); + return foundSchemas.collect(c -> new CompletionItem(c._name(), c._name() + ".")); + } + + private static MutableList getTableSuggestions(Database db, String schemaName, String tableName) + { + SetIterable tables = HelperRelationalBuilder.getAllTablesInSchema(db, schemaName, SourceInformation.getUnknownSourceInformation()); + MutableList foundTables = tables.select(c -> c._name().startsWith(tableName)).toSortedListBy(Table::_name); + return foundTables.collect(c -> new CompletionItem(c._name(), c._name() + "}#")); + } + private static boolean nameMatch(PackageableElement c, String writtenPath) { String path = org.finos.legend.pure.m3.navigation.PackageableElement.PackageableElement.getUserPathForPackageableElement(c); diff --git a/legend-engine-config/legend-engine-repl/legend-engine-repl-relational/src/test/java/org/finos/legend/engine/repl/TestCompleter.java b/legend-engine-config/legend-engine-repl/legend-engine-repl-relational/src/test/java/org/finos/legend/engine/repl/TestCompleter.java index bda185e1554..765318f827b 100644 --- a/legend-engine-config/legend-engine-repl/legend-engine-repl-relational/src/test/java/org/finos/legend/engine/repl/TestCompleter.java +++ b/legend-engine-config/legend-engine-repl/legend-engine-repl-relational/src/test/java/org/finos/legend/engine/repl/TestCompleter.java @@ -26,12 +26,16 @@ public class TestCompleter @Test public void testRelationAccessor() { - Assert.assertEquals("[a::A , >{a::A]", checkResultNoException(new Completer("###Relational\nDatabase a::A(Table t(col VARCHAR(200)))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>"))); - Assert.assertEquals("[a::other , >{a::other], [a::ABC , >{a::ABC]", checkResultNoException(new Completer("###Relational\nDatabase a::ABC(Table t(col VARCHAR(200)))\nDatabase a::other(Table t(col VARCHAR(200)))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a"))); - Assert.assertEquals("[a::ABC , >{a::ABC]", checkResultNoException(new Completer("###Relational\nDatabase a::ABC(Table t(col VARCHAR(200)))\nDatabase a::other(Table t(col VARCHAR(200)))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::A"))); - Assert.assertEquals("[a::ABC , >{a::ABC]", checkResultNoException(new Completer("###Relational\nDatabase a::ABC(Table t(col VARCHAR(200)))\nDatabase a::other(Table t(col VARCHAR(200)))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::ABC"))); - Assert.assertEquals("[t , t}]", checkResultNoException(new Completer("###Relational\nDatabase a::ABC(Table t(col VARCHAR(200)))\nDatabase a::other(Table t(col VARCHAR(200)))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::ABC."))); - Assert.assertEquals("[tab , tab}]", checkResultNoException(new Completer("###Relational\nDatabase a::A(Table co(val INTEGER) Table tab(col VARCHAR(200)))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::A.t"))); + Assert.assertEquals("[a::A , >{a::A.]", checkResultNoException(new Completer("###Relational\nDatabase a::A(Table t(col VARCHAR(200)))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>"))); + Assert.assertEquals("[a::other , >{a::other.], [a::ABC , >{a::ABC.]", checkResultNoException(new Completer("###Relational\nDatabase a::ABC(Table t(col VARCHAR(200)))\nDatabase a::other(Table t(col VARCHAR(200)))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a"))); + Assert.assertEquals("[a::ABC , >{a::ABC.]", checkResultNoException(new Completer("###Relational\nDatabase a::ABC(Table t(col VARCHAR(200)))\nDatabase a::other(Table t(col VARCHAR(200)))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::A"))); + Assert.assertEquals("[a::ABC , >{a::ABC.]", checkResultNoException(new Completer("###Relational\nDatabase a::ABC(Table t(col VARCHAR(200)))\nDatabase a::other(Table t(col VARCHAR(200)))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::ABC"))); + Assert.assertEquals("[t , t}#]", checkResultNoException(new Completer("###Relational\nDatabase a::ABC(Table t(col VARCHAR(200)))\nDatabase a::other(Table t(col VARCHAR(200)))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::ABC."))); + Assert.assertEquals("[at , at}#], [t , t}#], [ts , ts.]", checkResultNoException(new Completer("###Relational\nDatabase a::ABC(Schema ts(Table t(col VARCHAR(200))) Table t(col VARCHAR(200)) Table at(col VARCHAR(200)))\nDatabase a::other(Table t(col VARCHAR(200)))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::ABC."))); + Assert.assertEquals("[t , t}#], [ts , ts.]", checkResultNoException(new Completer("###Relational\nDatabase a::ABC(Schema ts(Table t(col VARCHAR(200))) Table t(col VARCHAR(200)) Table at(col VARCHAR(200)))\nDatabase a::other(Table t(col VARCHAR(200)))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::ABC.t"))); + Assert.assertEquals("[ts , ts.]", checkResultNoException(new Completer("###Relational\nDatabase a::ABC(Schema ts(Table t(col VARCHAR(200))) Table t(col VARCHAR(200)) Table at(col VARCHAR(200)))\nDatabase a::other(Table t(col VARCHAR(200)))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::ABC.ts"))); + Assert.assertEquals("[t , t}#]", checkResultNoException(new Completer("###Relational\nDatabase a::ABC(Schema ts(Table t(col VARCHAR(200))) Table t(col VARCHAR(200)) Table at(col VARCHAR(200)))\nDatabase a::other(Table t(col VARCHAR(200)))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::ABC.ts."))); + Assert.assertEquals("[tab , tab}#]", checkResultNoException(new Completer("###Relational\nDatabase a::A(Table co(val INTEGER) Table tab(col VARCHAR(200)))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::A.t"))); Assert.assertEquals("", checkResultNoException(new Completer("###Relational\nDatabase a::A(Table tab(col VARCHAR(200)))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::A.x"))); Assert.assertEquals("", checkResultNoException(new Completer("###Relational\nDatabase a::A(Table co(val INTEGER) Table tab(col VARCHAR(200)))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::A.tab}#"))); } @@ -189,8 +193,8 @@ public void testRelationCast() @Test public void testJoin() { - Assert.assertEquals("[a::A , >{a::A]", checkResultNoException(new Completer("###Relational\nDatabase a::A(Table t(col VARCHAR(200), val INT))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::A.t}#->join(#>"))); - Assert.assertEquals("[t , t}]", checkResultNoException(new Completer("###Relational\nDatabase a::A(Table t(col VARCHAR(200), val INT))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::A.t}#->join(#>{a::A."))); + Assert.assertEquals("[a::A , >{a::A.]", checkResultNoException(new Completer("###Relational\nDatabase a::A(Table t(col VARCHAR(200), val INT))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::A.t}#->join(#>"))); + Assert.assertEquals("[t , t}#]", checkResultNoException(new Completer("###Relational\nDatabase a::A(Table t(col VARCHAR(200), val INT))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::A.t}#->join(#>{a::A."))); Assert.assertEquals("[JoinKind , JoinKind.]", checkResultNoException(new Completer("###Relational\nDatabase a::A(Table t(col VARCHAR(200), val INT))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::A.t}#->join(#>{a::A.t}#, "))); Assert.assertEquals("[LEFT , LEFT], [INNER , INNER]", checkResultNoException(new Completer("###Relational\nDatabase a::A(Table t(col VARCHAR(200), val INT))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::A.t}#->join(#>{a::A.t}#, JoinKind."))); Assert.assertEquals("[col , col], [val , val]", checkResultNoException(new Completer("###Relational\nDatabase a::A(Table t(col VARCHAR(200), val INT))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::A.t}#->join(#>{a::A.t}#, JoinKind.INNER, {a,b|$a."))); @@ -205,8 +209,8 @@ public void testJoin() @Test public void testAsOfJoin() { - Assert.assertEquals("[a::A , >{a::A]", checkResultNoException(new Completer("###Relational\nDatabase a::A(Table t(col VARCHAR(200), val INT))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::A.t}#->asOfJoin(#>"))); - Assert.assertEquals("[t , t}]", checkResultNoException(new Completer("###Relational\nDatabase a::A(Table t(col VARCHAR(200), val INT))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::A.t}#->asOfJoin(#>{a::A."))); + Assert.assertEquals("[a::A , >{a::A.]", checkResultNoException(new Completer("###Relational\nDatabase a::A(Table t(col VARCHAR(200), val INT))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::A.t}#->asOfJoin(#>"))); + Assert.assertEquals("[t , t}#]", checkResultNoException(new Completer("###Relational\nDatabase a::A(Table t(col VARCHAR(200), val INT))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::A.t}#->asOfJoin(#>{a::A."))); Assert.assertEquals("[col , col], [val , val]", checkResultNoException(new Completer("###Relational\nDatabase a::A(Table t(col VARCHAR(200), val INT))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::A.t}#->asOfJoin(#>{a::A.t}#, {a,b|$a."))); Assert.assertEquals("", checkResultNoException(new Completer("###Relational\nDatabase a::A(Table t(col VARCHAR(200), val INT))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::A.t}#->asOfJoin(#>{a::A.t}#,"))); Assert.assertEquals("[k , k], [o , o]", checkResultNoException(new Completer("###Relational\nDatabase a::A(Table t2(k VARCHAR(200), o INT) Table t(col VARCHAR(200), val INT))", Lists.mutable.with(new RelationalCompleterExtension())).complete("#>{a::A.t}#->asOfJoin(#>{a::A.t2}#, {a,b|$a.col == $b."))); diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-PCT/legend-engine-pure-functions-relationalStore-PCT-pure/src/main/resources/core_external_test_connection/pct_relational.pure b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-PCT/legend-engine-pure-functions-relationalStore-PCT-pure/src/main/resources/core_external_test_connection/pct_relational.pure index 6564e970383..28aa66a71f1 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-PCT/legend-engine-pure-functions-relationalStore-PCT-pure/src/main/resources/core_external_test_connection/pct_relational.pure +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-PCT/legend-engine-pure-functions-relationalStore-PCT-pure/src/main/resources/core_external_test_connection/pct_relational.pure @@ -269,7 +269,12 @@ function meta::relational::tests::pct::process::reprocess(f:Function[1], db ], extraInstanceValueHandlers = [ - x:RelationStoreAccessor[1]|'#>{'+$x.store->elementToPath()+'.'+$x.sourceElement->cast(@Table).name->toOne()+'}#', + x:RelationStoreAccessor[1]| + let table = $x.sourceElement->cast(@Table); + let schema = $table.schema; + let schemaName = if ($schema.name == 'default', |'', |$schema.name + '.'); + '#>{' + $x.store->elementToPath() + '.' + $schemaName + $table.name->toOne() + '}#'; + , t:meta::pure::metamodel::relation::TDS[1]|'#TDS\n'+$t.csv->replace(' ','')+'#' ] ) diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperRelationalBuilder.java b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperRelationalBuilder.java index 326fd2bc8a6..5eb03a9646e 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperRelationalBuilder.java +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/HelperRelationalBuilder.java @@ -270,9 +270,14 @@ public static Filter getFilter(Database db, String _filterName, SourceInformatio } public static Schema getSchema(Database db, final String _schema) + { + return getSchema(db, _schema, SourceInformation.getUnknownSourceInformation()); + } + + public static Schema getSchema(Database db, final String _schema, SourceInformation sourceInformation) { Schema s = db._schemas().detect(schema -> _schema.equals(schema.getName())); - Assert.assertTrue(s != null, () -> "Can't find schema '" + _schema + "' in database '" + db.getName() + "'"); + Assert.assertTrue(s != null, () -> "Can't find schema '" + _schema + "' in database '" + db.getName() + "'", sourceInformation, EngineErrorType.COMPILATION); return s; } @@ -379,7 +384,7 @@ private static SetIterable
getAllTables(Database db, Predicate sc return tables; } - private static boolean schemaExists(Database database, String schemaName) + public static boolean schemaExists(Database database, String schemaName) { return DEFAULT_SCHEMA_NAME.equals(schemaName) || schemaExists(Sets.mutable.empty(), database, schemaName); } diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/RelationalCompilerExtension.java b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/RelationalCompilerExtension.java index 5738b689924..ac34cd61766 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/RelationalCompilerExtension.java +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/main/java/org/finos/legend/engine/language/pure/compiler/toPureGraph/RelationalCompilerExtension.java @@ -788,20 +788,11 @@ public List c.getName().equals(schemaName)).getFirst(); - if (schema == null) - { - throw new EngineException(schemaName == null ? "The database " + store._name() + " has no schemas" : "The schema " + schemaName + " can't be found in the store " + store._name(), accessor.sourceInformation, EngineErrorType.COMPILATION); - } - Table table = schema._tables().select(c -> c.getName().equals(tableName)).getFirst(); - if (table == null) - { - throw new EngineException("The table " + accessor.path.get(1) + " can't be found in the store " + store._name(), accessor.sourceInformation, EngineErrorType.COMPILATION); - } - + org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Schema schema = HelperRelationalBuilder.getSchema(ds, schemaName, accessor.sourceInformation); + Table table = (Table) HelperRelationalBuilder.getRelation(schema, tableName, accessor.sourceInformation); ProcessorSupport processorSupport = context.pureModel.getExecutionSupport().getProcessorSupport(); org.finos.legend.pure.m4.coreinstance.SourceInformation sourceInformation = null; diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/test/java/org/finos/legend/engine/language/pure/compiler/test/TestRelationStoreAccessorFromGrammar.java b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/test/java/org/finos/legend/engine/language/pure/compiler/test/TestRelationStoreAccessorFromGrammar.java index 179b7a77d3b..4c22a02c8a6 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/test/java/org/finos/legend/engine/language/pure/compiler/test/TestRelationStoreAccessorFromGrammar.java +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/test/java/org/finos/legend/engine/language/pure/compiler/test/TestRelationStoreAccessorFromGrammar.java @@ -123,34 +123,27 @@ public void testCompilationWithSchemaError() " #>{my::Store.SchemaMissing.myTable}#->filter(\n" + " c|$c.name == 'ok'\n" + " )\n" + - "}\n", "COMPILATION error at [19:3-38]: The schema SchemaMissing can't be found in the store Store"); + "}\n", "COMPILATION error at [19:3-38]: Can't find schema 'SchemaMissing' in database 'Store'"); } @Test public void testCompilationOfRelationStoreAccessorUnknownTable() { - try - { - test("###Relational\n" + - "Database my::Store" + - "(" + - " Table myTable" + - " (" + - " id INT," + - " name VARCHAR(200)" + - " )" + - ")\n" + - "###Pure\n" + - "function my::func():Any[*]" + - "{" + - " #>{my::Store.myTabe}#->filter(c|$c.name == 'ok');" + - "}"); - Assert.fail(); - } - catch (EngineException e) - { - Assert.assertEquals("COMPILATION error at [4:31-51]: The table myTabe can't be found in the store Store", e.toPretty()); - } + test("###Relational\n" + + "Database my::Store" + + "(" + + " Table myTable" + + " (" + + " id INT," + + " name VARCHAR(200)" + + " )" + + ")\n" + + "###Pure\n" + + "function my::func():Any[*]" + + "{" + + " #>{my::Store.myTabe}#->filter(c|$c.name == 'ok');" + + "}", + "COMPILATION error at [4:31-51]: Can't find table 'myTabe' in schema 'default' and database 'Store'"); } @Test @@ -184,28 +177,22 @@ public void testCompilationOfRelationStoreAccessorUnknownColumn() @Test public void testCompilationErrorMissingTable() { - try - { - test("###Relational\n" + - "Database my::Store" + - "(" + - " Table myTable" + - " (" + - " id INT," + - " name VARCHAR(200)" + - " )" + - ")\n" + - "###Pure\n" + - "function my::func():Any[*]" + - "{" + - " #>{my::Store}#->filter(c|$c.naeme == 'ok');" + - "}"); - Assert.fail(); - } - catch (EngineException e) - { - Assert.assertEquals("COMPILATION error at [4:31-44]: Error in the accessor definition. Please provide a table.", e.toPretty()); - } + test("###Relational\n" + + "Database my::Store" + + "(" + + " Table myTable" + + " (" + + " id INT," + + " name VARCHAR(200)" + + " )" + + ")\n" + + "###Pure\n" + + "function my::func():Any[*]" + + "{" + + " #>{my::Store}#->filter(c|$c.naeme == 'ok');" + + "}", + "COMPILATION error at [4:31-44]: Error in the accessor definition. Please provide a table." + ); } @Override diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/test/java/org/finos/legend/engine/language/pure/compiler/test/TestRelationalMapperCompilationFromGrammar.java b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/test/java/org/finos/legend/engine/language/pure/compiler/test/TestRelationalMapperCompilationFromGrammar.java index 21be6f47bbb..318f1136358 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/test/java/org/finos/legend/engine/language/pure/compiler/test/TestRelationalMapperCompilationFromGrammar.java +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-grammar/src/test/java/org/finos/legend/engine/language/pure/compiler/test/TestRelationalMapperCompilationFromGrammar.java @@ -151,7 +151,7 @@ public void testInvalidSchema() " test::OrganizationsDB.Productt -> 'ProductSchema'\n" + " ];\n" + ")", - " at [20:1-26:1]: Error in 'test::testMapper': Can't find schema 'Productt' in database 'OrganizationsDB'" + "COMPILATION error at [20:1-26:1]: Error in 'test::testMapper': Can't find schema 'Productt' in database 'OrganizationsDB'" ); }