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

-- | Specifies a data target that writes to Amazon S3 using the Glue Data
-- Catalog.
--
-- /See:/ 'newGovernedCatalogTarget' smart constructor.
data GovernedCatalogTarget = GovernedCatalogTarget'
  { -- | Specifies native partitioning using a sequence of keys.
    GovernedCatalogTarget -> Maybe [[Text]]
partitionKeys :: Prelude.Maybe [[Prelude.Text]],
    -- | A policy that specifies update behavior for the governed catalog.
    GovernedCatalogTarget -> Maybe CatalogSchemaChangePolicy
schemaChangePolicy :: Prelude.Maybe CatalogSchemaChangePolicy,
    -- | The name of the data target.
    GovernedCatalogTarget -> Text
name :: Prelude.Text,
    -- | The nodes that are inputs to the data target.
    GovernedCatalogTarget -> NonEmpty Text
inputs :: Prelude.NonEmpty Prelude.Text,
    -- | The name of the table in the database to write to.
    GovernedCatalogTarget -> Text
table :: Prelude.Text,
    -- | The name of the database to write to.
    GovernedCatalogTarget -> Text
database :: Prelude.Text
  }
  deriving (GovernedCatalogTarget -> GovernedCatalogTarget -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GovernedCatalogTarget -> GovernedCatalogTarget -> Bool
$c/= :: GovernedCatalogTarget -> GovernedCatalogTarget -> Bool
== :: GovernedCatalogTarget -> GovernedCatalogTarget -> Bool
$c== :: GovernedCatalogTarget -> GovernedCatalogTarget -> Bool
Prelude.Eq, ReadPrec [GovernedCatalogTarget]
ReadPrec GovernedCatalogTarget
Int -> ReadS GovernedCatalogTarget
ReadS [GovernedCatalogTarget]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GovernedCatalogTarget]
$creadListPrec :: ReadPrec [GovernedCatalogTarget]
readPrec :: ReadPrec GovernedCatalogTarget
$creadPrec :: ReadPrec GovernedCatalogTarget
readList :: ReadS [GovernedCatalogTarget]
$creadList :: ReadS [GovernedCatalogTarget]
readsPrec :: Int -> ReadS GovernedCatalogTarget
$creadsPrec :: Int -> ReadS GovernedCatalogTarget
Prelude.Read, Int -> GovernedCatalogTarget -> ShowS
[GovernedCatalogTarget] -> ShowS
GovernedCatalogTarget -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GovernedCatalogTarget] -> ShowS
$cshowList :: [GovernedCatalogTarget] -> ShowS
show :: GovernedCatalogTarget -> String
$cshow :: GovernedCatalogTarget -> String
showsPrec :: Int -> GovernedCatalogTarget -> ShowS
$cshowsPrec :: Int -> GovernedCatalogTarget -> ShowS
Prelude.Show, forall x. Rep GovernedCatalogTarget x -> GovernedCatalogTarget
forall x. GovernedCatalogTarget -> Rep GovernedCatalogTarget x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GovernedCatalogTarget x -> GovernedCatalogTarget
$cfrom :: forall x. GovernedCatalogTarget -> Rep GovernedCatalogTarget x
Prelude.Generic)

-- |
-- Create a value of 'GovernedCatalogTarget' 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:
--
-- 'partitionKeys', 'governedCatalogTarget_partitionKeys' - Specifies native partitioning using a sequence of keys.
--
-- 'schemaChangePolicy', 'governedCatalogTarget_schemaChangePolicy' - A policy that specifies update behavior for the governed catalog.
--
-- 'name', 'governedCatalogTarget_name' - The name of the data target.
--
-- 'inputs', 'governedCatalogTarget_inputs' - The nodes that are inputs to the data target.
--
-- 'table', 'governedCatalogTarget_table' - The name of the table in the database to write to.
--
-- 'database', 'governedCatalogTarget_database' - The name of the database to write to.
newGovernedCatalogTarget ::
  -- | 'name'
  Prelude.Text ->
  -- | 'inputs'
  Prelude.NonEmpty Prelude.Text ->
  -- | 'table'
  Prelude.Text ->
  -- | 'database'
  Prelude.Text ->
  GovernedCatalogTarget
