use of org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch in project legend-engine by finos.
the class ConnectionManagerSelector method transformToTestConnectionSpecification.
public static org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.Connection transformToTestConnectionSpecification(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.Connection originalConnection, String testData, List<String> setupSqls) {
RelationalDatabaseConnection db = new RelationalDatabaseConnection();
db.datasourceSpecification = new org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.specification.LocalH2DatasourceSpecification(testData, setupSqls);
db.authenticationStrategy = new TestDatabaseAuthenticationStrategy();
db.databaseType = DatabaseType.H2;
db.type = DatabaseType.H2;
db.element = originalConnection.element;
db.timeZone = originalConnection instanceof DatabaseConnection ? ((DatabaseConnection) originalConnection).timeZone : null;
db.quoteIdentifiers = originalConnection instanceof DatabaseConnection ? ((DatabaseConnection) originalConnection).quoteIdentifiers : null;
return db;
}
use of org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch in project legend-engine by finos.
the class HelperRelationalBuilder method processRelationalOperationElement.
public static RelationalOperationElement processRelationalOperationElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.RelationalOperationElement operationElement, CompileContext context, MutableMap<String, org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAlias> aliasMap, MutableList<org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAliasColumn> selfJoinTargets) {
if (operationElement instanceof org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.TableAliasColumn) {
org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.TableAliasColumn tableAliasColumn = (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.TableAliasColumn) operationElement;
// Self join
if (tableAliasColumn.table.table.equals(SELF_JOIN_TABLE_NAME) && tableAliasColumn.tableAlias.equals(SELF_JOIN_TABLE_NAME)) {
org.finos.legend.pure.m3.coreinstance.meta.relational.metamodel.TableAliasColumn selfJoin = new Root_meta_relational_metamodel_TableAliasColumn_Impl("")._columnName(tableAliasColumn.column);
selfJoinTargets.add(selfJoin);
return selfJoin;
}
Relation relation = getRelation((Database) context.resolveStore(tableAliasColumn.table.database, tableAliasColumn.table.sourceInformation), tableAliasColumn.table.schema, tableAliasColumn.table.table, tableAliasColumn.table.sourceInformation);
Column col = getColumn(relation, tableAliasColumn.column, tableAliasColumn.sourceInformation);
TableAlias alias = aliasMap.getIfAbsentPut(tableAliasColumn.table.schema + "." + tableAliasColumn.tableAlias, (Function0<TableAlias>) () -> new Root_meta_relational_metamodel_TableAlias_Impl("")._name(tableAliasColumn.tableAlias)._relationalElement(col._owner())._database(HelperRelationalBuilder.resolveDatabase(tableAliasColumn.table.getDb(), tableAliasColumn.table.sourceInformation, context)));
return new Root_meta_relational_metamodel_TableAliasColumn_Impl("")._columnName(col._name())._column(col)._alias(alias);
} else if (operationElement instanceof ElementWithJoins) {
ElementWithJoins elementWithJoins = (ElementWithJoins) operationElement;
RelationalOperationElementWithJoin res = new Root_meta_relational_metamodel_RelationalOperationElementWithJoin_Impl("")._joinTreeNode(buildElementWithJoinsJoinTreeNode(elementWithJoins.joins, context));
return elementWithJoins.relationalElement == null ? res : res._relationalOperationElement(processRelationalOperationElement(elementWithJoins.relationalElement, context, UnifiedMap.newMap(), selfJoinTargets));
} else if (operationElement instanceof DynaFunc) {
DynaFunc dynaFunc = (DynaFunc) operationElement;
MutableList<RelationalOperationElement> ps = ListIterate.collect(dynaFunc.parameters, relationalOperationElement -> processRelationalOperationElement(relationalOperationElement, context, aliasMap, selfJoinTargets));
return new Root_meta_relational_metamodel_DynaFunction_Impl("")._name(dynaFunc.funcName)._parameters(ps);
} else if (operationElement instanceof org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.Literal) {
org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.Literal literal = (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.Literal) operationElement;
return new Root_meta_relational_metamodel_Literal_Impl("")._value(convertLiteral(convertLiteral(literal.value)));
} else if (operationElement instanceof org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.LiteralList) {
org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.LiteralList literalList = (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.LiteralList) operationElement;
return new Root_meta_relational_metamodel_LiteralList_Impl("")._values(ListIterate.collect(literalList.values, l -> new Root_meta_relational_metamodel_Literal_Impl("")._value(convertLiteral(l.value))));
}
throw new UnsupportedOperationException();
}
use of org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch in project legend-engine by finos.
the class RelationalParseTreeWalker method visitColumnDefinition.
private Column visitColumnDefinition(RelationalParserGrammar.ColumnDefinitionContext ctx, List<String> primaryKeys) {
Column column = new Column();
column.sourceInformation = this.walkerSourceInformation.getSourceInformation(ctx);
column.name = ctx.relationalIdentifier().getText();
boolean nullable = true;
if (ctx.PRIMARY_KEY() != null) {
nullable = false;
primaryKeys.add(column.name);
} else if (ctx.NOT_NULL() != null) {
nullable = false;
}
column.nullable = nullable;
String dataType = PureGrammarParserUtility.fromIdentifier(ctx.identifier());
switch(dataType.toUpperCase()) {
// String
case "CHAR":
{
if (ctx.INTEGER().size() == 1) {
Char type = new Char();
type.size = Integer.parseInt(ctx.INTEGER().get(0).getText());
column.type = type;
} else {
throw new EngineException("Column data type CHAR requires 1 parameter (size) in declaration", this.walkerSourceInformation.getSourceInformation(ctx.identifier().getStart(), ctx.PAREN_CLOSE() != null ? ctx.PAREN_CLOSE().getSymbol() : ctx.identifier().getStop()), EngineErrorType.PARSER);
}
break;
}
case "VARCHAR":
{
if (ctx.INTEGER().size() == 1) {
VarChar type = new VarChar();
type.size = Integer.parseInt(ctx.INTEGER().get(0).getText());
column.type = type;
} else {
throw new EngineException("Column data type VARCHAR requires 1 parameter (size) in declaration", this.walkerSourceInformation.getSourceInformation(ctx.identifier().getStart(), ctx.PAREN_CLOSE() != null ? ctx.PAREN_CLOSE().getSymbol() : ctx.identifier().getStop()), EngineErrorType.PARSER);
}
break;
}
// Binary
case "BINARY":
{
if (ctx.INTEGER().size() == 1) {
Binary type = new Binary();
type.size = Integer.parseInt(ctx.INTEGER().get(0).getText());
column.type = type;
} else {
throw new EngineException("Column data type BINARY requires 1 parameter (size) in declaration", this.walkerSourceInformation.getSourceInformation(ctx.identifier().getStart(), ctx.PAREN_CLOSE() != null ? ctx.PAREN_CLOSE().getSymbol() : ctx.identifier().getStop()), EngineErrorType.PARSER);
}
break;
}
case "VARBINARY":
{
if (ctx.INTEGER().size() == 1) {
Varbinary type = new Varbinary();
type.size = Integer.parseInt(ctx.INTEGER().get(0).getText());
column.type = type;
} else {
throw new EngineException("Column data type VARBINARY requires 1 parameter (size) in declaration", this.walkerSourceInformation.getSourceInformation(ctx.identifier().getStart(), ctx.PAREN_CLOSE() != null ? ctx.PAREN_CLOSE().getSymbol() : ctx.identifier().getStop()), EngineErrorType.PARSER);
}
break;
}
case "BIT":
{
column.type = new Bit();
if (!ctx.INTEGER().isEmpty()) {
throw new EngineException("Column data type BIT does not expect any parameters in declaration", this.walkerSourceInformation.getSourceInformation(ctx.identifier().getStart(), ctx.PAREN_CLOSE() != null ? ctx.PAREN_CLOSE().getSymbol() : ctx.identifier().getStop()), EngineErrorType.PARSER);
}
break;
}
// Integer
case "INT":
case "INTEGER":
{
column.type = new org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.datatype.Integer();
if (!ctx.INTEGER().isEmpty()) {
throw new EngineException("Column data type INTEGER does not expect any parameters in declaration", this.walkerSourceInformation.getSourceInformation(ctx.identifier().getStart(), ctx.PAREN_CLOSE() != null ? ctx.PAREN_CLOSE().getSymbol() : ctx.identifier().getStop()), EngineErrorType.PARSER);
}
break;
}
case "BIGINT":
{
column.type = new BigInt();
if (!ctx.INTEGER().isEmpty()) {
throw new EngineException("Column data type BIGINT does not expect any parameters in declaration", this.walkerSourceInformation.getSourceInformation(ctx.identifier().getStart(), ctx.PAREN_CLOSE() != null ? ctx.PAREN_CLOSE().getSymbol() : ctx.identifier().getStop()), EngineErrorType.PARSER);
}
break;
}
case "SMALLINT":
{
column.type = new SmallInt();
if (!ctx.INTEGER().isEmpty()) {
throw new EngineException("Column data type SMALLINT does not expect any parameters in declaration", this.walkerSourceInformation.getSourceInformation(ctx.identifier().getStart(), ctx.PAREN_CLOSE() != null ? ctx.PAREN_CLOSE().getSymbol() : ctx.identifier().getStop()), EngineErrorType.PARSER);
}
break;
}
case "TINYINT":
{
column.type = new TinyInt();
if (!ctx.INTEGER().isEmpty()) {
throw new EngineException("Column data type TINYINT does not expect any parameters in declaration", this.walkerSourceInformation.getSourceInformation(ctx.identifier().getStart(), ctx.PAREN_CLOSE() != null ? ctx.PAREN_CLOSE().getSymbol() : ctx.identifier().getStop()), EngineErrorType.PARSER);
}
break;
}
// Timestamp
case "TIMESTAMP":
{
column.type = new Timestamp();
if (!ctx.INTEGER().isEmpty()) {
throw new EngineException("Column data type TIMESTAMP does not expect any parameters in declaration", this.walkerSourceInformation.getSourceInformation(ctx.identifier().getStart(), ctx.PAREN_CLOSE() != null ? ctx.PAREN_CLOSE().getSymbol() : ctx.identifier().getStop()), EngineErrorType.PARSER);
}
break;
}
case "DATE":
{
column.type = new Date();
if (!ctx.INTEGER().isEmpty()) {
throw new EngineException("Column data type DATE does not expect any parameters in declaration", this.walkerSourceInformation.getSourceInformation(ctx.identifier().getStart(), ctx.PAREN_CLOSE() != null ? ctx.PAREN_CLOSE().getSymbol() : ctx.identifier().getStop()), EngineErrorType.PARSER);
}
break;
}
// Numeric
case "NUMERIC":
{
if (ctx.INTEGER().size() == 2) {
Numeric type = new Numeric();
type.precision = Integer.parseInt(ctx.INTEGER().get(0).getText());
type.scale = Integer.parseInt(ctx.INTEGER().get(1).getText());
column.type = type;
} else {
throw new EngineException("Column data type NUMERIC requires 2 parameters (precision, scale) in declaration", this.walkerSourceInformation.getSourceInformation(ctx.identifier().getStart(), ctx.PAREN_CLOSE() != null ? ctx.PAREN_CLOSE().getSymbol() : ctx.identifier().getStop()), EngineErrorType.PARSER);
}
break;
}
case "DECIMAL":
{
if (ctx.INTEGER().size() == 2) {
Decimal type = new Decimal();
type.precision = Integer.parseInt(ctx.INTEGER().get(0).getText());
type.scale = Integer.parseInt(ctx.INTEGER().get(1).getText());
column.type = type;
} else {
throw new EngineException("Column data type DECIMAL requires 2 parameters (precision, scale) in declaration", this.walkerSourceInformation.getSourceInformation(ctx.identifier().getStart(), ctx.PAREN_CLOSE() != null ? ctx.PAREN_CLOSE().getSymbol() : ctx.identifier().getStop()), EngineErrorType.PARSER);
}
break;
}
case "FLOAT":
{
column.type = new org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.datatype.Float();
if (!ctx.INTEGER().isEmpty()) {
throw new EngineException("Column data type FLOAT does not expect any parameters in declaration", this.walkerSourceInformation.getSourceInformation(ctx.identifier().getStart(), ctx.PAREN_CLOSE() != null ? ctx.PAREN_CLOSE().getSymbol() : ctx.identifier().getStop()), EngineErrorType.PARSER);
}
break;
}
case "DOUBLE":
{
column.type = new org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.datatype.Double();
if (!ctx.INTEGER().isEmpty()) {
throw new EngineException("Column data type DOUBLE does not expect any parameters in declaration", this.walkerSourceInformation.getSourceInformation(ctx.identifier().getStart(), ctx.PAREN_CLOSE() != null ? ctx.PAREN_CLOSE().getSymbol() : ctx.identifier().getStop()), EngineErrorType.PARSER);
}
break;
}
case "REAL":
{
column.type = new Real();
if (!ctx.INTEGER().isEmpty()) {
throw new EngineException("Column data type REAL does not expect any parameters in declaration", this.walkerSourceInformation.getSourceInformation(ctx.identifier().getStart(), ctx.PAREN_CLOSE() != null ? ctx.PAREN_CLOSE().getSymbol() : ctx.identifier().getStop()), EngineErrorType.PARSER);
}
break;
}
// Other
case "ARRAY":
{
column.type = new Other();
if (!ctx.INTEGER().isEmpty()) {
throw new EngineException("Column data type ARRAY does not expect any parameters in declaration", this.walkerSourceInformation.getSourceInformation(ctx.identifier().getStart(), ctx.PAREN_CLOSE() != null ? ctx.PAREN_CLOSE().getSymbol() : ctx.identifier().getStop()), EngineErrorType.PARSER);
}
break;
}
case "OTHER":
{
column.type = new Other();
if (!ctx.INTEGER().isEmpty()) {
throw new EngineException("Column data type OTHER does not expect any parameters in declaration", this.walkerSourceInformation.getSourceInformation(ctx.identifier().getStart(), ctx.PAREN_CLOSE() != null ? ctx.PAREN_CLOSE().getSymbol() : ctx.identifier().getStop()), EngineErrorType.PARSER);
}
break;
}
case "SEMISTRUCTURED":
{
column.type = new SemiStructured();
if (!ctx.INTEGER().isEmpty()) {
throw new EngineException("Column data type SEMISTRUCTURED does not expect any parameters in declaration", this.walkerSourceInformation.getSourceInformation(ctx.identifier().getStart(), ctx.PAREN_CLOSE() != null ? ctx.PAREN_CLOSE().getSymbol() : ctx.identifier().getStop()), EngineErrorType.PARSER);
}
break;
}
default:
{
throw new EngineException("Unsupported column data type '" + dataType + "'", this.walkerSourceInformation.getSourceInformation(ctx.identifier()), EngineErrorType.PARSER);
}
}
return column;
}
use of org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch in project legend-engine by finos.
the class HelperMappingBuilder method processAggregateSpecification.
private static AggregateSpecification processAggregateSpecification(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.aggregationAware.AggregateSpecification aggregateSpecification, CompileContext context, MutableList<String> openVariables, String parentClassPath) {
ProcessingContext ctx = new ProcessingContext("Lambda");
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification thisVariable = HelperModelBuilder.createThisVariableForClass(context, parentClassPath);
ctx.addInferredVariables("this", thisVariable);
AggregateSpecification as = new Root_meta_pure_mapping_aggregationAware_AggregateSpecification_Impl(" ");
as._canAggregate(aggregateSpecification.canAggregate);
for (GroupByFunction gb : aggregateSpecification.groupByFunctions) {
as._groupByFunctionsAdd(processGroupByFunction(gb, context, openVariables, ctx));
}
for (AggregateFunction af : aggregateSpecification.aggregateValues) {
as._aggregateValuesAdd(processAggregationFunction(af, context, openVariables, ctx));
}
ctx.flushVariable("this");
return as;
}
use of org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch in project legend-engine by finos.
the class HelperModelBuilder method getAppliedProperty.
/**
* Recursively go through hierarchical/generalization chain and find the property.
*/
public static AbstractProperty<?> getAppliedProperty(CompileContext context, org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<?> _class, Optional<? extends List<? extends org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification>> parameters, String name, org.finos.legend.engine.protocol.pure.v1.model.SourceInformation sourceInformation) {
for (CoreInstance c_type : org.finos.legend.pure.m3.navigation.type.Type.getGeneralizationResolutionOrder(_class, context.pureModel.getExecutionSupport().getProcessorSupport())) {
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<?> type = (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<?>) c_type;
AbstractProperty<?> property = type._properties().detect(p -> name.equals(p.getName()));
if (property != null) {
return property;
}
property = type._propertiesFromAssociations().detect(p -> name.equals(p.getName()));
if (property != null) {
return property;
}
property = type._qualifiedProperties().detect(parameters.isPresent() ? p -> isCompatibleDerivedProperty(p, name, parameters.get()) : p -> name.equals(p._name()));
if (property != null) {
return property;
}
property = type._qualifiedPropertiesFromAssociations().detect(p -> name.equals(p._name()));
if (property != null) {
return property;
}
}
throw new EngineException("Can't find property '" + name + "' in [" + org.finos.legend.pure.m3.navigation.type.Type.getGeneralizationResolutionOrder(_class, context.pureModel.getExecutionSupport().getProcessorSupport()).makeString(", ") + "]", sourceInformation, EngineErrorType.COMPILATION);
}
Aggregations