{-# 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.PartitionIndexDescriptor
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Glue.Types.PartitionIndexDescriptor where

import qualified Amazonka.Core as Core
import Amazonka.Glue.Types.BackfillError
import Amazonka.Glue.Types.KeySchemaElement
import Amazonka.Glue.Types.PartitionIndexStatus
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A descriptor for a partition index in a table.
--
-- /See:/ 'newPartitionIndexDescriptor' smart constructor.
data PartitionIndexDescriptor = PartitionIndexDescriptor'
  { -- | A list of errors that can occur when registering partition indexes for
    -- an existing table.
    PartitionIndexDescriptor -> Maybe [BackfillError]
backfillErrors :: Prelude.Maybe [BackfillError],
    -- | The name of the partition index.
    PartitionIndexDescriptor -> Text
indexName :: Prelude.Text,
    -- | A list of one or more keys, as @KeySchemaElement@ structures, for the
    -- partition index.
    PartitionIndexDescriptor -> NonEmpty KeySchemaElement
keys :: Prelude.NonEmpty KeySchemaElement,
    -- | The status of the partition index.
    --
    -- The possible statuses are:
    --
    -- -   CREATING: The index is being created. When an index is in a CREATING
    --     state, the index or its table cannot be deleted.
    --
    -- -   ACTIVE: The index creation succeeds.
    --
    -- -   FAILED: The index creation fails.
    --
    -- -   DELETING: The index is deleted from the list of indexes.
    PartitionIndexDescriptor -> PartitionIndexStatus
indexStatus :: PartitionIndexStatus
  }
  deriving (PartitionIndexDescriptor -> PartitionIndexDescriptor -> Bool
(PartitionIndexDescriptor -> PartitionIndexDescriptor -> Bool)
-> (PartitionIndexDescriptor -> PartitionIndexDescriptor -> Bool)
-> Eq PartitionIndexDescriptor
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PartitionIndexDescriptor -> PartitionIndexDescriptor -> Bool
$c/= :: PartitionIndexDescriptor -> PartitionIndexDescriptor -> Bool
== :: PartitionIndexDescriptor -> PartitionIndexDescriptor -> Bool
$c== :: PartitionIndexDescriptor -> PartitionIndexDescriptor -> Bool
Prelude.Eq, ReadPrec [PartitionIndexDescriptor]
ReadPrec PartitionIndexDescriptor
Int -> ReadS PartitionIndexDescriptor
ReadS [PartitionIndexDescriptor]
(Int -> ReadS PartitionIndexDescriptor)
-> ReadS [PartitionIndexDescriptor]
-> ReadPrec PartitionIndexDescriptor
-> ReadPrec [PartitionIndexDescriptor]
-> Read PartitionIndexDescriptor
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PartitionIndexDescriptor]
$creadListPrec :: ReadPrec [PartitionIndexDescriptor]
readPrec :: ReadPrec PartitionIndexDescriptor
$creadPrec :: ReadPrec PartitionIndexDescriptor
readList :: ReadS [PartitionIndexDescriptor]
$creadList :: ReadS [PartitionIndexDescriptor]
readsPrec :: Int -> ReadS PartitionIndexDescriptor
$creadsPrec :: Int -> ReadS PartitionIndexDescriptor
Prelude.Read, Int -> PartitionIndexDescriptor -> ShowS
[PartitionIndexDescriptor] -> ShowS
PartitionIndexDescriptor -> String
(Int -> PartitionIndexDescriptor -> ShowS)
-> (PartitionIndexDescriptor -> String)
-> ([PartitionIndexDescriptor] -> ShowS)
-> Show PartitionIndexDescriptor
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PartitionIndexDescriptor] -> ShowS
$cshowList :: [PartitionIndexDescriptor] -> ShowS
show :: PartitionIndexDescriptor -> String
$cshow :: PartitionIndexDescriptor -> String
showsPrec :: Int -> PartitionIndexDescriptor -> ShowS
$cshowsPrec :: Int -> PartitionIndexDescriptor -> ShowS
Prelude.Show, (forall x.
 PartitionIndexDescriptor -> Rep PartitionIndexDescriptor x)
