Skip to content

Commit

Permalink
repl: fix computation of isResultColumnsDynamic flag (finos#3096)
Browse files Browse the repository at this point in the history
  • Loading branch information
akphi authored Sep 17, 2024
1 parent 06bb592 commit b3d9d97
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4855,6 +4855,14 @@ function meta::relational::functions::pureToSqlQuery::processGroupBy(expression:
);
}

// TODO: since we use SELECT * when processing PIVOT (effectively always force pivot to be part of a subselect in subsequent processing)
// we perform the following check to see if the result columns can be dynamic. The following check is still pretty naive
// it should (in theory) walk the chain of SELECT * (i.e. $select.columns->isEmpty()) and determine if the source of this is from a pivot()
function meta::relational::functions::pureToSqlQuery::isResultColumnsDynamic(select:SelectSQLQuery[1]):Boolean[1]
{
!$select.pivot->isEmpty() || $select.columns->isEmpty();
}

function meta::relational::functions::pureToSqlQuery::processPivot(expression:FunctionExpression[1], currentPropertyMapping:PropertyMapping[*], operation:SelectWithCursor[1], vars:Map<VariableExpression, ValueSpecification>[1], state:State[1], joinType:JoinType[1], nodeId:String[1], aggFromMap:List<ColumnGroup>[1], context:DebugContext[1], extensions:Extension[*]):RelationalOperationElement[1]
{
let mainQuery = processValueSpecification($expression.parametersValues->at(0), [], $operation, $vars, $state, JoinType.LEFT_OUTER, $nodeId, $aggFromMap, $context, $extensions)->toOne()->cast(@SelectWithCursor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function meta::relational::mapping::generateSQLExecutionNode(query:SQLQuery[1],
metadata = ^meta::relational::mapping::TableInfo(info = $query->meta::relational::milestoning::getQueryTableAliases()->map(a|$a.relationalElement)->cast(@Table)->removeDuplicatesBy(t|$t.schema.name+'.'+$t.name)->map(tab| ^meta::relational::mapping::TableIdentifier(schema=$tab.schema.name, table=$tab.name))),
// the only case that we yield result with dynamic columns is when pivot() is used and no casting is done afterwards, resulting
// in a select statement with no columns being specified
isResultColumnsDynamic = $query->match([sel:SelectSQLQuery[1] | if(!$sel.pivot->isEmpty() && $sel.columns->isEmpty(), |true,|[]), a:Any[1] | []])
isResultColumnsDynamic = $query->match([sel:SelectSQLQuery[1] | if(isResultColumnsDynamic($sel), |true,|[]), a:Any[1] | []])
);
}

Expand Down

0 comments on commit b3d9d97

Please sign in to comment.