{-# 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.Firehose.Types.OpenXJsonSerDe
-- 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.Firehose.Types.OpenXJsonSerDe 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

-- | The OpenX SerDe. Used by Kinesis Data Firehose for deserializing data,
-- which means converting it from the JSON format in preparation for
-- serializing it to the Parquet or ORC format. This is one of two
-- deserializers you can choose, depending on which one offers the
-- functionality you need. The other option is the native Hive \/ HCatalog
-- JsonSerDe.
--
-- /See:/ 'newOpenXJsonSerDe' smart constructor.
data OpenXJsonSerDe = OpenXJsonSerDe'
  { -- | When set to @true@, which is the default, Kinesis Data Firehose converts
    -- JSON keys to lowercase before deserializing them.
    OpenXJsonSerDe -> Maybe Bool
caseInsensitive :: Prelude.Maybe Prelude.Bool,
    -- | Maps column names to JSON keys that aren\'t identical to the column
    -- names. This is useful when the JSON contains keys that are Hive
    -- keywords. For example, @timestamp@ is a Hive keyword. If you have a JSON
    -- key named @timestamp@, set this parameter to @{\"ts\": \"timestamp\"}@
    -- to map this key to a column named @ts@.
    OpenXJsonSerDe -> Maybe (HashMap Text Text)
columnToJsonKeyMappings :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | When set to @true@, specifies that the names of the keys include dots
    -- and that you want Kinesis Data Firehose to replace them with
    -- underscores. This is useful because Apache Hive does not allow dots in
    -- column names. For example, if the JSON contains a key whose name is
    -- \"a.b\", you can define the column name to be \"a_b\" when using this
    -- option.
    --
    -- The default is @false@.
    OpenXJsonSerDe -> Maybe Bool
convertDotsInJsonKeysToUnderscores :: Prelude.Maybe Prelude.Bool
  }
  deriving (OpenXJsonSerDe -> OpenXJsonSerDe -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OpenXJsonSerDe -> OpenXJsonSerDe -> Bool
$c/= :: OpenXJsonSerDe -> OpenXJsonSerDe -> Bool
== :: OpenXJsonSerDe -> OpenXJsonSerDe -> Bool
$c== :: OpenXJsonSerDe -> OpenXJsonSerDe -> Bool
Prelude.Eq, ReadPrec [OpenXJsonSerDe]
ReadPrec OpenXJsonSerDe
Int -> ReadS OpenXJsonSerDe
ReadS [OpenXJsonSerDe]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OpenXJsonSerDe]
$creadListPrec :: ReadPrec [OpenXJsonSerDe]
readPrec :: ReadPrec OpenXJsonSerDe
$creadPrec :: ReadPrec OpenXJsonSerDe
readList :: ReadS [OpenXJsonSerDe]
$creadList :: ReadS [OpenXJsonSerDe]
readsPrec :: Int -> ReadS OpenXJsonSerDe
$creadsPrec :: Int -> ReadS OpenXJsonSerDe
Prelude.Read, Int -> OpenXJsonSerDe -> ShowS
[OpenXJsonSerDe] -> ShowS
OpenXJsonSerDe -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OpenXJsonSerDe] -> ShowS
$cshowList :: [OpenXJsonSerDe] -> ShowS
show :: OpenXJsonSerDe -> String
$cshow :: OpenXJsonSerDe -> String
showsPrec :: Int -> OpenXJsonSerDe -> ShowS
$cshowsPrec :: Int -> OpenXJsonSerDe -> ShowS
Prelude.Show, forall x. Rep OpenXJsonSerDe x -> OpenXJsonSerDe
forall x. OpenXJsonSerDe -> Rep OpenXJsonSerDe x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OpenXJsonSerDe x -> OpenXJsonSerDe
$cfrom :: forall x. OpenXJsonSerDe -> Rep OpenXJsonSerDe x
Prelude.Generic)

