{-# 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.Spigot
-- 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.Spigot 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 writes samples of the data to an Amazon S3
-- bucket.
--
-- /See:/ 'newSpigot' smart constructor.
data Spigot = Spigot'
  { -- | The probability (a decimal value with a maximum value of 1) of picking
    -- any given record. A value of 1 indicates that each row read from the
    -- dataset should be included in the sample output.
    Spigot -> Maybe Double
prob :: Prelude.Maybe Prelude.Double,
    -- | Specifies a number of records to write starting from the beginning of
    -- the dataset.
    Spigot -> Maybe Natural
topk :: Prelude.Maybe Prelude.Natural,
    -- | The name of the transform node.
    Spigot -> Text
name :: Prelude.Text,
    -- | The data inputs identified by their node names.
    Spigot -> NonEmpty Text
inputs :: Prelude.NonEmpty Prelude.Text,
    -- | A path in Amazon S3 where the transform will write a subset of records
    -- from the dataset to a JSON file in an Amazon S3 bucket.
    Spigot -> Text
path :: Prelude.Text
  }
  deriving (Spigot -> Spigot -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Spigot -> Spigot -> Bool
$c/= :: Spigot -> Spigot -> Bool
== :: Spigot -> Spigot -> Bool
$c== :: Spigot -> Spigot -> Bool
Prelude.Eq, ReadPrec [Spigot]
ReadPrec Spigot
Int -> ReadS Spigot
ReadS [Spigot]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Spigot]
$creadListPrec :: ReadPrec [Spigot]
readPrec :: ReadPrec Spigot
$creadPrec :: ReadPrec Spigot
readList :: ReadS [Spigot]
$creadList :: ReadS [Spigot]
readsPrec :: Int -> ReadS Spigot
$creadsPrec :: Int -> ReadS Spigot
Prelude.Read, Int -> Spigot -> ShowS
[Spigot] -> ShowS
Spigot -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Spigot] -> ShowS
$cshowList :: [Spigot] -> ShowS
show :: Spigot -> String
$cshow :: Spigot -> String
showsPrec :: Int -> Spigot -> ShowS
$cshowsPrec :: Int -> Spigot -> ShowS
Prelude.Show, forall x. Rep Spigot x -> Spigot
forall x. Spigot -> Rep Spigot x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Spigot x -> Spigot
$cfrom :: forall x. Spigot -> Rep Spigot x
Prelude.Generic)

-- |
-- Create a value of 'Spigot' 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:
--
-- 'prob', 'spigot_prob' - The probability (a decimal value with a maximum value of 1) of picking
-- any given record. A value of 1 indicates that each row read from the
-- dataset should be included in the sample output.
--
-- 'topk', 'spigot_topk' - Specifies a number of records to write starting from the beginning of
-- the dataset.
--
-- 'name', 'spigot_name' - The name of the transform node.
--
-- 'inputs', 'spigot_inputs' - The data inputs identified by their node names.
--
-- 'path', 'spigot_path' - A path in Amazon S3 where the transform will write a subset of records
-- from the dataset to a JSON file in an Amazon S3 bucket.
newSpigot ::
  -- | 'name'
  Prelude.Text ->
  -- | 'inputs'
  Prelude.NonEmpty Prelude.Text ->
  -- | 'path'
  Prelude.Text ->
  Spigot
newSpigot :: Text -> NonEmpty Text -> Text -> Spigot
newSpigot Text
pName_ NonEmpty Text
pInputs_ Text
pPath_ =
  Spigot'
    { $sel:prob:Spigot' :: Maybe Double
prob = forall a. Maybe a
Prelude.Nothing,
      $sel:topk:Spigot' :: Maybe Natural
topk = forall a. Maybe a
Prelude.Nothing,
      $sel:name:Spigot' :: Text
name = Text
pName_,
      $sel:inputs:Spigot' :: 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_,
      $sel:path:Spigot' :: Text
path = Text
pPath_
    }

