{-# 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.RedshiftTarget
-- 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.RedshiftTarget 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.UpsertRedshiftTargetOptions
import qualified Amazonka.Prelude as Prelude

-- | Specifies a target that uses Amazon Redshift.
--
-- /See:/ 'newRedshiftTarget' smart constructor.
data RedshiftTarget = RedshiftTarget'
  { -- | The Amazon S3 path where temporary data can be staged when copying out
    -- of the database.
    RedshiftTarget -> Maybe Text
redshiftTmpDir :: Prelude.Maybe Prelude.Text,
    -- | The IAM role with permissions.
    RedshiftTarget -> Maybe Text
tmpDirIAMRole :: Prelude.Maybe Prelude.Text,
    -- | The set of options to configure an upsert operation when writing to a
    -- Redshift target.
    RedshiftTarget -> Maybe UpsertRedshiftTargetOptions
upsertRedshiftOptions :: Prelude.Maybe UpsertRedshiftTargetOptions,
    -- | The name of the data target.
    RedshiftTarget -> Text
name :: Prelude.Text,
    -- | The nodes that are inputs to the data target.
    RedshiftTarget -> NonEmpty Text
inputs :: Prelude.NonEmpty Prelude.Text,
    -- | The name of the database to write to.
    RedshiftTarget -> Text
database :: Prelude.Text,
    -- | The name of the table in the database to write to.
    RedshiftTarget -> Text
table :: Prelude.Text
  }
  deriving (RedshiftTarget -> RedshiftTarget -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RedshiftTarget -> RedshiftTarget -> Bool
$c/= :: RedshiftTarget -> RedshiftTarget -> Bool
== :: RedshiftTarget -> RedshiftTarget -> Bool
$c== :: RedshiftTarget -> RedshiftTarget -> Bool
Prelude.Eq, ReadPrec [RedshiftTarget]
ReadPrec RedshiftTarget
Int -> ReadS RedshiftTarget
ReadS [RedshiftTarget]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RedshiftTarget]
$creadListPrec :: ReadPrec [RedshiftTarget]
readPrec :: ReadPrec RedshiftTarget
$creadPrec :: ReadPrec RedshiftTarget
readList :: ReadS [RedshiftTarget]
$creadList :: ReadS [RedshiftTarget]
readsPrec :: Int -> ReadS RedshiftTarget
$creadsPrec :: Int -> ReadS RedshiftTarget
Prelude.Read, Int -> RedshiftTarget -> ShowS
[RedshiftTarget] -> ShowS
RedshiftTarget -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RedshiftTarget] -> ShowS
$cshowList :: [RedshiftTarget] -> ShowS
show :: RedshiftTarget -> String
$cshow :: RedshiftTarget -> String
showsPrec :: Int -> RedshiftTarget -> ShowS
$cshowsPrec :: Int -> RedshiftTarget -> ShowS
Prelude.Show, forall x. Rep RedshiftTarget x -> RedshiftTarget
forall x. RedshiftTarget -> Rep RedshiftTarget x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RedshiftTarget x -> RedshiftTarget
$cfrom :: forall x. RedshiftTarget -> Rep RedshiftTarget x
Prelude.Generic)

-- |
-- Create a value of 'RedshiftTarget' 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:
--
-- 'redshiftTmpDir', 'redshiftTarget_redshiftTmpDir' - The Amazon S3 path where temporary data can be staged when copying out
-- of the database.
--
-- 'tmpDirIAMRole', 'redshiftTarget_tmpDirIAMRole' - The IAM role with permissions.
--
-- 'upsertRedshiftOptions', 'redshiftTarget_upsertRedshiftOptions' - The set of options to configure an upsert operation when writing to a
-- Redshift target.
--
-- 'name', 'redshiftTarget_name' - The name of the data target.
--
-- 'inputs', 'redshiftTarget_inputs' - The nodes that are inputs to the data target.
--
-- 'database', 'redshiftTarget_database' - The name of the database to write to.
--
-- 'table', 'redshiftTarget_table' - The name of the table in the database to write to.
newRedshiftTarget ::
  -- | 'name'
  Prelude.Text ->
  -- | 'inputs'
  Prelude.NonEmpty Prelude.Text ->
  -- | 'database'
  Prelude.Text ->
  -- | 'table'
  Prelude.Text ->
  RedshiftTarget
