{-# 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.LakeFormation.Types.QueryPlanningContext
-- 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.LakeFormation.Types.QueryPlanningContext 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

-- | A structure containing information about the query plan.
--
-- /See:/ 'newQueryPlanningContext' smart constructor.
data QueryPlanningContext = QueryPlanningContext'
  { -- | The ID of the Data Catalog where the partition in question resides. If
    -- none is provided, the Amazon Web Services account ID is used by default.
    QueryPlanningContext -> Maybe Text
catalogId :: Prelude.Maybe Prelude.Text,
    -- | The time as of when to read the table contents. If not set, the most
    -- recent transaction commit time will be used. Cannot be specified along
    -- with @TransactionId@.
    QueryPlanningContext -> Maybe POSIX
queryAsOfTime :: Prelude.Maybe Data.POSIX,
    -- | A map consisting of key-value pairs.
    QueryPlanningContext -> Maybe (HashMap Text Text)
queryParameters :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The transaction ID at which to read the table contents. If this
    -- transaction is not committed, the read will be treated as part of that
    -- transaction and will see its writes. If this transaction has aborted, an
    -- error will be returned. If not set, defaults to the most recent
    -- committed transaction. Cannot be specified along with @QueryAsOfTime@.
    QueryPlanningContext -> Maybe Text
transactionId :: Prelude.Maybe Prelude.Text,
    -- | The database containing the table.
    QueryPlanningContext -> Text
databaseName :: Prelude.Text
  }
  deriving (QueryPlanningContext -> QueryPlanningContext -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: QueryPlanningContext -> QueryPlanningContext -> Bool
$c/= :: QueryPlanningContext -> QueryPlanningContext -> Bool
== :: QueryPlanningContext -> QueryPlanningContext -> Bool
$c== :: QueryPlanningContext -> QueryPlanningContext -> Bool
Prelude.Eq, ReadPrec [QueryPlanningContext]
ReadPrec QueryPlanningContext
Int -> ReadS QueryPlanningContext
ReadS [QueryPlanningContext]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [QueryPlanningContext]
$creadListPrec :: ReadPrec [QueryPlanningContext]
readPrec :: ReadPrec QueryPlanningContext
$creadPrec :: ReadPrec QueryPlanningContext
readList :: ReadS [QueryPlanningContext]
$creadList :: ReadS [QueryPlanningContext]
readsPrec :: Int -> ReadS QueryPlanningContext
$creadsPrec :: Int -> ReadS QueryPlanningContext
Prelude.Read, Int -> QueryPlanningContext -> ShowS
[QueryPlanningContext] -> ShowS
QueryPlanningContext -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [QueryPlanningContext] -> ShowS
$cshowList :: [QueryPlanningContext] -> ShowS
show :: QueryPlanningContext -> String
$cshow :: QueryPlanningContext -> String
showsPrec :: Int -> QueryPlanningContext -> ShowS
$cshowsPrec :: Int -> QueryPlanningContext -> ShowS
Prelude.Show, forall x. Rep QueryPlanningContext x -> QueryPlanningContext
forall x. QueryPlanningContext -> Rep QueryPlanningContext x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep QueryPlanningContext x -> QueryPlanningContext
$cfrom :: forall x. QueryPlanningContext -> Rep QueryPlanningContext x
Prelude.Generic)

-- |
-- Create a value of 'QueryPlanningContext' 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:
--
-- 'catalogId', 'queryPlanningContext_catalogId' - The ID of the Data Catalog where the partition in question resides. If
-- none is provided, the Amazon Web Services account ID is used by default.
--
-- 'queryAsOfTime', 'queryPlanningContext_queryAsOfTime' - The time as of when to read the table contents. If not set, the most
-- recent transaction commit time will be used. Cannot be specified along
-- with @TransactionId@.
--
-- 'queryParameters', 'queryPlanningContext_queryParameters' - A map consisting of key-value pairs.
--
-- 'transactionId', 'queryPlanningContext_transactionId' - The transaction ID at which to read the table contents. If this
-- transaction is not committed, the read will be treated as part of that
-- transaction and will see its writes. If this transaction has aborted, an
-- error will be returned. If not set, defaults to the most recent
-- committed transaction. Cannot be specified along with @QueryAsOfTime@.
--
-- 'databaseName', 'queryPlanningContext_databaseName' - The database containing the table.
newQueryPlanningContext ::
  -- | 'databaseName'
  Prelude.Text ->
  QueryPlanningContext
newQueryPlanningContext :: Text -> QueryPlanningContext
newQueryPlanningContext Text
pDatabaseName_ =
  QueryPlanningContext'
    { $sel:catalogId:QueryPlanningContext' :: Maybe Text
catalogId = forall a. Maybe a
Prelude.Nothing,
      $sel:queryAsOfTime:QueryPlanningContext' :: Maybe POSIX
queryAsOfTime = forall a. Maybe a
Prelude.Nothing,
      $sel:queryParameters:QueryPlanningContext' :: Maybe (HashMap Text Text)
queryParameters = forall a. Maybe a
Prelude.Nothing,
      $sel:transactionId:QueryPlanningContext' :: Maybe Text
transactionId = forall a. Maybe a
Prelude.Nothing,
      $sel:databaseName:QueryPlanningContext' :: Text
databaseName = Text
pDatabaseName_
    }

-- | The ID of the Data Catalog where the partition in question resides. If
-- none is provided, the Amazon Web Services account ID is used by default.
queryPlanningContext_catalogId :: Lens.Lens' QueryPlanningContext (Prelude.Maybe Prelude.Text)
queryPlanningContext_catalogId :: Lens' QueryPlanningContext (Maybe Text)
queryPlanningContext_catalogId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryPlanningContext' {Maybe Text
catalogId :: Maybe Text
$sel:catalogId:QueryPlanningContext' :: QueryPlanningContext -> Maybe Text
catalogId} -> Maybe Text
catalogId) (\s :: QueryPlanningContext
s@QueryPlanningContext' {} Maybe Text
a -> QueryPlanningContext
s {$sel:catalogId:QueryPlanningContext' :: Maybe Text
catalogId = Maybe Text
a} :: QueryPlanningContext)