newGovernedCatalogTarget :: Text -> NonEmpty Text -> Text -> Text -> GovernedCatalogTarget
newGovernedCatalogTarget
  Text
pName_
  NonEmpty Text
pInputs_
  Text
pTable_
  Text
pDatabase_ =
    GovernedCatalogTarget'
      { $sel:partitionKeys:GovernedCatalogTarget' :: Maybe [[Text]]
partitionKeys =
          forall a. Maybe a
Prelude.Nothing,
        $sel:schemaChangePolicy:GovernedCatalogTarget' :: Maybe CatalogSchemaChangePolicy
schemaChangePolicy = forall a. Maybe a
Prelude.Nothing,
        $sel:name:GovernedCatalogTarget' :: Text
name = Text
pName_,
        $sel:inputs:GovernedCatalogTarget' :: 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:table:GovernedCatalogTarget' :: Text
table = Text
pTable_,
        $sel:database:GovernedCatalogTarget' :: Text
database = Text
pDatabase_
      }

-- | Specifies native partitioning using a sequence of keys.
governedCatalogTarget_partitionKeys :: Lens.Lens' GovernedCatalogTarget (Prelude.Maybe [[Prelude.Text]])
governedCatalogTarget_partitionKeys :: Lens' GovernedCatalogTarget (Maybe [[Text]])
governedCatalogTarget_partitionKeys = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GovernedCatalogTarget' {Maybe [[Text]]
partitionKeys :: Maybe [[Text]]
$sel:partitionKeys:GovernedCatalogTarget' :: GovernedCatalogTarget -> Maybe [[Text]]
partitionKeys} -> Maybe [[Text]]
partitionKeys) (\s :: GovernedCatalogTarget
s@GovernedCatalogTarget' {} Maybe [[Text]]
a -> GovernedCatalogTarget
s {$sel:partitionKeys:GovernedCatalogTarget' :: Maybe [[Text]]
partitionKeys = Maybe [[Text]]
a} :: GovernedCatalogTarget) 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

-- | A policy that specifies update behavior for the governed catalog.
governedCatalogTarget_schemaChangePolicy :: Lens.Lens' GovernedCatalogTarget (Prelude.Maybe CatalogSchemaChangePolicy)
governedCatalogTarget_schemaChangePolicy :: Lens' GovernedCatalogTarget (Maybe CatalogSchemaChangePolicy)
governedCatalogTarget_schemaChangePolicy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GovernedCatalogTarget' {Maybe CatalogSchemaChangePolicy
schemaChangePolicy :: Maybe CatalogSchemaChangePolicy
$sel:schemaChangePolicy:GovernedCatalogTarget' :: GovernedCatalogTarget -> Maybe CatalogSchemaChangePolicy
schemaChangePolicy} -> Maybe CatalogSchemaChangePolicy
schemaChangePolicy) (\s :: GovernedCatalogTarget
s@GovernedCatalogTarget' {} Maybe CatalogSchemaChangePolicy
a -> GovernedCatalogTarget
s {$sel:schemaChangePolicy:GovernedCatalogTarget' :: Maybe CatalogSchemaChangePolicy
schemaChangePolicy = Maybe CatalogSchemaChangePolicy
a} :: GovernedCatalogTarget)

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

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

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

instance Data.FromJSON GovernedCatalogTarget where
  parseJSON :: Value -> Parser GovernedCatalogTarget
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"GovernedCatalogTarget"
      ( \Object
x ->
          Maybe [[Text]]
-> Maybe CatalogSchemaChangePolicy
-> Text
-> NonEmpty Text
-> Text
-> Text
-> GovernedCatalogTarget
GovernedCatalogTarget'
            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
"PartitionKeys" 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 (Maybe a)
Data..:? Key
"SchemaChangePolicy")
            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