-> (forall x.
    Rep PartitionIndexDescriptor x -> PartitionIndexDescriptor)
-> Generic PartitionIndexDescriptor
forall x.
Rep PartitionIndexDescriptor x -> PartitionIndexDescriptor
forall x.
PartitionIndexDescriptor -> Rep PartitionIndexDescriptor x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PartitionIndexDescriptor x -> PartitionIndexDescriptor
$cfrom :: forall x.
PartitionIndexDescriptor -> Rep PartitionIndexDescriptor x
Prelude.Generic)

-- |
-- Create a value of 'PartitionIndexDescriptor' 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:
--
-- 'backfillErrors', 'partitionIndexDescriptor_backfillErrors' - A list of errors that can occur when registering partition indexes for
-- an existing table.
--
-- 'indexName', 'partitionIndexDescriptor_indexName' - The name of the partition index.
--
-- 'keys', 'partitionIndexDescriptor_keys' - A list of one or more keys, as @KeySchemaElement@ structures, for the
-- partition index.
--
-- 'indexStatus', 'partitionIndexDescriptor_indexStatus' - The status of the partition index.
--
-- The possible statuses are:
--
-- -   CREATING: The index is being created. When an index is in a CREATING
--     state, the index or its table cannot be deleted.
--
-- -   ACTIVE: The index creation succeeds.
--
-- -   FAILED: The index creation fails.
--
-- -   DELETING: The index is deleted from the list of indexes.
newPartitionIndexDescriptor ::
  -- | 'indexName'
  Prelude.Text ->
  -- | 'keys'
  Prelude.NonEmpty KeySchemaElement ->
  -- | 'indexStatus'
  PartitionIndexStatus ->
  PartitionIndexDescriptor
newPartitionIndexDescriptor :: Text
-> NonEmpty KeySchemaElement
-> PartitionIndexStatus
-> PartitionIndexDescriptor
newPartitionIndexDescriptor
  Text
pIndexName_
  NonEmpty KeySchemaElement
pKeys_
  PartitionIndexStatus
pIndexStatus_ =
    PartitionIndexDescriptor' :: Maybe [BackfillError]
-> Text
-> NonEmpty KeySchemaElement
-> PartitionIndexStatus
-> PartitionIndexDescriptor
PartitionIndexDescriptor'
      { $sel:backfillErrors:PartitionIndexDescriptor' :: Maybe [BackfillError]
backfillErrors =
          Maybe [BackfillError]
forall a. Maybe a
Prelude.Nothing,
        $sel:indexName:PartitionIndexDescriptor' :: Text
indexName = Text
pIndexName_,
        $sel:keys:PartitionIndexDescriptor' :: NonEmpty KeySchemaElement
keys = Tagged
  (NonEmpty KeySchemaElement) (Identity (NonEmpty KeySchemaElement))
-> Tagged
     (NonEmpty KeySchemaElement) (Identity (NonEmpty KeySchemaElement))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged
   (NonEmpty KeySchemaElement) (Identity (NonEmpty KeySchemaElement))
 -> Tagged
      (NonEmpty KeySchemaElement) (Identity (NonEmpty KeySchemaElement)))
-> NonEmpty KeySchemaElement -> NonEmpty KeySchemaElement
forall t b. AReview t b -> b -> t
Lens.# NonEmpty KeySchemaElement
pKeys_,
        $sel:indexStatus:PartitionIndexDescriptor' :: PartitionIndexStatus
indexStatus = PartitionIndexStatus
pIndexStatus_
      }

-- | A list of errors that can occur when registering partition indexes for
-- an existing table.
partitionIndexDescriptor_backfillErrors :: Lens.Lens' PartitionIndexDescriptor (Prelude.Maybe [BackfillError])
partitionIndexDescriptor_backfillErrors :: (Maybe [BackfillError] -> f (Maybe [BackfillError]))
-> PartitionIndexDescriptor -> f PartitionIndexDescriptor
partitionIndexDescriptor_backfillErrors = (PartitionIndexDescriptor -> Maybe [BackfillError])
-> (PartitionIndexDescriptor
    -> Maybe [BackfillError] -> PartitionIndexDescriptor)