-- | The time as of when to read the table contents. If not set, the most
-- recent transaction commit time will be used. Cannot be specified along
-- with @TransactionId@.
queryPlanningContext_queryAsOfTime :: Lens.Lens' QueryPlanningContext (Prelude.Maybe Prelude.UTCTime)
queryPlanningContext_queryAsOfTime :: Lens' QueryPlanningContext (Maybe UTCTime)
queryPlanningContext_queryAsOfTime = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryPlanningContext' {Maybe POSIX
queryAsOfTime :: Maybe POSIX
$sel:queryAsOfTime:QueryPlanningContext' :: QueryPlanningContext -> Maybe POSIX
queryAsOfTime} -> Maybe POSIX
queryAsOfTime) (\s :: QueryPlanningContext
s@QueryPlanningContext' {} Maybe POSIX
a -> QueryPlanningContext
s {$sel:queryAsOfTime:QueryPlanningContext' :: Maybe POSIX
queryAsOfTime = Maybe POSIX
a} :: QueryPlanningContext) 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 (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | A map consisting of key-value pairs.
queryPlanningContext_queryParameters :: Lens.Lens' QueryPlanningContext (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
queryPlanningContext_queryParameters :: Lens' QueryPlanningContext (Maybe (HashMap Text Text))
queryPlanningContext_queryParameters = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryPlanningContext' {Maybe (HashMap Text Text)
queryParameters :: Maybe (HashMap Text Text)
$sel:queryParameters:QueryPlanningContext' :: QueryPlanningContext -> Maybe (HashMap Text Text)
queryParameters} -> Maybe (HashMap Text Text)
queryParameters) (\s :: QueryPlanningContext
s@QueryPlanningContext' {} Maybe (HashMap Text Text)
a -> QueryPlanningContext
s {$sel:queryParameters:QueryPlanningContext' :: Maybe (HashMap Text Text)
queryParameters = Maybe (HashMap Text Text)
a} :: QueryPlanningContext) 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 transaction ID at which to read the table contents. If this
-- transaction is not committed, the read will be treated as part of that
-- transaction and will see its writes. If this transaction has aborted, an
-- error will be returned. If not set, defaults to the most recent
-- committed transaction. Cannot be specified along with @QueryAsOfTime@.
queryPlanningContext_transactionId :: Lens.Lens' QueryPlanningContext (Prelude.Maybe Prelude.Text)
queryPlanningContext_transactionId :: Lens' QueryPlanningContext (Maybe Text)
queryPlanningContext_transactionId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryPlanningContext' {Maybe Text
transactionId :: Maybe Text
$sel:transactionId:QueryPlanningContext' :: QueryPlanningContext -> Maybe Text
transactionId} -> Maybe Text
transactionId) (\s :: QueryPlanningContext
s@QueryPlanningContext' {} Maybe Text
a -> QueryPlanningContext
s {$sel:transactionId:QueryPlanningContext' :: Maybe Text
transactionId = Maybe Text
a} :: QueryPlanningContext)