-- | The probability (a decimal value with a maximum value of 1) of picking
-- any given record. A value of 1 indicates that each row read from the
-- dataset should be included in the sample output.
spigot_prob :: Lens.Lens' Spigot (Prelude.Maybe Prelude.Double)
spigot_prob :: Lens' Spigot (Maybe Double)
spigot_prob = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Spigot' {Maybe Double
prob :: Maybe Double
$sel:prob:Spigot' :: Spigot -> Maybe Double
prob} -> Maybe Double
prob) (\s :: Spigot
s@Spigot' {} Maybe Double
a -> Spigot
s {$sel:prob:Spigot' :: Maybe Double
prob = Maybe Double
a} :: Spigot)

-- | Specifies a number of records to write starting from the beginning of
-- the dataset.
spigot_topk :: Lens.Lens' Spigot (Prelude.Maybe Prelude.Natural)
spigot_topk :: Lens' Spigot (Maybe Natural)
spigot_topk = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Spigot' {Maybe Natural
topk :: Maybe Natural
$sel:topk:Spigot' :: Spigot -> Maybe Natural
topk} -> Maybe Natural
topk) (\s :: Spigot
s@Spigot' {} Maybe Natural
a -> Spigot
s {$sel:topk:Spigot' :: Maybe Natural
topk = Maybe Natural
a} :: Spigot)

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

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

-- | A path in Amazon S3 where the transform will write a subset of records
-- from the dataset to a JSON file in an Amazon S3 bucket.
spigot_path :: Lens.Lens' Spigot Prelude.Text
spigot_path :: Lens' Spigot Text
spigot_path = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Spigot' {Text
path :: Text
$sel:path:Spigot' :: Spigot -> Text
path} -> Text
path) (\s :: Spigot
s@Spigot' {} Text
a -> Spigot
s {$sel:path:Spigot' :: Text
path = Text
a} :: Spigot)

instance Data.FromJSON Spigot where
  parseJSON :: Value -> Parser Spigot
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Spigot"
      ( \Object
x ->
          Maybe Double
-> Maybe Natural -> Text -> NonEmpty Text -> Text -> Spigot
Spigot'
            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
"Prob")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Topk")
            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")
            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
"Path")
      )

instance Prelude.Hashable Spigot where
  hashWithSalt :: Int -> Spigot -> Int
hashWithSalt Int
_salt Spigot' {Maybe Double
Maybe Natural
NonEmpty Text
Text
path :: Text
inputs :: NonEmpty Text
name :: Text
topk :: Maybe Natural
prob :: Maybe Double
$sel:path:Spigot' :: Spigot -> Text
$sel:inputs:Spigot' :: Spigot -> NonEmpty Text
$sel:name:Spigot' :: Spigot -> Text
$sel:topk:Spigot' :: Spigot -> Maybe Natural
$sel:prob:Spigot' :: Spigot -> Maybe Double
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
prob
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
topk
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
inputs
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
path

instance Prelude.NFData Spigot where
  rnf :: Spigot -> ()
rnf Spigot' {Maybe Double
Maybe Natural
NonEmpty Text
Text
path :: Text
inputs :: NonEmpty Text
name :: Text
topk :: Maybe Natural
prob :: Maybe Double
$sel:path:Spigot' :: Spigot -> Text
$sel:inputs:Spigot' :: Spigot -> NonEmpty Text
$sel:name:Spigot' :: Spigot -> Text
$sel:topk:Spigot' :: Spigot -> Maybe Natural
$sel:prob:Spigot' :: Spigot -> Maybe Double
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
prob
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
topk
      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
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
path

instance Data.ToJSON Spigot where
  toJSON :: Spigot -> Value
toJSON Spigot' {Maybe Double
Maybe Natural
NonEmpty Text
Text
path :: Text
inputs :: NonEmpty Text
name :: Text
topk :: Maybe Natural
prob :: Maybe Double
$sel:path:Spigot' :: Spigot -> Text
$sel:inputs:Spigot' :: Spigot -> NonEmpty Text
$sel:name:Spigot' :: Spigot -> Text
$sel:topk:Spigot' :: Spigot -> Maybe Natural
$sel:prob:Spigot' :: Spigot -> Maybe Double
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Prob" 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 Double
prob,
            (Key
"Topk" 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 Natural
topk,
            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),
            forall a. a -> Maybe a
Prelude.Just (Key
"Path" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
path)
          ]
      )