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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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'
  { -- | 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@, which is the default, Kinesis Data Firehose converts
    -- JSON keys to lowercase before deserializing them.
    OpenXJsonSerDe -> Maybe Bool
caseInsensitive :: Prelude.Maybe Prelude.Bool,
    -- | 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
(OpenXJsonSerDe -> OpenXJsonSerDe -> Bool)
-> (OpenXJsonSerDe -> OpenXJsonSerDe -> Bool) -> Eq OpenXJsonSerDe
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]
(Int -> ReadS OpenXJsonSerDe)
-> ReadS [OpenXJsonSerDe]
-> ReadPrec OpenXJsonSerDe
-> ReadPrec [OpenXJsonSerDe]
-> Read 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
(Int -> OpenXJsonSerDe -> ShowS)
-> (OpenXJsonSerDe -> String)
-> ([OpenXJsonSerDe] -> ShowS)
-> Show OpenXJsonSerDe
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. OpenXJsonSerDe -> Rep OpenXJsonSerDe x)
-> (forall x. Rep OpenXJsonSerDe x -> OpenXJsonSerDe)
-> Generic OpenXJsonSerDe
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:
--
-- '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@.
--
-- 'caseInsensitive', 'openXJsonSerDe_caseInsensitive' - When set to @true@, which is the default, Kinesis Data Firehose converts
-- JSON keys to lowercase before deserializing them.
--
-- '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' :: Maybe (HashMap Text Text)
-> Maybe Bool -> Maybe Bool -> OpenXJsonSerDe
OpenXJsonSerDe'
    { $sel:columnToJsonKeyMappings:OpenXJsonSerDe' :: Maybe (HashMap Text Text)
columnToJsonKeyMappings =
        Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:caseInsensitive:OpenXJsonSerDe' :: Maybe Bool
caseInsensitive = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:convertDotsInJsonKeysToUnderscores:OpenXJsonSerDe' :: Maybe Bool
convertDotsInJsonKeysToUnderscores = Maybe Bool
forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> OpenXJsonSerDe -> f OpenXJsonSerDe
openXJsonSerDe_columnToJsonKeyMappings = (OpenXJsonSerDe -> Maybe (HashMap Text Text))
-> (OpenXJsonSerDe -> Maybe (HashMap Text Text) -> OpenXJsonSerDe)
-> Lens
     OpenXJsonSerDe
     OpenXJsonSerDe
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> OpenXJsonSerDe -> f OpenXJsonSerDe)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> OpenXJsonSerDe
-> f OpenXJsonSerDe
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | 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 :: (Maybe Bool -> f (Maybe Bool))
-> OpenXJsonSerDe -> f OpenXJsonSerDe
openXJsonSerDe_caseInsensitive = (OpenXJsonSerDe -> Maybe Bool)
-> (OpenXJsonSerDe -> Maybe Bool -> OpenXJsonSerDe)
-> Lens OpenXJsonSerDe OpenXJsonSerDe (Maybe Bool) (Maybe Bool)
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)

-- | 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 :: (Maybe Bool -> f (Maybe Bool))
-> OpenXJsonSerDe -> f OpenXJsonSerDe
openXJsonSerDe_convertDotsInJsonKeysToUnderscores = (OpenXJsonSerDe -> Maybe Bool)
-> (OpenXJsonSerDe -> Maybe Bool -> OpenXJsonSerDe)
-> Lens OpenXJsonSerDe OpenXJsonSerDe (Maybe Bool) (Maybe Bool)
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 Core.FromJSON OpenXJsonSerDe where
  parseJSON :: Value -> Parser OpenXJsonSerDe
parseJSON =
    String
-> (Object -> Parser OpenXJsonSerDe)
-> Value
-> Parser OpenXJsonSerDe
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"OpenXJsonSerDe"
      ( \Object
x ->
          Maybe (HashMap Text Text)
-> Maybe Bool -> Maybe Bool -> OpenXJsonSerDe
OpenXJsonSerDe'
            (Maybe (HashMap Text Text)
 -> Maybe Bool -> Maybe Bool -> OpenXJsonSerDe)
-> Parser (Maybe (HashMap Text Text))
-> Parser (Maybe Bool -> Maybe Bool -> OpenXJsonSerDe)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ColumnToJsonKeyMappings"
                            Parser (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text) -> Parser (Maybe (HashMap Text Text))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser (Maybe Bool -> Maybe Bool -> OpenXJsonSerDe)
-> Parser (Maybe Bool) -> Parser (Maybe Bool -> OpenXJsonSerDe)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"CaseInsensitive")
            Parser (Maybe Bool -> OpenXJsonSerDe)
-> Parser (Maybe Bool) -> Parser OpenXJsonSerDe
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ConvertDotsInJsonKeysToUnderscores")
      )

instance Prelude.Hashable OpenXJsonSerDe

instance Prelude.NFData OpenXJsonSerDe

instance Core.ToJSON OpenXJsonSerDe where
  toJSON :: OpenXJsonSerDe -> Value
toJSON OpenXJsonSerDe' {Maybe Bool
Maybe (HashMap Text Text)
convertDotsInJsonKeysToUnderscores :: Maybe Bool
caseInsensitive :: Maybe Bool
columnToJsonKeyMappings :: Maybe (HashMap Text Text)
$sel:convertDotsInJsonKeysToUnderscores:OpenXJsonSerDe' :: OpenXJsonSerDe -> Maybe Bool
$sel:caseInsensitive:OpenXJsonSerDe' :: OpenXJsonSerDe -> Maybe Bool
$sel:columnToJsonKeyMappings:OpenXJsonSerDe' :: OpenXJsonSerDe -> Maybe (HashMap Text Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ColumnToJsonKeyMappings" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
columnToJsonKeyMappings,
            (Text
"CaseInsensitive" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
caseInsensitive,
            (Text
"ConvertDotsInJsonKeysToUnderscores" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
convertDotsInJsonKeysToUnderscores
          ]
      )