Skip to content

Commit

Permalink
refactor: simplify functions in the "hoist from selected fields" process
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenceisla committed Aug 21, 2024
1 parent e9244f1 commit 2302f78
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/PostgREST/Plan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -703,14 +703,12 @@ hoistFromSelectFields relAggAlias fields =
let (modifiedField, maybeAgg) = modifyField field
in (modifiedField : newFields, maybeAgg : aggList)

modifyField field =
case csAggFunction field of
Just aggFunc ->
( field { csAggFunction = Nothing, csAggCast = Nothing },
Just ((relAggAlias, determineFieldName field), (aggFunc, csAggCast field, csAlias field)))
Nothing -> (field, Nothing)

determineFieldName field = fromMaybe (cfName $ csField field) (csAlias field)
modifyField field@CoercibleSelectField{csAggFunction=Just aggFunc, csField, csAggCast, csAlias} =
let determineFieldName = fromMaybe (cfName csField) csAlias
updatedField = field {csAggFunction = Nothing, csAggCast = Nothing}
hoistedField = Just ((relAggAlias, determineFieldName), (aggFunc, csAggCast, csAlias))
in (updatedField, hoistedField)
modifyField field = (field, Nothing)

-- Taking the hoisted aggregates, modify the rel selects to apply the aggregates,
-- and any applicable casts or aliases.
Expand Down

0 comments on commit 2302f78

Please sign in to comment.