{-# 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.DropDuplicates
-- 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.DropDuplicates where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Specifies a transform that removes rows of repeating data from a data
-- set.
--
-- /See:/ 'newDropDuplicates' smart constructor.
data DropDuplicates = DropDuplicates'
  { -- | The name of the columns to be merged or removed if repeating.
    DropDuplicates -> Maybe [[Text]]
columns :: Prelude.Maybe [[Prelude.Text]],
    -- | The name of the transform node.
    DropDuplicates -> Text
name :: Prelude.Text,
    -- | The data inputs identified by their node names.
    DropDuplicates -> NonEmpty Text
inputs :: Prelude.NonEmpty Prelude.Text
  }
  deriving (DropDuplicates -> DropDuplicates -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DropDuplicates -> DropDuplicates -> Bool
$c/= :: DropDuplicates -> DropDuplicates -> Bool
== :: DropDuplicates -> DropDuplicates -> Bool
$c== :: DropDuplicates -> DropDuplicates -> Bool
Prelude.Eq, ReadPrec [DropDuplicates]
ReadPrec DropDuplicates
Int -> ReadS DropDuplicates
ReadS [DropDuplicates]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DropDuplicates]
$creadListPrec :: ReadPrec [DropDuplicates]
readPrec :: ReadPrec DropDuplicates
$creadPrec :: ReadPrec DropDuplicates
readList :: ReadS [DropDuplicates]
$creadList :: ReadS [DropDuplicates]
readsPrec :: Int -> ReadS DropDuplicates
$creadsPrec :: Int -> ReadS DropDuplicates
Prelude.Read, Int -> DropDuplicates -> ShowS
[DropDuplicates] -> ShowS
DropDuplicates -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DropDuplicates] -> ShowS
$cshowList :: [DropDuplicates] -> ShowS
show :: DropDuplicates -> String
$cshow :: DropDuplicates -> String
showsPrec :: Int -> DropDuplicates -> ShowS
$cshowsPrec :: Int -> DropDuplicates -> ShowS
Prelude.Show, forall x. Rep DropDuplicates x -> DropDuplicates
forall x. DropDuplicates -> Rep DropDuplicates x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DropDuplicates x -> DropDuplicates
$cfrom :: forall x. DropDuplicates -> Rep DropDuplicates x
Prelude.Generic)

-- |
-- Create a value of 'DropDuplicates' 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:
--
-- 'columns', 'dropDuplicates_columns' - The name of the columns to be merged or removed if repeating.
--
-- 'name', 'dropDuplicates_name' - The name of the transform node.
--
-- 'inputs', 'dropDuplicates_inputs' - The data inputs identified by their node names.
newDropDuplicates ::
  -- | 'name'
  Prelude.Text ->
  -- | 'inputs'
  Prelude.NonEmpty Prelude.Text ->
  DropDuplicates
newDropDuplicates :: Text -> NonEmpty Text -> DropDuplicates
newDropDuplicates Text
pName_ NonEmpty Text
pInputs_ =
  DropDuplicates'
    { $sel:columns:DropDuplicates' :: Maybe [[Text]]
columns = forall a. Maybe a
Prelude.Nothing,
      $sel:name:DropDuplicates' :: Text
name = Text
pName_,
      $sel:inputs:DropDuplicates' :: NonEmpty Text
inputs = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pInputs_
    }

-- | The name of the columns to be merged or removed if repeating.
dropDuplicates_columns :: Lens.Lens' DropDuplicates (Prelude.Maybe [[Prelude.Text]])
dropDuplicates_columns :: Lens' DropDuplicates (Maybe [[Text]])
dropDuplicates_columns = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DropDuplicates' {Maybe [[Text]]
columns :: Maybe [[Text]]
$sel:columns:DropDuplicates' :: DropDuplicates -> Maybe [[Text]]
columns} -> Maybe [[Text]]
columns) (\s :: DropDuplicates
s@DropDuplicates' {} Maybe [[Text]]
a -> DropDuplicates
s {$sel:columns:DropDuplicates' :: Maybe [[Text]]
columns = Maybe [[Text]]
a} :: DropDuplicates) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the transform node.
dropDuplicates_name :: Lens.Lens' DropDuplicates Prelude.Text
dropDuplicates_name :: Lens' DropDuplicates Text
dropDuplicates_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DropDuplicates' {Text
name :: Text
$sel:name:DropDuplicates' :: DropDuplicates -> Text
name} -> Text
name) (\s :: DropDuplicates
s@DropDuplicates' {} Text
a -> DropDuplicates
s {$sel:name:DropDuplicates' :: Text
name = Text
a} :: DropDuplicates)

-- | The data inputs identified by their node names.
dropDuplicates_inputs :: Lens.Lens' DropDuplicates (Prelude.NonEmpty Prelude.Text)
dropDuplicates_inputs :: Lens' DropDuplicates (NonEmpty Text)
dropDuplicates_inputs = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DropDuplicates' {NonEmpty Text
inputs :: NonEmpty Text
$sel:inputs:DropDuplicates' :: DropDuplicates -> NonEmpty Text
inputs} -> NonEmpty Text
inputs) (\s :: DropDuplicates
s@DropDuplicates' {} NonEmpty Text
a -> DropDuplicates
s {$sel:inputs:DropDuplicates' :: NonEmpty Text
inputs = NonEmpty Text
a} :: DropDuplicates) 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

instance Data.FromJSON DropDuplicates where
  parseJSON :: Value -> Parser DropDuplicates
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"DropDuplicates"
      ( \Object
x ->
          Maybe [[Text]] -> Text -> NonEmpty Text -> DropDuplicates
DropDuplicates'
            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
"Columns" 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
"Name")
            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
"Inputs")
      )

instance Prelude.Hashable DropDuplicates where
  hashWithSalt :: Int -> DropDuplicates -> Int
hashWithSalt Int
_salt DropDuplicates' {Maybe [[Text]]
NonEmpty Text
Text
inputs :: NonEmpty Text
name :: Text
columns :: Maybe [[Text]]
$sel:inputs:DropDuplicates' :: DropDuplicates -> NonEmpty Text
$sel:name:DropDuplicates' :: DropDuplicates -> Text
$sel:columns:DropDuplicates' :: DropDuplicates -> Maybe [[Text]]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [[Text]]
columns
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
inputs

instance Prelude.NFData DropDuplicates where
  rnf :: DropDuplicates -> ()
rnf DropDuplicates' {Maybe [[Text]]
NonEmpty Text
Text
inputs :: NonEmpty Text
name :: Text
columns :: Maybe [[Text]]
$sel:inputs:DropDuplicates' :: DropDuplicates -> NonEmpty Text
$sel:name:DropDuplicates' :: DropDuplicates -> Text
$sel:columns:DropDuplicates' :: DropDuplicates -> Maybe [[Text]]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [[Text]]
columns
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Text
inputs

instance Data.ToJSON DropDuplicates where
  toJSON :: DropDuplicates -> Value
toJSON DropDuplicates' {Maybe [[Text]]
NonEmpty Text
Text
inputs :: NonEmpty Text
name :: Text
columns :: Maybe [[Text]]
$sel:inputs:DropDuplicates' :: DropDuplicates -> NonEmpty Text
$sel:name:DropDuplicates' :: DropDuplicates -> Text
$sel:columns:DropDuplicates' :: DropDuplicates -> Maybe [[Text]]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Columns" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [[Text]]
columns,
            forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"Inputs" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
inputs)
          ]
      )