use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.Schema in project legend-engine by finos.
the class RelationalCompilerExtension method getExtraExecutionContextProcessors.
@Override
public List<Function2<ExecutionContext, CompileContext, org.finos.legend.pure.m3.coreinstance.meta.pure.runtime.ExecutionContext>> getExtraExecutionContextProcessors() {
return Collections.singletonList((executionContext, context) -> {
if (executionContext instanceof RelationalExecutionContext) {
RelationalExecutionContext relationalContext = (RelationalExecutionContext) executionContext;
MutableMap<Relation, org.finos.legend.pure.m3.coreinstance.meta.pure.functions.collection.List<Column>> fksByTable = Maps.mutable.empty();
ListIterate.forEach(relationalContext.importDataFlowFkCols, fks -> {
org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Schema schema = ((org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.Database) context.pureModel.getStore(fks.table.getDb()))._schemas().detect(s -> s._name().equals(fks.table.schema));
RichIterable<? extends NamedRelation> relations = fks.table._type.equals("Table") ? schema._tables() : fks.table._type.equals("View") ? schema._views() : null;
Relation table = relations != null ? relations.detect(a -> a._name().equals(fks.table.table)) : null;
RichIterable<Column> columns = ListIterate.collect(fks.columns, col -> table != null ? table._columns().select(c -> c instanceof Column).collect(c -> (Column) c).detect(c -> c._name().equals(col)) : null).select(Objects::nonNull);
fksByTable.put(table, new Root_meta_pure_functions_collection_List_Impl("")._values(columns));
});
return new Root_meta_relational_runtime_RelationalExecutionContext_Impl("")._queryTimeOutInSeconds(relationalContext.queryTimeOutInSeconds)._enableConstraints(relationalContext.enableConstraints)._addDriverTablePkForProject(relationalContext.addDriverTablePkForProject)._insertDriverTablePkInTempTable(relationalContext.insertDriverTablePkInTempTable)._useTempTableAsDriver(relationalContext.useTempTableAsDriver)._preserveJoinOrder(relationalContext.preserveJoinOrder)._importDataFlow(relationalContext.importDataFlow)._importDataFlowAddFks(relationalContext.importDataFlowAddFks)._importDataFlowFksByTable(relationalContext.importDataFlowAddFks != null && relationalContext.importDataFlowAddFks ? new PureMap(fksByTable) : null)._importDataFlowImplementationCount(relationalContext.importDataFlowImplementationCount);
}
return null;
});
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.Schema in project legend-engine by finos.
the class RelationalCompilerExtension method getExtraStoreStatBuilders.
@Override
public List<Procedure2<PackageableElement, MutableMap<String, String>>> getExtraStoreStatBuilders() {
return Collections.singletonList((element, stats) -> {
if (element instanceof Database) {
Database db = (Database) element;
stats.put("type", "Database");
stats.put("tables", "" + ListIterate.injectInto(0, db.schemas, (IntObjectToIntFunction<Schema>) (a, b) -> a + b.tables.size()));
stats.put("views", "" + ListIterate.injectInto(0, db.schemas, (IntObjectToIntFunction<Schema>) (a, b) -> a + b.views.size()));
stats.put("joins", "" + db.joins.size());
stats.put("filters", "" + db.filters.size());
}
});
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.Schema in project legend-engine by finos.
the class RelationalParseTreeWalker method generateTableAlias.
private TablePtr generateTableAlias(ScopeInfo scopeInfo, SourceInformation sourceInformation) {
Token schema = scopeInfo.schemaToken;
Token alias = scopeInfo.tableAliasToken;
if (alias == null) {
if (schema == null) {
throw new EngineException("Missing table or alias" + (scopeInfo.columnToken == null ? "" : (" for column '" + scopeInfo.columnToken.getText() + "'")), sourceInformation, EngineErrorType.PARSER);
}
alias = schema;
schema = null;
}
TablePtr tablePtr = new TablePtr();
tablePtr._type = "Table";
String database = scopeInfo.database;
tablePtr.database = database;
tablePtr.mainTableDb = database;
// NOTE: this is a minor inference for the schema name, we might consider moving this to the compiler instead
tablePtr.schema = schema != null ? schema.getText() : "default";
tablePtr.table = alias.getText();
tablePtr.sourceInformation = schema == null ? this.walkerSourceInformation.getSourceInformation(alias) : this.walkerSourceInformation.getSourceInformation(schema, alias);
return tablePtr;
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.Schema in project legend-engine by finos.
the class RelationalParseTreeWalker method visitDatabase.
private Database visitDatabase(RelationalParserGrammar.DatabaseContext ctx) {
Database database = new Database();
database.name = PureGrammarParserUtility.fromIdentifier(ctx.qualifiedName().identifier());
database._package = ctx.qualifiedName().packagePath() == null ? "" : PureGrammarParserUtility.fromPath(ctx.qualifiedName().packagePath().identifier());
database.sourceInformation = this.walkerSourceInformation.getSourceInformation(ctx);
ScopeInfo scopeInfo = ScopeInfo.Builder.newInstance().withDatabase(PureGrammarParserUtility.fromQualifiedName(ctx.qualifiedName().packagePath() == null ? Collections.emptyList() : ctx.qualifiedName().packagePath().identifier(), ctx.qualifiedName().identifier())).build();
database.includedStores = ListIterate.collect(ctx.include(), includeContext -> PureGrammarParserUtility.fromQualifiedName(includeContext.qualifiedName().packagePath() == null ? Collections.emptyList() : includeContext.qualifiedName().packagePath().identifier(), includeContext.qualifiedName().identifier()));
database.schemas = ListIterate.collect(ctx.schema(), schemaCtx -> this.visitSchema(schemaCtx, scopeInfo));
// NOTE: if tables and views are defined without a schema, create a default schema to hold these
List<Table> tables = ListIterate.collect(ctx.table(), this::visitTable);
List<View> views = ListIterate.collect(ctx.view(), viewCtx -> this.visitView(viewCtx, scopeInfo));
if (!tables.isEmpty() || !views.isEmpty()) {
Schema schema = new Schema();
schema.sourceInformation = database.sourceInformation;
schema.name = "default";
schema.tables = tables;
schema.views = views;
database.schemas.add(schema);
}
database.joins = ListIterate.collect(ctx.join(), joinCtx -> this.visitJoin(joinCtx, scopeInfo));
MutableList<Filter> filters = ListIterate.collect(ctx.filter(), filterCtx -> this.visitFilter(filterCtx, scopeInfo));
if (!ctx.multiGrainFilter().isEmpty()) {
filters.addAll(ListIterate.collect(ctx.multiGrainFilter(), filterCtx -> this.visitMultiGrainFilter(filterCtx, scopeInfo)));
}
database.filters = filters;
return database;
}
use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.Schema in project legend-engine by finos.
the class RelationalParseTreeWalker method visitSchema.
// ----------------------------------------------- SCHEMA -----------------------------------------------
public Schema visitSchema(RelationalParserGrammar.SchemaContext ctx, ScopeInfo scopeInfo) {
Schema schema = new Schema();
schema.sourceInformation = this.walkerSourceInformation.getSourceInformation(ctx);
schema.name = PureGrammarParserUtility.fromIdentifier(ctx.identifier());
schema.tables = ListIterate.collect(ctx.table(), this::visitTable);
schema.views = ListIterate.collect(ctx.view(), viewCtx -> this.visitView(viewCtx, ScopeInfo.Builder.newInstance(scopeInfo).withSchemaToken(ctx.identifier().getStart()).build()));
return schema;
}
Aggregations