newRedshiftTarget :: Text -> NonEmpty Text -> Text -> Text -> RedshiftTarget
newRedshiftTarget Text
pName_ NonEmpty Text
pInputs_ Text
pDatabase_ Text
pTable_ =
  RedshiftTarget'
    { $sel:redshiftTmpDir:RedshiftTarget' :: Maybe Text
redshiftTmpDir = forall a. Maybe a
Prelude.Nothing,
      $sel:tmpDirIAMRole:RedshiftTarget' :: Maybe Text
tmpDirIAMRole = forall a. Maybe a
Prelude.Nothing,
      $sel:upsertRedshiftOptions:RedshiftTarget' :: Maybe UpsertRedshiftTargetOptions
upsertRedshiftOptions = forall a. Maybe a
Prelude.Nothing,
      $sel:name:RedshiftTarget' :: Text
name = Text
pName_,
      $sel:inputs:RedshiftTarget' :: 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:database:RedshiftTarget' :: Text
database = Text
pDatabase_,
      $sel:table:RedshiftTarget' :: Text
table = Text
pTable_
    }

-- | The Amazon S3 path where temporary data can be staged when copying out
-- of the database.
redshiftTarget_redshiftTmpDir :: Lens.Lens' RedshiftTarget (Prelude.Maybe Prelude.Text)
redshiftTarget_redshiftTmpDir :: Lens' RedshiftTarget (Maybe Text)
redshiftTarget_redshiftTmpDir = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RedshiftTarget' {Maybe Text
redshiftTmpDir :: Maybe Text
$sel:redshiftTmpDir:RedshiftTarget' :: RedshiftTarget -> Maybe Text
redshiftTmpDir} -> Maybe Text
redshiftTmpDir) (\s :: RedshiftTarget
s@RedshiftTarget' {} Maybe Text
a -> RedshiftTarget
s {$sel:redshiftTmpDir:RedshiftTarget' :: Maybe Text
redshiftTmpDir = Maybe Text
a} :: RedshiftTarget)

-- | The IAM role with permissions.
redshiftTarget_tmpDirIAMRole :: Lens.Lens' RedshiftTarget (Prelude.Maybe Prelude.Text)
redshiftTarget_tmpDirIAMRole :: Lens' RedshiftTarget (Maybe Text)
redshiftTarget_tmpDirIAMRole = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RedshiftTarget' {Maybe Text
tmpDirIAMRole :: Maybe Text
$sel:tmpDirIAMRole:RedshiftTarget' :: RedshiftTarget -> Maybe Text
tmpDirIAMRole} -> Maybe Text
tmpDirIAMRole) (\s :: RedshiftTarget
s@RedshiftTarget' {} Maybe Text
a -> RedshiftTarget
s {$sel:tmpDirIAMRole:RedshiftTarget' :: Maybe Text
tmpDirIAMRole = Maybe Text
a} :: RedshiftTarget)

-- | The set of options to configure an upsert operation when writing to a
-- Redshift target.
redshiftTarget_upsertRedshiftOptions :: Lens.Lens' RedshiftTarget (Prelude.Maybe UpsertRedshiftTargetOptions)
redshiftTarget_upsertRedshiftOptions :: Lens' RedshiftTarget (Maybe UpsertRedshiftTargetOptions)
redshiftTarget_upsertRedshiftOptions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RedshiftTarget' {Maybe UpsertRedshiftTargetOptions
upsertRedshiftOptions :: Maybe UpsertRedshiftTargetOptions
$sel:upsertRedshiftOptions:RedshiftTarget' :: RedshiftTarget -> Maybe UpsertRedshiftTargetOptions
upsertRedshiftOptions} -> Maybe UpsertRedshiftTargetOptions
upsertRedshiftOptions) (\s :: RedshiftTarget
s@RedshiftTarget' {} Maybe UpsertRedshiftTargetOptions
a -> RedshiftTarget
s {$sel:upsertRedshiftOptions:RedshiftTarget' :: Maybe UpsertRedshiftTargetOptions
upsertRedshiftOptions = Maybe UpsertRedshiftTargetOptions
a} :: RedshiftTarget)

