2022-07-20 08:20:49 +03:00
|
|
|
{-# LANGUAGE DeriveAnyClass #-}
|
|
|
|
|
|
|
|
module Hasura.Backends.DataConnector.IR.Aggregate
|
|
|
|
( Aggregate (..),
|
|
|
|
SingleColumnAggregate (..),
|
|
|
|
SingleColumnAggregateFunction (..),
|
|
|
|
CountAggregate (..),
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
import Data.Aeson (FromJSON, ToJSON)
|
|
|
|
import Hasura.Backends.DataConnector.API qualified as API
|
|
|
|
import Hasura.Backends.DataConnector.IR.Column qualified as IR.C
|
|
|
|
import Hasura.Incremental (Cacheable)
|
|
|
|
import Hasura.Prelude
|
|
|
|
import Witch qualified
|
|
|
|
|
|
|
|
data Aggregate
|
|
|
|
= SingleColumn SingleColumnAggregate
|
|
|
|
| Count CountAggregate
|
|
|
|
deriving stock (Data, Eq, Generic, Ord, Show)
|
|
|
|
deriving anyclass (Cacheable, FromJSON, Hashable, NFData, ToJSON)
|
|
|
|
|
|
|
|
instance Witch.From Aggregate API.Aggregate where
|
|
|
|
from (SingleColumn singleColumn) = API.SingleColumn (Witch.from singleColumn)
|
|
|
|
from (Count StarCount) = API.StarCount
|
2022-07-28 10:24:13 +03:00
|
|
|
from (Count (ColumnCount column)) = API.ColumnCount $ API.ColumnCountAggregate {_ccaColumn = Witch.from column, _ccaDistinct = False}
|
|
|
|
from (Count (ColumnDistinctCount column)) = API.ColumnCount $ API.ColumnCountAggregate {_ccaColumn = Witch.from column, _ccaDistinct = True}
|
2022-07-20 08:20:49 +03:00
|
|
|
|
|
|
|
data SingleColumnAggregate = SingleColumnAggregate
|
|
|
|
{ _scaFunction :: SingleColumnAggregateFunction,
|
|
|
|
_scaColumn :: IR.C.Name
|
|
|
|
}
|
|
|
|
deriving stock (Data, Eq, Generic, Ord, Show)
|
|
|
|
deriving anyclass (Cacheable, FromJSON, Hashable, NFData, ToJSON)
|
|
|
|
|
|
|
|
instance Witch.From SingleColumnAggregate API.SingleColumnAggregate where
|
|
|
|
from SingleColumnAggregate {..} = API.SingleColumnAggregate (Witch.from _scaFunction) (Witch.from _scaColumn)
|
|
|
|
|
|
|
|
data SingleColumnAggregateFunction
|
|
|
|
= Average
|
|
|
|
| Max
|
|
|
|
| Min
|
|
|
|
| StandardDeviationPopulation
|
|
|
|
| StandardDeviationSample
|
|
|
|
| Sum
|
|
|
|
| VariancePopulation
|
|
|
|
| VarianceSample
|
|
|
|
deriving stock (Data, Eq, Generic, Ord, Show)
|
|
|
|
deriving anyclass (Cacheable, FromJSON, Hashable, NFData, ToJSON)
|
|
|
|
|
|
|
|
instance Witch.From API.SingleColumnAggregateFunction SingleColumnAggregateFunction where
|
|
|
|
from API.Average = Average
|
|
|
|
from API.Max = Max
|
|
|
|
from API.Min = Min
|
|
|
|
from API.StandardDeviationPopulation = StandardDeviationPopulation
|
|
|
|
from API.StandardDeviationSample = StandardDeviationSample
|
|
|
|
from API.Sum = Sum
|
|
|
|
from API.VariancePopulation = VariancePopulation
|
|
|
|
from API.VarianceSample = VarianceSample
|
|
|
|
|
|
|
|
instance Witch.From SingleColumnAggregateFunction API.SingleColumnAggregateFunction where
|
|
|
|
from Average = API.Average
|
|
|
|
from Max = API.Max
|
|
|
|
from Min = API.Min
|
|
|
|
from StandardDeviationPopulation = API.StandardDeviationPopulation
|
|
|
|
from StandardDeviationSample = API.StandardDeviationSample
|
|
|
|
from Sum = API.Sum
|
|
|
|
from VariancePopulation = API.VariancePopulation
|
|
|
|
from VarianceSample = API.VarianceSample
|
|
|
|
|
|
|
|
data CountAggregate
|
|
|
|
= StarCount
|
2022-07-28 10:24:13 +03:00
|
|
|
| ColumnCount IR.C.Name
|
|
|
|
| ColumnDistinctCount IR.C.Name
|
2022-07-20 08:20:49 +03:00
|
|
|
deriving stock (Data, Eq, Generic, Ord, Show)
|
|
|
|
deriving anyclass (Cacheable, FromJSON, Hashable, NFData, ToJSON)
|