{-# 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-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.PartitionIndexDescriptor 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.BackfillError
import Amazonka.Glue.Types.KeySchemaElement
import Amazonka.Glue.Types.PartitionIndexStatus
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
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]
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
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.
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'
      { $sel:backfillErrors:PartitionIndexDescriptor' :: Maybe [BackfillError]
backfillErrors =
          forall a. Maybe a
Prelude.Nothing,
        $sel:indexName:PartitionIndexDescriptor' :: Text
indexName = Text
pIndexName_,
        $sel:keys:PartitionIndexDescriptor' :: NonEmpty KeySchemaElement
keys = 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 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 :: Lens' PartitionIndexDescriptor (Maybe [BackfillError])
partitionIndexDescriptor_backfillErrors = 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) 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 partition index.
partitionIndexDescriptor_indexName :: Lens.Lens' PartitionIndexDescriptor Prelude.Text
partitionIndexDescriptor_indexName :: Lens' PartitionIndexDescriptor Text
partitionIndexDescriptor_indexName = 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 :: Lens' PartitionIndexDescriptor (NonEmpty KeySchemaElement)
partitionIndexDescriptor_keys = 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) 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 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 :: Lens' PartitionIndexDescriptor PartitionIndexStatus
partitionIndexDescriptor_indexStatus = 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 Data.FromJSON PartitionIndexDescriptor where
  parseJSON :: Value -> Parser PartitionIndexDescriptor
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PartitionIndexDescriptor"
      ( \Object
x ->
          Maybe [BackfillError]
-> Text
-> NonEmpty KeySchemaElement
-> PartitionIndexStatus
-> PartitionIndexDescriptor
PartitionIndexDescriptor'
            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
"BackfillErrors" 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
"IndexName")
            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
"Keys")
            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
"IndexStatus")
      )

instance Prelude.Hashable PartitionIndexDescriptor where
  hashWithSalt :: Int -> PartitionIndexDescriptor -> Int
hashWithSalt Int
_salt PartitionIndexDescriptor' {Maybe [BackfillError]
NonEmpty KeySchemaElement
Text
PartitionIndexStatus
indexStatus :: PartitionIndexStatus
keys :: NonEmpty KeySchemaElement
indexName :: Text
backfillErrors :: Maybe [BackfillError]
$sel:indexStatus:PartitionIndexDescriptor' :: PartitionIndexDescriptor -> PartitionIndexStatus
$sel:keys:PartitionIndexDescriptor' :: PartitionIndexDescriptor -> NonEmpty KeySchemaElement
$sel:indexName:PartitionIndexDescriptor' :: PartitionIndexDescriptor -> Text
$sel:backfillErrors:PartitionIndexDescriptor' :: PartitionIndexDescriptor -> Maybe [BackfillError]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [BackfillError]
backfillErrors
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
indexName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty KeySchemaElement
keys
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` PartitionIndexStatus
indexStatus

instance Prelude.NFData PartitionIndexDescriptor where
  rnf :: PartitionIndexDescriptor -> ()
rnf PartitionIndexDescriptor' {Maybe [BackfillError]
NonEmpty KeySchemaElement
Text
PartitionIndexStatus
indexStatus :: PartitionIndexStatus
keys :: NonEmpty KeySchemaElement
indexName :: Text
backfillErrors :: Maybe [BackfillError]
$sel:indexStatus:PartitionIndexDescriptor' :: PartitionIndexDescriptor -> PartitionIndexStatus
$sel:keys:PartitionIndexDescriptor' :: PartitionIndexDescriptor -> NonEmpty KeySchemaElement
$sel:indexName:PartitionIndexDescriptor' :: PartitionIndexDescriptor -> Text
$sel:backfillErrors:PartitionIndexDescriptor' :: PartitionIndexDescriptor -> Maybe [BackfillError]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [BackfillError]
backfillErrors
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
indexName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty KeySchemaElement
keys
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf PartitionIndexStatus
indexStatus