-- |
-- Create a value of 'OpenXJsonSerDe' 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:
--
-- 'caseInsensitive', 'openXJsonSerDe_caseInsensitive' - When set to @true@, which is the default, Kinesis Data Firehose converts
-- JSON keys to lowercase before deserializing them.
--
-- 'columnToJsonKeyMappings', 'openXJsonSerDe_columnToJsonKeyMappings' - Maps column names to JSON keys that aren\'t identical to the column
-- names. This is useful when the JSON contains keys that are Hive
-- keywords. For example, @timestamp@ is a Hive keyword. If you have a JSON
-- key named @timestamp@, set this parameter to @{\"ts\": \"timestamp\"}@
-- to map this key to a column named @ts@.
--
-- 'convertDotsInJsonKeysToUnderscores', 'openXJsonSerDe_convertDotsInJsonKeysToUnderscores' - When set to @true@, specifies that the names of the keys include dots
-- and that you want Kinesis Data Firehose to replace them with
-- underscores. This is useful because Apache Hive does not allow dots in
-- column names. For example, if the JSON contains a key whose name is
-- \"a.b\", you can define the column name to be \"a_b\" when using this
-- option.
--
-- The default is @false@.
newOpenXJsonSerDe ::
  OpenXJsonSerDe
newOpenXJsonSerDe :: OpenXJsonSerDe
newOpenXJsonSerDe =
  OpenXJsonSerDe'
    { $sel:caseInsensitive:OpenXJsonSerDe' :: Maybe Bool
caseInsensitive = forall a. Maybe a
Prelude.Nothing,
      $sel:columnToJsonKeyMappings:OpenXJsonSerDe' :: Maybe (HashMap Text Text)
columnToJsonKeyMappings = forall a. Maybe a
Prelude.Nothing,
      $sel:convertDotsInJsonKeysToUnderscores:OpenXJsonSerDe' :: Maybe Bool
convertDotsInJsonKeysToUnderscores = forall a. Maybe a
Prelude.Nothing
    }

-- | When set to @true@, which is the default, Kinesis Data Firehose converts
-- JSON keys to lowercase before deserializing them.
openXJsonSerDe_caseInsensitive :: Lens.Lens' OpenXJsonSerDe (Prelude.Maybe Prelude.Bool)
openXJsonSerDe_caseInsensitive :: Lens' OpenXJsonSerDe (Maybe Bool)
openXJsonSerDe_caseInsensitive = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OpenXJsonSerDe' {Maybe Bool
caseInsensitive :: Maybe Bool
$sel:caseInsensitive:OpenXJsonSerDe' :: OpenXJsonSerDe -> Maybe Bool
caseInsensitive} -> Maybe Bool
caseInsensitive) (\s :: OpenXJsonSerDe
s@OpenXJsonSerDe' {} Maybe Bool
a -> OpenXJsonSerDe
s {$sel:caseInsensitive:OpenXJsonSerDe' :: Maybe Bool
caseInsensitive = Maybe Bool
a} :: OpenXJsonSerDe)

-- | Maps column names to JSON keys that aren\'t identical to the column
-- names. This is useful when the JSON contains keys that are Hive
-- keywords. For example, @timestamp@ is a Hive keyword. If you have a JSON
-- key named @timestamp@, set this parameter to @{\"ts\": \"timestamp\"}@
-- to map this key to a column named @ts@.
openXJsonSerDe_columnToJsonKeyMappings :: Lens.Lens' OpenXJsonSerDe (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
openXJsonSerDe_columnToJsonKeyMappings :: Lens' OpenXJsonSerDe (Maybe (HashMap Text Text))
openXJsonSerDe_columnToJsonKeyMappings = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OpenXJsonSerDe' {Maybe (HashMap Text Text)
columnToJsonKeyMappings :: Maybe (HashMap Text Text)
$sel:columnToJsonKeyMappings:OpenXJsonSerDe' :: OpenXJsonSerDe -> Maybe (HashMap Text Text)
columnToJsonKeyMappings} -> Maybe (HashMap Text Text)
columnToJsonKeyMappings) (\s :: OpenXJsonSerDe
s@OpenXJsonSerDe' {} Maybe (HashMap Text Text)
a -> OpenXJsonSerDe
s {$sel:columnToJsonKeyMappings:OpenXJsonSerDe' :: Maybe (HashMap Text Text)
columnToJsonKeyMappings = Maybe (HashMap Text Text)
a} :: OpenXJsonSerDe) 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