-- | The name of the data target.
redshiftTarget_name :: Lens.Lens' RedshiftTarget Prelude.Text
redshiftTarget_name :: Lens' RedshiftTarget Text
redshiftTarget_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RedshiftTarget' {Text
name :: Text
$sel:name:RedshiftTarget' :: RedshiftTarget -> Text
name} -> Text
name) (\s :: RedshiftTarget
s@RedshiftTarget' {} Text
a -> RedshiftTarget
s {$sel:name:RedshiftTarget' :: Text
name = Text
a} :: RedshiftTarget)

-- | The nodes that are inputs to the data target.
redshiftTarget_inputs :: Lens.Lens' RedshiftTarget (Prelude.NonEmpty Prelude.Text)
redshiftTarget_inputs :: Lens' RedshiftTarget (NonEmpty Text)
redshiftTarget_inputs = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RedshiftTarget' {NonEmpty Text
inputs :: NonEmpty Text
$sel:inputs:RedshiftTarget' :: RedshiftTarget -> NonEmpty Text
inputs} -> NonEmpty Text
inputs) (\s :: RedshiftTarget
s@RedshiftTarget' {} NonEmpty Text
a -> RedshiftTarget
s {$sel:inputs:RedshiftTarget' :: NonEmpty Text
inputs = NonEmpty Text
a} :: RedshiftTarget) 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

-- | The name of the database to write to.
redshiftTarget_database :: Lens.Lens' RedshiftTarget Prelude.Text
redshiftTarget_database :: Lens' RedshiftTarget Text
redshiftTarget_database = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RedshiftTarget' {Text
database :: Text
$sel:database:RedshiftTarget' :: RedshiftTarget -> Text
database} -> Text
database) (\s :: RedshiftTarget
s@RedshiftTarget' {} Text
a -> RedshiftTarget
s {$sel:database:RedshiftTarget' :: Text
database = Text
a} :: RedshiftTarget)

-- | The name of the table in the database to write to.
redshiftTarget_table :: Lens.Lens' RedshiftTarget Prelude.Text
redshiftTarget_table :: Lens' RedshiftTarget Text
redshiftTarget_table = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RedshiftTarget' {Text
table :: Text
$sel:table:RedshiftTarget' :: RedshiftTarget -> Text
table} -> Text
table) (\s :: RedshiftTarget
s@RedshiftTarget' {} Text
a -> RedshiftTarget
s {$sel:table:RedshiftTarget' :: Text
table = Text
a} :: RedshiftTarget)

instance Data.FromJSON RedshiftTarget where
  parseJSON :: Value -> Parser RedshiftTarget
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RedshiftTarget"
      ( \Object
x ->
          Maybe Text
-> Maybe Text
-> Maybe UpsertRedshiftTargetOptions
-> Text
-> NonEmpty Text
-> Text
-> Text
-> RedshiftTarget
RedshiftTarget'
            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
"RedshiftTmpDir")
            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
"TmpDirIAMRole")
            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
"UpsertRedshiftOptions")
            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
"Database")
            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
"Table")
      )

instance Prelude.Hashable RedshiftTarget where
  hashWithSalt :: Int -> RedshiftTarget -> Int