-- | The database containing the table.
queryPlanningContext_databaseName :: Lens.Lens' QueryPlanningContext Prelude.Text
queryPlanningContext_databaseName :: Lens' QueryPlanningContext Text
queryPlanningContext_databaseName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\QueryPlanningContext' {Text
databaseName :: Text
$sel:databaseName:QueryPlanningContext' :: QueryPlanningContext -> Text
databaseName} -> Text
databaseName) (\s :: QueryPlanningContext
s@QueryPlanningContext' {} Text
a -> QueryPlanningContext
s {$sel:databaseName:QueryPlanningContext' :: Text
databaseName = Text
a} :: QueryPlanningContext)

instance Prelude.Hashable QueryPlanningContext where
  hashWithSalt :: Int -> QueryPlanningContext -> Int
hashWithSalt Int
_salt QueryPlanningContext' {Maybe Text
Maybe (HashMap Text Text)
Maybe POSIX
Text
databaseName :: Text
transactionId :: Maybe Text
queryParameters :: Maybe (HashMap Text Text)
queryAsOfTime :: Maybe POSIX
catalogId :: Maybe Text
$sel:databaseName:QueryPlanningContext' :: QueryPlanningContext -> Text
$sel:transactionId:QueryPlanningContext' :: QueryPlanningContext -> Maybe Text
$sel:queryParameters:QueryPlanningContext' :: QueryPlanningContext -> Maybe (HashMap Text Text)
$sel:queryAsOfTime:QueryPlanningContext' :: QueryPlanningContext -> Maybe POSIX
$sel:catalogId:QueryPlanningContext' :: QueryPlanningContext -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
catalogId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
queryAsOfTime
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
queryParameters
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
transactionId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
databaseName

instance Prelude.NFData QueryPlanningContext where
  rnf :: QueryPlanningContext -> ()
rnf QueryPlanningContext' {Maybe Text
Maybe (HashMap Text Text)
Maybe POSIX
Text
databaseName :: Text
transactionId :: Maybe Text
queryParameters :: Maybe (HashMap Text Text)
queryAsOfTime :: Maybe POSIX
catalogId :: Maybe Text
$sel:databaseName:QueryPlanningContext' :: QueryPlanningContext -> Text
$sel:transactionId:QueryPlanningContext' :: QueryPlanningContext -> Maybe Text
$sel:queryParameters:QueryPlanningContext' :: QueryPlanningContext -> Maybe (HashMap Text Text)
$sel:queryAsOfTime:QueryPlanningContext' :: QueryPlanningContext -> Maybe POSIX
$sel:catalogId:QueryPlanningContext' :: QueryPlanningContext -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
catalogId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
queryAsOfTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
queryParameters
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
transactionId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
databaseName

instance Data.ToJSON QueryPlanningContext where
  toJSON :: QueryPlanningContext -> Value
toJSON QueryPlanningContext' {Maybe Text
Maybe (HashMap Text Text)
Maybe POSIX
Text
databaseName :: Text
transactionId :: Maybe Text
queryParameters :: Maybe (HashMap Text Text)
queryAsOfTime :: Maybe POSIX
catalogId :: Maybe Text
$sel:databaseName:QueryPlanningContext' :: QueryPlanningContext -> Text
$sel:transactionId:QueryPlanningContext' :: QueryPlanningContext -> Maybe Text
$sel:queryParameters:QueryPlanningContext' :: QueryPlanningContext -> Maybe (HashMap Text Text)
$sel:queryAsOfTime:QueryPlanningContext' :: QueryPlanningContext -> Maybe POSIX
$sel:catalogId:QueryPlanningContext' :: QueryPlanningContext -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"CatalogId" 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
catalogId,
            (Key
"QueryAsOfTime" 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 POSIX
queryAsOfTime,
            (Key
"QueryParameters" 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 (HashMap Text Text)
queryParameters,
            (Key
"TransactionId" 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
transactionId,
            forall a. a -> Maybe a
Prelude.Just (Key
"DatabaseName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
databaseName)
          ]
      )