{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.Glue.Types.AggregateOperation
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Glue.Types.AggregateOperation where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Glue.Types.AggFunction
import qualified Amazonka.Prelude as Prelude

-- | Specifies the set of parameters needed to perform aggregation in the
-- aggregate transform.
--
-- /See:/ 'newAggregateOperation' smart constructor.
data AggregateOperation = AggregateOperation'
  { -- | Specifies the column on the data set on which the aggregation function
    -- will be applied.
    AggregateOperation -> [Text]
column :: [Prelude.Text],
    -- | Specifies the aggregation function to apply.
    --
    -- Possible aggregation functions include: avg countDistinct, count, first,
    -- last, kurtosis, max, min, skewness, stddev_samp, stddev_pop, sum,
    -- sumDistinct, var_samp, var_pop
    AggregateOperation -> AggFunction
aggFunc :: AggFunction
  }
  deriving (AggregateOperation -> AggregateOperation -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AggregateOperation -> AggregateOperation -> Bool
$c/= :: AggregateOperation -> AggregateOperation -> Bool
== :: AggregateOperation -> AggregateOperation -> Bool
$c== :: AggregateOperation -> AggregateOperation -> Bool
Prelude.Eq, ReadPrec [AggregateOperation]
ReadPrec AggregateOperation
Int -> ReadS AggregateOperation
ReadS [AggregateOperation]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AggregateOperation]
$creadListPrec :: ReadPrec [AggregateOperation]
readPrec :: ReadPrec AggregateOperation
$creadPrec :: ReadPrec AggregateOperation
readList :: ReadS [AggregateOperation]
$creadList :: ReadS [AggregateOperation]
readsPrec :: Int -> ReadS AggregateOperation
$creadsPrec :: Int -> ReadS AggregateOperation
Prelude.Read, Int -> AggregateOperation -> ShowS
[AggregateOperation] -> ShowS
AggregateOperation -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AggregateOperation] -> ShowS
$cshowList :: [AggregateOperation] -> ShowS
show :: AggregateOperation -> String
$cshow :: AggregateOperation -> String
showsPrec :: Int -> AggregateOperation -> ShowS
$cshowsPrec :: Int -> AggregateOperation -> ShowS
Prelude.Show, forall x. Rep AggregateOperation x -> AggregateOperation
forall x. AggregateOperation -> Rep AggregateOperation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AggregateOperation x -> AggregateOperation
$cfrom :: forall x. AggregateOperation -> Rep AggregateOperation x
Prelude.Generic)

-- |
-- Create a value of 'AggregateOperation' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'column', 'aggregateOperation_column' - Specifies the column on the data set on which the aggregation function
-- will be applied.
--
-- 'aggFunc', 'aggregateOperation_aggFunc' - Specifies the aggregation function to apply.
--
-- Possible aggregation functions include: avg countDistinct, count, first,
-- last, kurtosis, max, min, skewness, stddev_samp, stddev_pop, sum,
-- sumDistinct, var_samp, var_pop
newAggregateOperation ::
  -- | 'aggFunc'
  AggFunction ->
  AggregateOperation
newAggregateOperation :: AggFunction -> AggregateOperation
newAggregateOperation AggFunction
pAggFunc_ =
  AggregateOperation'
    { $sel:column:AggregateOperation' :: [Text]
column = forall a. Monoid a => a
Prelude.mempty,
      $sel:aggFunc:AggregateOperation' :: AggFunction
aggFunc = AggFunction
pAggFunc_
    }

-- | Specifies the column on the data set on which the aggregation function
-- will be applied.
aggregateOperation_column :: Lens.Lens' AggregateOperation [Prelude.Text]
aggregateOperation_column :: Lens' AggregateOperation [Text]
aggregateOperation_column = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AggregateOperation' {[Text]
column :: [Text]
$sel:column:AggregateOperation' :: AggregateOperation -> [Text]
column} -> [Text]
column) (\s :: AggregateOperation
s@AggregateOperation' {} [Text]
a -> AggregateOperation
s {$sel:column:AggregateOperation' :: [Text]
column = [Text]
a} :: AggregateOperation) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Specifies the aggregation function to apply.
--
-- Possible aggregation functions include: avg countDistinct, count, first,
-- last, kurtosis, max, min, skewness, stddev_samp, stddev_pop, sum,
-- sumDistinct, var_samp, var_pop
aggregateOperation_aggFunc :: Lens.Lens' AggregateOperation AggFunction
aggregateOperation_aggFunc :: Lens' AggregateOperation AggFunction
aggregateOperation_aggFunc = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AggregateOperation' {AggFunction
aggFunc :: AggFunction
$sel:aggFunc:AggregateOperation' :: AggregateOperation -> AggFunction
aggFunc} -> AggFunction
aggFunc) (\s :: AggregateOperation
s@AggregateOperation' {} AggFunction
a -> AggregateOperation
s {$sel:aggFunc:AggregateOperation' :: AggFunction
aggFunc = AggFunction
a} :: AggregateOperation)

instance Data.FromJSON AggregateOperation where
  parseJSON :: Value -> Parser AggregateOperation
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AggregateOperation"
      ( \Object
x ->
          [Text] -> AggFunction -> AggregateOperation
AggregateOperation'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Column" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"AggFunc")
      )

instance Prelude.Hashable AggregateOperation where
  hashWithSalt :: Int -> AggregateOperation -> Int
hashWithSalt Int
_salt AggregateOperation' {[Text]
AggFunction
aggFunc :: AggFunction
column :: [Text]
$sel:aggFunc:AggregateOperation' :: AggregateOperation -> AggFunction
$sel:column:AggregateOperation' :: AggregateOperation -> [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
column
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` AggFunction
aggFunc

instance Prelude.NFData AggregateOperation where
  rnf :: AggregateOperation -> ()
rnf AggregateOperation' {[Text]
AggFunction
aggFunc :: AggFunction
column :: [Text]
$sel:aggFunc:AggregateOperation' :: AggregateOperation -> AggFunction
$sel:column:AggregateOperation' :: AggregateOperation -> [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf [Text]
column
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf AggFunction
aggFunc

instance Data.ToJSON AggregateOperation where
  toJSON :: AggregateOperation -> Value
toJSON AggregateOperation' {[Text]
AggFunction
aggFunc :: AggFunction
column :: [Text]
$sel:aggFunc:AggregateOperation' :: AggregateOperation -> AggFunction
$sel:column:AggregateOperation' :: AggregateOperation -> [Text]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Column" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [Text]
column),
            forall a. a -> Maybe a
Prelude.Just (Key
"AggFunc" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= AggFunction
aggFunc)
          ]
      )