fix: filter on unselected columns in a table-valued function

This commit is contained in:
Taimoor Zaeem
2025-04-27 14:20:13 -05:00
committed by Steve Chavez
parent cd5a611a1a
commit f53147674e
5 changed files with 57 additions and 4 deletions
+17
View File
@@ -1019,6 +1019,7 @@ callPlan proc ApiRequest{} paramKeys args readReq = FunctionCall {
, funCScalar = funcReturnsScalar proc
, funCSetOfScalar = funcReturnsSetOfScalar proc
, funCRetCompositeAlias = funcReturnsCompositeAlias proc
, funCFilterFields = getFilterFieldNames readReq
, funCReturning = inferColsEmbedNeeds readReq []
}
where
@@ -1028,6 +1029,22 @@ callPlan proc ApiRequest{} paramKeys args readReq = FunctionCall {
| otherwise -> KeyParams $ specifiedParams [prm]
prms -> KeyParams $ specifiedParams prms
-- | Get filter fields/column names from read plan
getFilterFieldNames :: ReadPlanTree -> Set FieldName
getFilterFieldNames rpt = S.fromList $ foldr (\rp names -> names <> rpToFieldNames rp) [] rpt
where
rpToFieldNames :: ReadPlan -> [FieldName]
rpToFieldNames = logicTreesToFieldName . ReadPlan.where_
logicTreesToFieldName :: [CoercibleLogicTree] -> [FieldName]
logicTreesToFieldName = concatMap coLogicTreeToFieldNames
coLogicTreeToFieldNames :: CoercibleLogicTree -> [FieldName]
coLogicTreeToFieldNames = \case
CoercibleStmnt (CoercibleFilter{field=CoercibleField{cfName}}) -> [cfName]
CoercibleStmnt (CoercibleFilterNullEmbed _ cfName) -> [cfName] -- needs test coverage
CoercibleExpr _ _ clts -> concatMap coLogicTreeToFieldNames clts
-- | Infers the columns needed for an embed to be successful after a mutation or a function call.
inferColsEmbedNeeds :: ReadPlanTree -> [FieldName] -> S.Set FieldName
inferColsEmbedNeeds (Node ReadPlan{select} forest) pkCols