Skip to content

Commit

Permalink
Avoid Post processor failure for queries without data component (#2890)
Browse files Browse the repository at this point in the history
Avoid Post processor failure for queries without data component
  • Loading branch information
Yasirmod17 authored Jun 5, 2024
1 parent 37d149b commit af6f1f9
Showing 1 changed file with 43 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,47 +135,49 @@ function meta::relational::postProcessor::transform(r:RelationalOperationElement
c:CommonTableExpression[1] | let transformedSql= $c.sqlQuery->transform($f, $transformed);
pair(^$c(sqlQuery=$transformedSql.first->cast(@SQLQuery)), $transformedSql.second);,

s:SelectSQLQuery[1] | let transformedData = $s.data->toOne()->transform($f, $transformed);
let transformedColumns = $s.columns->fold({c, agg |
let colTransform = $c->transform($f, $agg.second);
pair(list($agg.first.values->add($colTransform.first)), $colTransform.second);
}, pair(^List<RelationalOperationElement>(), $transformedData.second));
let transformedFilterOp = $s.filteringOperation->fold({fo, agg |
let foTransform = $fo->transform($f, $agg.second);
pair(list($agg.first.values->add($foTransform.first)), $foTransform.second);
}, pair(^List<RelationalOperationElement>(), $transformedColumns.second));
let transformedGroupBy = $s.groupBy->fold({gp, agg |
let gpTransform = $gp->transform($f, $agg.second);
pair(list($agg.first.values->add($gpTransform.first)), $gpTransform.second);
}, pair(^List<RelationalOperationElement>(), $transformedFilterOp.second));
let transformedHavingOp = $s.havingOperation->fold({ho, agg |
let hoTransform = $ho->transform($f, $agg.second);
pair(list($agg.first.values->add($hoTransform.first)), $hoTransform.second);
}, pair(^List<RelationalOperationElement>(), $transformedGroupBy.second));
let transformedOrderBy = $s.orderBy->fold({ob, agg |
let obTransform = $ob.column->transform($f, $agg.second);
pair(list($agg.first.values->add(^$ob(column=$obTransform.first))), $obTransform.second);
}, pair(^List<OrderBy>(), $transformedHavingOp.second));
let newS = ^$s( data=$transformedData.first->cast(@RootJoinTreeNode),
columns=$transformedColumns.first.values,
filteringOperation=$transformedFilterOp.first.values,
groupBy=$transformedGroupBy.first.values,
havingOperation=$transformedHavingOp.first.values,
orderBy=$transformedOrderBy.first.values
);
let newSWithLeftSideModified = if(!$newS.leftSideOfFilter->isEmpty(),| ^$newS(leftSideOfFilter=$s.leftSideOfFilter->toOne()->meta::relational::functions::pureToSqlQuery::findOneNode($s.data->toOne(), $newS.data->toOne())),|$newS);
if($newSWithLeftSideModified->instanceOf(SelectSQLQueryWithCommonTableExpressions),
|
let selectWithCte = $newSWithLeftSideModified->cast(@SelectSQLQueryWithCommonTableExpressions);
let transformedCommonTableExpressions = $selectWithCte.commonTableExpressions->fold({cte, agg |
let cteTransform = $cte->transform($f, $agg.second);
pair(list($agg.first.values->add($cteTransform.first->cast(@CommonTableExpression))), $cteTransform.second);
}, pair(^List<CommonTableExpression>(), $transformedOrderBy.second));
let newSelectWithCte = ^$selectWithCte(commonTableExpressions = $transformedCommonTableExpressions.first.values);
pair($newSelectWithCte, $transformedCommonTableExpressions.second);,
|
pair($newSWithLeftSideModified, $transformedOrderBy.second);
);,
s:SelectSQLQuery[1] | if($s.data->isNotEmpty(),
| let transformedData = $s.data->toOne()->transform($f, $transformed);
let transformedColumns = $s.columns->fold({c, agg |
let colTransform = $c->transform($f, $agg.second);
pair(list($agg.first.values->add($colTransform.first)), $colTransform.second);
}, pair(^List<RelationalOperationElement>(), $transformedData.second));
let transformedFilterOp = $s.filteringOperation->fold({fo, agg |
let foTransform = $fo->transform($f, $agg.second);
pair(list($agg.first.values->add($foTransform.first)), $foTransform.second);
}, pair(^List<RelationalOperationElement>(), $transformedColumns.second));
let transformedGroupBy = $s.groupBy->fold({gp, agg |
let gpTransform = $gp->transform($f, $agg.second);
pair(list($agg.first.values->add($gpTransform.first)), $gpTransform.second);
}, pair(^List<RelationalOperationElement>(), $transformedFilterOp.second));
let transformedHavingOp = $s.havingOperation->fold({ho, agg |
let hoTransform = $ho->transform($f, $agg.second);
pair(list($agg.first.values->add($hoTransform.first)), $hoTransform.second);
}, pair(^List<RelationalOperationElement>(), $transformedGroupBy.second));
let transformedOrderBy = $s.orderBy->fold({ob, agg |
let obTransform = $ob.column->transform($f, $agg.second);
pair(list($agg.first.values->add(^$ob(column=$obTransform.first))), $obTransform.second);
}, pair(^List<OrderBy>(), $transformedHavingOp.second));
let newS = ^$s( data=$transformedData.first->cast(@RootJoinTreeNode),
columns=$transformedColumns.first.values,
filteringOperation=$transformedFilterOp.first.values,
groupBy=$transformedGroupBy.first.values,
havingOperation=$transformedHavingOp.first.values,
orderBy=$transformedOrderBy.first.values
);
let newSWithLeftSideModified = if(!$newS.leftSideOfFilter->isEmpty(),| ^$newS(leftSideOfFilter=$s.leftSideOfFilter->toOne()->meta::relational::functions::pureToSqlQuery::findOneNode($s.data->toOne(), $newS.data->toOne())),|$newS);
if($newSWithLeftSideModified->instanceOf(SelectSQLQueryWithCommonTableExpressions),
|
let selectWithCte = $newSWithLeftSideModified->cast(@SelectSQLQueryWithCommonTableExpressions);
let transformedCommonTableExpressions = $selectWithCte.commonTableExpressions->fold({cte, agg |
let cteTransform = $cte->transform($f, $agg.second);
pair(list($agg.first.values->add($cteTransform.first->cast(@CommonTableExpression))), $cteTransform.second);
}, pair(^List<CommonTableExpression>(), $transformedOrderBy.second));
let newSelectWithCte = ^$selectWithCte(commonTableExpressions = $transformedCommonTableExpressions.first.values);
pair($newSelectWithCte, $transformedCommonTableExpressions.second);,
|
pair($newSWithLeftSideModified, $transformedOrderBy.second);
);,
|pair($s, $transformed));,

v:ViewSelectSQLQuery[1] | let transformedSql = $v.selectSQLQuery->transform($f, $transformed);
pair(^$v(selectSQLQuery=$transformedSql.first->cast(@SelectSQLQuery)), $transformedSql.second);,
Expand Down

0 comments on commit af6f1f9

Please sign in to comment.