-> Lens
     PartitionIndexDescriptor
     PartitionIndexDescriptor
     (Maybe [BackfillError])
     (Maybe [BackfillError])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PartitionIndexDescriptor' {Maybe [BackfillError]
backfillErrors :: Maybe [BackfillError]
$sel:backfillErrors:PartitionIndexDescriptor' :: PartitionIndexDescriptor -> Maybe [BackfillError]
backfillErrors} -> Maybe [BackfillError]
backfillErrors) (\s :: PartitionIndexDescriptor
s@PartitionIndexDescriptor' {} Maybe [BackfillError]
a -> PartitionIndexDescriptor
s {$sel:backfillErrors:PartitionIndexDescriptor' :: Maybe [BackfillError]
backfillErrors = Maybe [BackfillError]
a} :: PartitionIndexDescriptor) ((Maybe [BackfillError] -> f (Maybe [BackfillError]))
 -> PartitionIndexDescriptor -> f PartitionIndexDescriptor)
-> ((Maybe [BackfillError] -> f (Maybe [BackfillError]))
    -> Maybe [BackfillError] -> f (Maybe [BackfillError]))
-> (Maybe [BackfillError] -> f (Maybe [BackfillError]))
-> PartitionIndexDescriptor
-> f PartitionIndexDescriptor
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [BackfillError] [BackfillError] [BackfillError] [BackfillError]
-> Iso
     (Maybe [BackfillError])
     (Maybe [BackfillError])
     (Maybe [BackfillError])
     (Maybe [BackfillError])
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 AnIso
  [BackfillError] [BackfillError] [BackfillError] [BackfillError]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the partition index.
partitionIndexDescriptor_indexName :: Lens.Lens' PartitionIndexDescriptor Prelude.Text
partitionIndexDescriptor_indexName :: (Text -> f Text)
-> PartitionIndexDescriptor -> f PartitionIndexDescriptor
partitionIndexDescriptor_indexName = (PartitionIndexDescriptor -> Text)
-> (PartitionIndexDescriptor -> Text -> PartitionIndexDescriptor)
-> Lens PartitionIndexDescriptor PartitionIndexDescriptor Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PartitionIndexDescriptor' {Text
indexName :: Text
$sel:indexName:PartitionIndexDescriptor' :: PartitionIndexDescriptor -> Text
indexName} -> Text
indexName) (\s :: PartitionIndexDescriptor
s@PartitionIndexDescriptor' {} Text
a -> PartitionIndexDescriptor
s {$sel:indexName:PartitionIndexDescriptor' :: Text
indexName = Text
a} :: PartitionIndexDescriptor)

