generated from finos/software-project-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squash commit for refactoring to the Rel transpiler, including suppor…
…t for more queries. (#2515)
- Loading branch information
1 parent
43400d6
commit f0bdb87
Showing
32 changed files
with
3,591 additions
and
2,402 deletions.
There are no files selected for viewing
1,328 changes: 0 additions & 1,328 deletions
1,328
...-relationalai-pure/src/main/resources/core_external_query_relationalai/compile/ir/ir.pure
This file was deleted.
Oops, something went wrong.
562 changes: 562 additions & 0 deletions
562
...lationalai-pure/src/main/resources/core_external_query_relationalai/compile/ir/pexpr.pure
Large diffs are not rendered by default.
Oops, something went wrong.
205 changes: 205 additions & 0 deletions
205
...tionalai-pure/src/main/resources/core_external_query_relationalai/compile/ir/project.pure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
import meta::rel::compile::ir::utils::*; | ||
import meta::pure::router::store::metamodel::*; | ||
import meta::rel::compile::ir::*; | ||
import meta::rel::mapping::*; | ||
import meta::rel::utils::*; | ||
import meta::rel::utils::lang::*; | ||
import meta::rel::trace::*; | ||
import meta::pure::router::metamodel::*; | ||
|
||
function <<access.private>> meta::rel::compile::ir::handleCaseProject1( | ||
func: FunctionExpression[1], | ||
trace: Trace[1] | ||
): Result<PExpr|0..1>[1] { | ||
assert($func.func == project_T_MANY__Path_MANY__TabularDataSet_1_); | ||
|
||
let newTrace = $trace->stage('handleCaseProject1(FunctionExpression[1],Trace[1])'); | ||
|
||
let param0 = $func.parametersValues->at(0); | ||
// Second argument is the path. | ||
let param1 = $func.parametersValues->at(1); | ||
|
||
$param0 | ||
->valueSpecToPExpr($trace) | ||
->andThen({parent: PExpr[1] | | ||
switch([ | ||
case($param1->instanceOf(ExtendedRoutedValueSpecification), | ||
| $param1 | ||
->cast(@ExtendedRoutedValueSpecification) | ||
.value | ||
->cast(@InstanceValue) | ||
.values | ||
->cast(@meta::pure::metamodel::path::Path<Nil,Any|1>) | ||
), | ||
case($param1->instanceOf(InstanceValue), | | ||
$param1 | ||
->cast(@InstanceValue) | ||
.values | ||
->cast(@meta::pure::metamodel::path::Path<Nil,Any|1>) | ||
) | ||
], {| $param1->reactivate(); }) | ||
->okOr(| errorTrace('Encountered unknown argument during compilation of `project_T_MANY__Path_MANY__TabularDataSet_1_`.', $newTrace)) | ||
->andThem({paths: meta::pure::metamodel::path::Path<Nil,Any|1>[*] | | ||
$parent | ||
->set() | ||
->okOr(| errorTrace('Expected set in parent expression of `project_T_MANY__Path_MANY__TabularDataSet_1_`.', $newTrace)) | ||
->andThen({set: RelSetImplementation[1] | | ||
$paths | ||
->map({path | | ||
$path.path | ||
->fold({element, accum | | ||
$accum | ||
->andThen({expr: PExpr[1] | | ||
$element | ||
->tryCast(@meta::pure::metamodel::path::PropertyPathElement, $newTrace) | ||
->andThen(p: meta::pure::metamodel::path::PropertyPathElement[1] | $p.property->tryCast(@Property<Nil,Any|*>, $newTrace)) | ||
->andThen({property: Property<Nil,Any|*>[1] | | ||
$property | ||
.genericType | ||
.rawType | ||
->okOr(| errorTrace(format('No type information for property `%s`.', $property.name), $newTrace)) | ||
->then({type: Type[1] | | ||
let next = | ||
$set | ||
.parent | ||
->meta::pure::mapping::classMappingById($type->elementToPath('_')) | ||
->map(set | $set->cast(@RelSetImplementation)); | ||
|
||
$expr->propertyAccess($property, $next); | ||
}) | ||
}); | ||
}); | ||
}, ok(setAccess($set, 'x'))) | ||
->then(expr: PExpr[1] | | ||
let name = | ||
if ($path.name->isEmpty() || $path.name == '', {| | ||
$path.path | ||
->last() | ||
->map({last | | ||
if ($last->instanceOf(meta::pure::metamodel::path::PropertyPathElement), {| | ||
$last | ||
->cast(@meta::pure::metamodel::path::PropertyPathElement) | ||
.property | ||
.name | ||
->orElse('') | ||
}, | '') | ||
}) | ||
->orElse(''); | ||
}, | $path.name) | ||
->orElse(''); | ||
|
||
pair($name, $expr->scopeUntyped('x')->withParent($parent)); | ||
); | ||
}) | ||
->collect() | ||
->them({pairs: Pair<String, PExprScope>[*] | | ||
$parent->project($pairs); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
function <<access.private>> meta::rel::compile::ir::handleCaseProject2( | ||
func: FunctionExpression[1], | ||
trace: Trace[1] | ||
): Result<PExpr|0..1>[1] { | ||
assert($func.func == project_T_MANY__ColumnSpecification_MANY__TabularDataSet_1_ || | ||
$func.func == project_TabularDataSet_1__ColumnSpecification_MANY__TabularDataSet_1_); | ||
|
||
let newTrace = $trace->stage('handleCaseProject1(FunctionExpression[1],Trace[1])'); | ||
|
||
let param0 = $func.parametersValues->at(0); | ||
// Second argument is the column specification. | ||
let param1 = $func.parametersValues->at(1); | ||
|
||
$param0 | ||
->valueSpecToPExpr($trace) | ||
->andThen({parent: PExpr[1] | | ||
$param1 | ||
->tryCast(@InstanceValue, $newTrace) | ||
->andThen({params: InstanceValue[1] | | ||
$params.values | ||
->map({v | | ||
$v->tryCast(@InstanceValue, $newTrace) | ||
->then(i: InstanceValue[1] | | ||
// Values guaranteed by function signature | ||
$i.values | ||
->toOne() | ||
->cast(@BasicColumnSpecification<Any>) | ||
); | ||
}) | ||
->collect() | ||
->andThem({columns: BasicColumnSpecification<Any>[*] | | ||
$columns.func | ||
->map(f | | ||
$f->tryCast(@FunctionDefinition<Any>, $newTrace) | ||
->andThen(fexpr: FunctionDefinition<Any>[1] | $fexpr->functionDefToUntypedScoped($parent, $trace)) | ||
) | ||
->collect() | ||
->them(fexprs: PExprScope[*] | $parent->project($columns.name->zip($fexprs))); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
function <<access.private>> meta::rel::compile::ir::handleCaseProject3( | ||
func: FunctionExpression[1], | ||
tracex: Trace[1] | ||
): Result<PExpr|0..1>[1] { | ||
assert($func.func == project_K_MANY__Function_MANY__String_MANY__TabularDataSet_1_); | ||
|
||
let newTrace = $tracex->stage('handleCaseProject3(FunctionExpression[1],Trace[1])'); | ||
|
||
let param0 = $func.parametersValues->at(0); | ||
// Second argument is the function (what is this??). | ||
let param1 = $func.parametersValues->at(1); | ||
// Third argument is the column names. | ||
let param2 = $func.parametersValues->at(2); | ||
|
||
$param0 | ||
->valueSpecToPExpr($newTrace) | ||
->andThen({parent: PExpr[1] | | ||
switch([ | ||
case($param1->instanceOf(InstanceValue), | | ||
$param1 | ||
->cast(@InstanceValue) | ||
.values | ||
->map( v | | ||
$v->tryCast(@FunctionRoutedValueSpecification, $newTrace) | ||
->then(s: FunctionRoutedValueSpecification[1] | | ||
// CHECK: Is value type guarenteed? | ||
$s.value->cast(@InstanceValue) | ||
) | ||
) | ||
->collect(); | ||
), | ||
case($param1->instanceOf(StoreMappingRoutedValueSpecification), | | ||
$param1 | ||
->cast(@StoreMappingRoutedValueSpecification) | ||
.value | ||
->cast(@FunctionRoutedValueSpecification) | ||
.value | ||
->tryCast(@InstanceValue, $newTrace) | ||
) | ||
], {| error('Match error: Unexpected type', $newTrace) } | ||
) | ||
->andThem({i: InstanceValue[*] | | ||
$i.values | ||
->map(v | | ||
// Type Result<Project> | ||
$v->tryCast(@FunctionDefinition<Any>, $newTrace) | ||
->andThen(fexpr: FunctionDefinition<Any>[1] | $fexpr->functionDefToUntypedScoped($parent, $newTrace)) | ||
) | ||
->collect() | ||
->andThem(fexprs: PExprScope[*] | | ||
// Type Result<Project> | ||
$param2->tryCast(@InstanceValue, $newTrace)->then(param: InstanceValue[1] | | ||
// Type guareteed by function signature. | ||
let columnNames = $param.values->cast(@String); | ||
$parent->project($columnNames->zip($fexprs)); | ||
) | ||
) | ||
}); | ||
}); | ||
} |
64 changes: 33 additions & 31 deletions
64
...relationalai-pure/src/main/resources/core_external_query_relationalai/compile/ir/tds.pure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,81 @@ | ||
import meta::rel::compile::ir::*; | ||
import meta::rel::compile::ir::tds::*; | ||
import meta::rel::trace::*; | ||
import meta::rel::utils::*; | ||
import meta::rel::utils::lang::*; | ||
|
||
Class meta::rel::compile::ir::tds::Join extends PExpr { | ||
type: meta::relational::metamodel::join::JoinType[1]; | ||
condition: Scoped[1]; | ||
condition: PExprScope[1]; | ||
left: PExpr[1]; | ||
right: PExpr[1]; | ||
} | ||
|
||
Class meta::rel::compile::ir::tds::TDSFilter extends PExpr { | ||
parent: PExpr[1]; | ||
predicate: Scoped[1]; | ||
predicate: PExprScope[1]; | ||
} | ||
|
||
function meta::rel::compile::ir::tds::join( | ||
left: PExpr[1], | ||
right: PExpr[1], | ||
type: meta::relational::metamodel::join::JoinType[1], | ||
condition: Scoped[1] | ||
condition: PExprScope[1] | ||
): Join[1] { | ||
^Join(type=$type, condition=$condition, left=$left, right=$right); | ||
} | ||
|
||
function meta::rel::compile::ir::tds::filter(parent: PExpr[1], predicate: Scoped[1]): TDSFilter[1] { | ||
function meta::rel::compile::ir::tds::filter(parent: PExpr[1], predicate: PExprScope[1]): TDSFilter[1] { | ||
^TDSFilter(parent=$parent, predicate=$predicate); | ||
} | ||
|
||
function meta::rel::compile::ir::tds::intoPExpr(func: FunctionExpression[1]): Result<PExpr|0..1>[1] { | ||
function meta::rel::compile::ir::tds::intoPExpr(func: FunctionExpression[1], trace: Trace[1]): Result<PExpr|0..1>[1] { | ||
let newTrace = $trace->stage('intoPExpr(FunctionExpression[1],Trace[1])'); | ||
switch([ | ||
case($func.func == meta::pure::tds::join_TabularDataSet_1__TabularDataSet_1__JoinType_1__Function_1__TabularDataSet_1_, {| | ||
$func.parametersValues | ||
->at(0) | ||
->meta::rel::compile::ir::intoPExpr() | ||
->andThen({left: PExpr[1] | | ||
->valueSpecToPExpr($newTrace) | ||
->andThen(left: PExpr[1] | | ||
$func.parametersValues | ||
->at(1) | ||
->meta::rel::compile::ir::intoPExpr() | ||
->andThen({right: PExpr[1] | | ||
->valueSpecToPExpr($newTrace) | ||
->andThen(right: PExpr[1] | | ||
$func.parametersValues | ||
->at(2) | ||
->reactivate(^Map<String, List<Any>>()) | ||
->tryCastm(@meta::relational::metamodel::join::JoinType) | ||
->them({js | $js->toOne()}) | ||
->andThen({joinType: meta::relational::metamodel::join::JoinType[1] | | ||
->tryCastm(@meta::relational::metamodel::join::JoinType, $newTrace) | ||
->them(js | $js->toOne()) | ||
->andThen(joinType: meta::relational::metamodel::join::JoinType[1] | | ||
$func.parametersValues | ||
->at(3) | ||
->intoScoped() | ||
->then(condition: Scoped[1] | join($left, $right, $joinType, $condition)); | ||
}); | ||
}); | ||
}); | ||
->valueSpecToUntypedScoped($newTrace) | ||
->then(condition: PExprScope[1] | join($left, $right, $joinType, $condition)) | ||
) | ||
) | ||
) | ||
}), | ||
case($func.func == meta::pure::tds::filter_TabularDataSet_1__Function_1__TabularDataSet_1_, {| | ||
$func.parametersValues | ||
->at(0) | ||
->meta::rel::compile::ir::intoPExpr() | ||
->andThen({parent: PExpr[1] | | ||
->valueSpecToPExpr($newTrace) | ||
->andThen(parent: PExpr[1] | | ||
$func.parametersValues | ||
->at(1) | ||
->meta::rel::compile::ir::intoScoped() | ||
->then({predicate: Scoped[1] | | ||
meta::rel::compile::ir::tds::filter($parent, $predicate); | ||
}); | ||
}); | ||
->valueSpecToUntypedScoped($newTrace) | ||
->then(predicate: PExprScope[1] | | ||
meta::rel::compile::ir::tds::filter($parent, $predicate) | ||
) | ||
) | ||
}) | ||
], {| | ||
let error = error(| | ||
'Encountered unknown instance while translating: ' + | ||
], | | ||
error( | ||
'Encountered unknown instance when constructing PExpr for TDS function with type: ' + | ||
$func.func | ||
->elementToPath() | ||
->else(| '<<unknown>>') | ||
->quote(); | ||
); | ||
error($error); | ||
}) | ||
->quote(), | ||
$newTrace | ||
) | ||
); | ||
} |
Oops, something went wrong.