"Table")
            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")
      )

instance Prelude.Hashable GovernedCatalogTarget where
  hashWithSalt :: Int -> GovernedCatalogTarget -> Int
hashWithSalt Int
_salt GovernedCatalogTarget' {Maybe [[Text]]
Maybe CatalogSchemaChangePolicy
NonEmpty Text
Text
database :: Text
table :: Text
inputs :: NonEmpty Text
name :: Text
schemaChangePolicy :: Maybe CatalogSchemaChangePolicy
partitionKeys :: Maybe [[Text]]
$sel:database:GovernedCatalogTarget' :: GovernedCatalogTarget -> Text
$sel:table:GovernedCatalogTarget' :: GovernedCatalogTarget -> Text
$sel:inputs:GovernedCatalogTarget' :: GovernedCatalogTarget -> NonEmpty Text
$sel:name:GovernedCatalogTarget' :: GovernedCatalogTarget -> Text
$sel:schemaChangePolicy:GovernedCatalogTarget' :: GovernedCatalogTarget -> Maybe CatalogSchemaChangePolicy
$sel:partitionKeys:GovernedCatalogTarget' :: GovernedCatalogTarget -> Maybe [[Text]]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [[Text]]
partitionKeys
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CatalogSchemaChangePolicy
schemaChangePolicy
      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
table
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
database

instance Prelude.NFData GovernedCatalogTarget where
  rnf :: GovernedCatalogTarget -> ()
rnf GovernedCatalogTarget' {Maybe [[Text]]
Maybe CatalogSchemaChangePolicy
NonEmpty Text
Text
database :: Text
table :: Text
inputs :: NonEmpty Text
name :: Text
schemaChangePolicy :: Maybe CatalogSchemaChangePolicy
partitionKeys :: Maybe [[Text]]
$sel:database:GovernedCatalogTarget' :: GovernedCatalogTarget -> Text
$sel:table:GovernedCatalogTarget' :: GovernedCatalogTarget -> Text
$sel:inputs:GovernedCatalogTarget' :: GovernedCatalogTarget -> NonEmpty Text
$sel:name:GovernedCatalogTarget' :: GovernedCatalogTarget -> Text
$sel:schemaChangePolicy:GovernedCatalogTarget' :: GovernedCatalogTarget -> Maybe CatalogSchemaChangePolicy
$sel:partitionKeys:GovernedCatalogTarget' :: GovernedCatalogTarget -> Maybe [[Text]]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [[Text]]
partitionKeys
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe CatalogSchemaChangePolicy
schemaChangePolicy
      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
table
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
database

instance Data.ToJSON GovernedCatalogTarget where
  toJSON :: GovernedCatalogTarget -> Value
toJSON GovernedCatalogTarget' {Maybe [[Text]]
Maybe CatalogSchemaChangePolicy
NonEmpty Text
Text
database :: Text
table :: Text
inputs :: NonEmpty Text
name :: Text
schemaChangePolicy :: Maybe CatalogSchemaChangePolicy
partitionKeys :: Maybe [[Text]]
$sel:database:GovernedCatalogTarget' :: GovernedCatalogTarget -> Text
$sel:table:GovernedCatalogTarget' :: GovernedCatalogTarget -> Text
$sel:inputs:GovernedCatalogTarget' :: GovernedCatalogTarget -> NonEmpty Text
$sel:name:GovernedCatalogTarget' :: GovernedCatalogTarget -> Text
$sel:schemaChangePolicy:GovernedCatalogTarget' :: GovernedCatalogTarget -> Maybe CatalogSchemaChangePolicy
$sel:partitionKeys:GovernedCatalogTarget' :: GovernedCatalogTarget -> Maybe [[Text]]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"PartitionKeys" 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]]
partitionKeys,
            (Key
"SchemaChangePolicy" 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 CatalogSchemaChangePolicy
schemaChangePolicy,
            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
"Table" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
table),
            forall a. a -> Maybe a
Prelude.Just (Key
"Database" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
database)
          ]
      )