-- | A list of one or more keys, as @KeySchemaElement@ structures, for the
-- partition index.
partitionIndexDescriptor_keys :: Lens.Lens' PartitionIndexDescriptor (Prelude.NonEmpty KeySchemaElement)
partitionIndexDescriptor_keys :: (NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
-> PartitionIndexDescriptor -> f PartitionIndexDescriptor
partitionIndexDescriptor_keys = (PartitionIndexDescriptor -> NonEmpty KeySchemaElement)
-> (PartitionIndexDescriptor
    -> NonEmpty KeySchemaElement -> PartitionIndexDescriptor)
-> Lens
     PartitionIndexDescriptor
     PartitionIndexDescriptor
     (NonEmpty KeySchemaElement)
     (NonEmpty KeySchemaElement)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PartitionIndexDescriptor' {NonEmpty KeySchemaElement
keys :: NonEmpty KeySchemaElement
$sel:keys:PartitionIndexDescriptor' :: PartitionIndexDescriptor -> NonEmpty KeySchemaElement
keys} -> NonEmpty KeySchemaElement
keys) (\s :: PartitionIndexDescriptor
s@PartitionIndexDescriptor' {} NonEmpty KeySchemaElement
a -> PartitionIndexDescriptor
s {$sel:keys:PartitionIndexDescriptor' :: NonEmpty KeySchemaElement
keys = NonEmpty KeySchemaElement
a} :: PartitionIndexDescriptor) ((NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
 -> PartitionIndexDescriptor -> f PartitionIndexDescriptor)
-> ((NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
    -> NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
-> (NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
-> PartitionIndexDescriptor
-> f PartitionIndexDescriptor
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement))
-> NonEmpty KeySchemaElement -> f (NonEmpty KeySchemaElement)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The status of the partition index.
--
-- The possible statuses are:
--
-- -   CREATING: The index is being created. When an index is in a CREATING
--     state, the index or its table cannot be deleted.
--
-- -   ACTIVE: The index creation succeeds.
--
-- -   FAILED: The index creation fails.
--
-- -   DELETING: The index is deleted from the list of indexes.
partitionIndexDescriptor_indexStatus :: Lens.Lens' PartitionIndexDescriptor PartitionIndexStatus
partitionIndexDescriptor_indexStatus :: (PartitionIndexStatus -> f PartitionIndexStatus)
-> PartitionIndexDescriptor -> f PartitionIndexDescriptor
partitionIndexDescriptor_indexStatus = (PartitionIndexDescriptor -> PartitionIndexStatus)
-> (PartitionIndexDescriptor
    -> PartitionIndexStatus -> PartitionIndexDescriptor)
-> Lens
     PartitionIndexDescriptor
     PartitionIndexDescriptor
     PartitionIndexStatus
     PartitionIndexStatus
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PartitionIndexDescriptor' {PartitionIndexStatus
indexStatus :: PartitionIndexStatus
$sel:indexStatus:PartitionIndexDescriptor' :: PartitionIndexDescriptor -> PartitionIndexStatus
indexStatus} -> PartitionIndexStatus
indexStatus) (\s :: PartitionIndexDescriptor
s@PartitionIndexDescriptor' {} PartitionIndexStatus
a -> PartitionIndexDescriptor
s {$sel:indexStatus:PartitionIndexDescriptor' :: PartitionIndexStatus
indexStatus = PartitionIndexStatus
a} :: PartitionIndexDescriptor)

instance Core.FromJSON PartitionIndexDescriptor where
  parseJSON :: Value -> Parser PartitionIndexDescriptor
parseJSON =
    String
-> (Object -> Parser PartitionIndexDescriptor)
-> Value
-> Parser PartitionIndexDescriptor
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PartitionIndexDescriptor"
      ( \Object
x ->
          Maybe [BackfillError]
-> Text
-> NonEmpty KeySchemaElement
-> PartitionIndexStatus
-> PartitionIndexDescriptor
PartitionIndexDescriptor'
            (Maybe [BackfillError]
 -> Text
 -> NonEmpty KeySchemaElement
 -> PartitionIndexStatus
 -> PartitionIndexDescriptor)
-> Parser (Maybe [BackfillError])
-> Parser
     (Text
      -> NonEmpty KeySchemaElement
      -> PartitionIndexStatus
      -> PartitionIndexDescriptor)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [BackfillError]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"BackfillErrors" Parser (Maybe (Maybe [BackfillError]))
-> Maybe [BackfillError] -> Parser (Maybe [BackfillError])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [BackfillError]
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Text
   -> NonEmpty KeySchemaElement
   -> PartitionIndexStatus
   -> PartitionIndexDescriptor)
-> Parser Text
-> Parser
     (NonEmpty KeySchemaElement
      -> PartitionIndexStatus -> PartitionIndexDescriptor)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"IndexName")
            Parser
  (NonEmpty KeySchemaElement
   -> PartitionIndexStatus -> PartitionIndexDescriptor)
-> Parser (NonEmpty KeySchemaElement)
-> Parser (PartitionIndexStatus -> PartitionIndexDescriptor)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (NonEmpty KeySchemaElement)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Keys")
            Parser (PartitionIndexStatus -> PartitionIndexDescriptor)
-> Parser PartitionIndexStatus -> Parser PartitionIndexDescriptor
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser PartitionIndexStatus
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"IndexStatus")
      )

instance Prelude.Hashable PartitionIndexDescriptor

instance Prelude.NFData PartitionIndexDescriptor