hashWithSalt Int
_salt RedshiftTarget' {Maybe Text
Maybe UpsertRedshiftTargetOptions
NonEmpty Text
Text
table :: Text
database :: Text
inputs :: NonEmpty Text
name :: Text
upsertRedshiftOptions :: Maybe UpsertRedshiftTargetOptions
tmpDirIAMRole :: Maybe Text
redshiftTmpDir :: Maybe Text
$sel:table:RedshiftTarget' :: RedshiftTarget -> Text
$sel:database:RedshiftTarget' :: RedshiftTarget -> Text
$sel:inputs:RedshiftTarget' :: RedshiftTarget -> NonEmpty Text
$sel:name:RedshiftTarget' :: RedshiftTarget -> Text
$sel:upsertRedshiftOptions:RedshiftTarget' :: RedshiftTarget -> Maybe UpsertRedshiftTargetOptions
$sel:tmpDirIAMRole:RedshiftTarget' :: RedshiftTarget -> Maybe Text
$sel:redshiftTmpDir:RedshiftTarget' :: RedshiftTarget -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
redshiftTmpDir
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
tmpDirIAMRole
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe UpsertRedshiftTargetOptions
upsertRedshiftOptions
      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
database
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
table

instance Prelude.NFData RedshiftTarget where
  rnf :: RedshiftTarget -> ()
rnf RedshiftTarget' {Maybe Text
Maybe UpsertRedshiftTargetOptions
NonEmpty Text
Text
table :: Text
database :: Text
inputs :: NonEmpty Text
name :: Text
upsertRedshiftOptions :: Maybe UpsertRedshiftTargetOptions
tmpDirIAMRole :: Maybe Text
redshiftTmpDir :: Maybe Text
$sel:table:RedshiftTarget' :: RedshiftTarget -> Text
$sel:database:RedshiftTarget' :: RedshiftTarget -> Text
$sel:inputs:RedshiftTarget' :: RedshiftTarget -> NonEmpty Text
$sel:name:RedshiftTarget' :: RedshiftTarget -> Text
$sel:upsertRedshiftOptions:RedshiftTarget' :: RedshiftTarget -> Maybe UpsertRedshiftTargetOptions
$sel:tmpDirIAMRole:RedshiftTarget' :: RedshiftTarget -> Maybe Text
$sel:redshiftTmpDir:RedshiftTarget' :: RedshiftTarget -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
redshiftTmpDir
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
tmpDirIAMRole
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe UpsertRedshiftTargetOptions
upsertRedshiftOptions
      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
database
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
table

instance Data.ToJSON RedshiftTarget where
  toJSON :: RedshiftTarget -> Value
toJSON RedshiftTarget' {Maybe Text
Maybe UpsertRedshiftTargetOptions
NonEmpty Text
Text
table :: Text
database :: Text
inputs :: NonEmpty Text
name :: Text
upsertRedshiftOptions :: Maybe UpsertRedshiftTargetOptions
tmpDirIAMRole :: Maybe Text
redshiftTmpDir :: Maybe Text
$sel:table:RedshiftTarget' :: RedshiftTarget -> Text
$sel:database:RedshiftTarget' :: RedshiftTarget -> Text
$sel:inputs:RedshiftTarget' :: RedshiftTarget -> NonEmpty Text
$sel:name:RedshiftTarget' :: RedshiftTarget -> Text
$sel:upsertRedshiftOptions:RedshiftTarget' :: RedshiftTarget -> Maybe UpsertRedshiftTargetOptions
$sel:tmpDirIAMRole:RedshiftTarget' :: RedshiftTarget -> Maybe Text
$sel:redshiftTmpDir:RedshiftTarget' :: RedshiftTarget -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"RedshiftTmpDir" 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
redshiftTmpDir,
            (Key
"TmpDirIAMRole" 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
tmpDirIAMRole,
            (Key
"UpsertRedshiftOptions" 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 UpsertRedshiftTargetOptions
upsertRedshiftOptions,
            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
"Database" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
database),
            forall a. a -> Maybe a
Prelude.Just (Key
"Table" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
table)
          ]
      )