-- | When set to @true@, specifies that the names of the keys include dots
-- and that you want Kinesis Data Firehose to replace them with
-- underscores. This is useful because Apache Hive does not allow dots in
-- column names. For example, if the JSON contains a key whose name is
-- \"a.b\", you can define the column name to be \"a_b\" when using this
-- option.
--
-- The default is @false@.
openXJsonSerDe_convertDotsInJsonKeysToUnderscores :: Lens.Lens' OpenXJsonSerDe (Prelude.Maybe Prelude.Bool)
openXJsonSerDe_convertDotsInJsonKeysToUnderscores :: Lens' OpenXJsonSerDe (Maybe Bool)
openXJsonSerDe_convertDotsInJsonKeysToUnderscores = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OpenXJsonSerDe' {Maybe Bool
convertDotsInJsonKeysToUnderscores :: Maybe Bool
$sel:convertDotsInJsonKeysToUnderscores:OpenXJsonSerDe' :: OpenXJsonSerDe -> Maybe Bool
convertDotsInJsonKeysToUnderscores} -> Maybe Bool
convertDotsInJsonKeysToUnderscores) (\s :: OpenXJsonSerDe
s@OpenXJsonSerDe' {} Maybe Bool
a -> OpenXJsonSerDe
s {$sel:convertDotsInJsonKeysToUnderscores:OpenXJsonSerDe' :: Maybe Bool
convertDotsInJsonKeysToUnderscores = Maybe Bool
a} :: OpenXJsonSerDe)

instance Data.FromJSON OpenXJsonSerDe where
  parseJSON :: Value -> Parser OpenXJsonSerDe
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"OpenXJsonSerDe"
      ( \Object
x ->
          Maybe Bool
-> Maybe (HashMap Text Text) -> Maybe Bool -> OpenXJsonSerDe
OpenXJsonSerDe'
            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
"CaseInsensitive")
            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
"ColumnToJsonKeyMappings"
                            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
"ConvertDotsInJsonKeysToUnderscores")
      )

instance Prelude.Hashable OpenXJsonSerDe where
  hashWithSalt :: Int -> OpenXJsonSerDe -> Int
hashWithSalt Int
_salt OpenXJsonSerDe' {Maybe Bool
Maybe (HashMap Text Text)
convertDotsInJsonKeysToUnderscores :: Maybe Bool
columnToJsonKeyMappings :: Maybe (HashMap Text Text)
caseInsensitive :: Maybe Bool
$sel:convertDotsInJsonKeysToUnderscores:OpenXJsonSerDe' :: OpenXJsonSerDe -> Maybe Bool
$sel:columnToJsonKeyMappings:OpenXJsonSerDe' :: OpenXJsonSerDe -> Maybe (HashMap Text Text)
$sel:caseInsensitive:OpenXJsonSerDe' :: OpenXJsonSerDe -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
caseInsensitive
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
columnToJsonKeyMappings
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
convertDotsInJsonKeysToUnderscores

instance Prelude.NFData OpenXJsonSerDe where
  rnf :: OpenXJsonSerDe -> ()
rnf OpenXJsonSerDe' {Maybe Bool
Maybe (HashMap Text Text)
convertDotsInJsonKeysToUnderscores :: Maybe Bool
columnToJsonKeyMappings :: Maybe (HashMap Text Text)
caseInsensitive :: Maybe Bool
$sel:convertDotsInJsonKeysToUnderscores:OpenXJsonSerDe' :: OpenXJsonSerDe -> Maybe Bool
$sel:columnToJsonKeyMappings:OpenXJsonSerDe' :: OpenXJsonSerDe -> Maybe (HashMap Text Text)
$sel:caseInsensitive:OpenXJsonSerDe' :: OpenXJsonSerDe -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
caseInsensitive
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
columnToJsonKeyMappings
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
convertDotsInJsonKeysToUnderscores

instance Data.ToJSON OpenXJsonSerDe where
  toJSON :: OpenXJsonSerDe -> Value
toJSON OpenXJsonSerDe' {Maybe Bool
Maybe (HashMap Text Text)
convertDotsInJsonKeysToUnderscores :: Maybe Bool
columnToJsonKeyMappings :: Maybe (HashMap Text Text)
caseInsensitive :: Maybe Bool
$sel:convertDotsInJsonKeysToUnderscores:OpenXJsonSerDe' :: OpenXJsonSerDe -> Maybe Bool
$sel:columnToJsonKeyMappings:OpenXJsonSerDe' :: OpenXJsonSerDe -> Maybe (HashMap Text Text)
$sel:caseInsensitive:OpenXJsonSerDe' :: OpenXJsonSerDe -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"CaseInsensitive" 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 Bool
caseInsensitive,
            (Key
"ColumnToJsonKeyMappings" 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)
columnToJsonKeyMappings,
            (Key
"ConvertDotsInJsonKeysToUnderscores" 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 Bool
convertDotsInJsonKeysToUnderscores
          ]
      )