{-# 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.Deserializer
-- 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.Deserializer where

import qualified Amazonka.Core as Core
import Amazonka.Firehose.Types.HiveJsonSerDe
import Amazonka.Firehose.Types.OpenXJsonSerDe
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The deserializer you want Kinesis Data Firehose to use for converting
-- the input data from JSON. Kinesis Data Firehose then serializes the data
-- to its final format using the Serializer. Kinesis Data Firehose supports
-- two types of deserializers: the
-- <https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-JSON Apache Hive JSON SerDe>
-- and the <https://github.com/rcongiu/Hive-JSON-Serde OpenX JSON SerDe>.
--
-- /See:/ 'newDeserializer' smart constructor.
data Deserializer = Deserializer'
  { -- | 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.
    Deserializer -> Maybe OpenXJsonSerDe
openXJsonSerDe :: Prelude.Maybe OpenXJsonSerDe,
    -- | The native Hive \/ HCatalog JsonSerDe. 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 OpenX SerDe.
    Deserializer -> Maybe HiveJsonSerDe
hiveJsonSerDe :: Prelude.Maybe HiveJsonSerDe
  }
  deriving (Deserializer -> Deserializer -> Bool
(Deserializer -> Deserializer -> Bool)
-> (Deserializer -> Deserializer -> Bool) -> Eq Deserializer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Deserializer -> Deserializer -> Bool
$c/= :: Deserializer -> Deserializer -> Bool
== :: Deserializer -> Deserializer -> Bool
$c== :: Deserializer -> Deserializer -> Bool
Prelude.Eq, ReadPrec [Deserializer]
ReadPrec Deserializer
Int -> ReadS Deserializer
ReadS [Deserializer]
(Int -> ReadS Deserializer)
-> ReadS [Deserializer]
-> ReadPrec Deserializer
-> ReadPrec [Deserializer]
-> Read Deserializer
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Deserializer]
$creadListPrec :: ReadPrec [Deserializer]
readPrec :: ReadPrec Deserializer
$creadPrec :: ReadPrec Deserializer
readList :: ReadS [Deserializer]
$creadList :: ReadS [Deserializer]
readsPrec :: Int -> ReadS Deserializer
$creadsPrec :: Int -> ReadS Deserializer
Prelude.Read, Int -> Deserializer -> ShowS
[Deserializer] -> ShowS
Deserializer -> String
(Int -> Deserializer -> ShowS)
-> (Deserializer -> String)
-> ([Deserializer] -> ShowS)
-> Show Deserializer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Deserializer] -> ShowS
$cshowList :: [Deserializer] -> ShowS
show :: Deserializer -> String
$cshow :: Deserializer -> String
showsPrec :: Int -> Deserializer -> ShowS
$cshowsPrec :: Int -> Deserializer -> ShowS
Prelude.Show, (forall x. Deserializer -> Rep Deserializer x)
-> (forall x. Rep Deserializer x -> Deserializer)
-> Generic Deserializer
forall x. Rep Deserializer x -> Deserializer
forall x. Deserializer -> Rep Deserializer x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Deserializer x -> Deserializer
$cfrom :: forall x. Deserializer -> Rep Deserializer x
Prelude.Generic)

-- |
-- Create a value of 'Deserializer' 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:
--
-- 'openXJsonSerDe', 'deserializer_openXJsonSerDe' - 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.
--
-- 'hiveJsonSerDe', 'deserializer_hiveJsonSerDe' - The native Hive \/ HCatalog JsonSerDe. 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 OpenX SerDe.
newDeserializer ::
  Deserializer
newDeserializer :: Deserializer
newDeserializer =
  Deserializer' :: Maybe OpenXJsonSerDe -> Maybe HiveJsonSerDe -> Deserializer
Deserializer'
    { $sel:openXJsonSerDe:Deserializer' :: Maybe OpenXJsonSerDe
openXJsonSerDe = Maybe OpenXJsonSerDe
forall a. Maybe a
Prelude.Nothing,
      $sel:hiveJsonSerDe:Deserializer' :: Maybe HiveJsonSerDe
hiveJsonSerDe = Maybe HiveJsonSerDe
forall a. Maybe a
Prelude.Nothing
    }

-- | 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.
deserializer_openXJsonSerDe :: Lens.Lens' Deserializer (Prelude.Maybe OpenXJsonSerDe)
deserializer_openXJsonSerDe :: (Maybe OpenXJsonSerDe -> f (Maybe OpenXJsonSerDe))
-> Deserializer -> f Deserializer
deserializer_openXJsonSerDe = (Deserializer -> Maybe OpenXJsonSerDe)
-> (Deserializer -> Maybe OpenXJsonSerDe -> Deserializer)
-> Lens
     Deserializer
     Deserializer
     (Maybe OpenXJsonSerDe)
     (Maybe OpenXJsonSerDe)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Deserializer' {Maybe OpenXJsonSerDe
openXJsonSerDe :: Maybe OpenXJsonSerDe
$sel:openXJsonSerDe:Deserializer' :: Deserializer -> Maybe OpenXJsonSerDe
openXJsonSerDe} -> Maybe OpenXJsonSerDe
openXJsonSerDe) (\s :: Deserializer
s@Deserializer' {} Maybe OpenXJsonSerDe
a -> Deserializer
s {$sel:openXJsonSerDe:Deserializer' :: Maybe OpenXJsonSerDe
openXJsonSerDe = Maybe OpenXJsonSerDe
a} :: Deserializer)

-- | The native Hive \/ HCatalog JsonSerDe. 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 OpenX SerDe.
deserializer_hiveJsonSerDe :: Lens.Lens' Deserializer (Prelude.Maybe HiveJsonSerDe)
deserializer_hiveJsonSerDe :: (Maybe HiveJsonSerDe -> f (Maybe HiveJsonSerDe))
-> Deserializer -> f Deserializer
deserializer_hiveJsonSerDe = (Deserializer -> Maybe HiveJsonSerDe)
-> (Deserializer -> Maybe HiveJsonSerDe -> Deserializer)
-> Lens
     Deserializer
     Deserializer
     (Maybe HiveJsonSerDe)
     (Maybe HiveJsonSerDe)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Deserializer' {Maybe HiveJsonSerDe
hiveJsonSerDe :: Maybe HiveJsonSerDe
$sel:hiveJsonSerDe:Deserializer' :: Deserializer -> Maybe HiveJsonSerDe
hiveJsonSerDe} -> Maybe HiveJsonSerDe
hiveJsonSerDe) (\s :: Deserializer
s@Deserializer' {} Maybe HiveJsonSerDe
a -> Deserializer
s {$sel:hiveJsonSerDe:Deserializer' :: Maybe HiveJsonSerDe
hiveJsonSerDe = Maybe HiveJsonSerDe
a} :: Deserializer)

instance Core.FromJSON Deserializer where
  parseJSON :: Value -> Parser Deserializer
parseJSON =
    String
-> (Object -> Parser Deserializer) -> Value -> Parser Deserializer
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Deserializer"
      ( \Object
x ->
          Maybe OpenXJsonSerDe -> Maybe HiveJsonSerDe -> Deserializer
Deserializer'
            (Maybe OpenXJsonSerDe -> Maybe HiveJsonSerDe -> Deserializer)
-> Parser (Maybe OpenXJsonSerDe)
-> Parser (Maybe HiveJsonSerDe -> Deserializer)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe OpenXJsonSerDe)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"OpenXJsonSerDe")
            Parser (Maybe HiveJsonSerDe -> Deserializer)
-> Parser (Maybe HiveJsonSerDe) -> Parser Deserializer
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe HiveJsonSerDe)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"HiveJsonSerDe")
      )

instance Prelude.Hashable Deserializer

instance Prelude.NFData Deserializer

instance Core.ToJSON Deserializer where
  toJSON :: Deserializer -> Value
toJSON Deserializer' {Maybe HiveJsonSerDe
Maybe OpenXJsonSerDe
hiveJsonSerDe :: Maybe HiveJsonSerDe
openXJsonSerDe :: Maybe OpenXJsonSerDe
$sel:hiveJsonSerDe:Deserializer' :: Deserializer -> Maybe HiveJsonSerDe
$sel:openXJsonSerDe:Deserializer' :: Deserializer -> Maybe OpenXJsonSerDe
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"OpenXJsonSerDe" Text -> OpenXJsonSerDe -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (OpenXJsonSerDe -> Pair) -> Maybe OpenXJsonSerDe -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe OpenXJsonSerDe
openXJsonSerDe,
            (Text
"HiveJsonSerDe" Text -> HiveJsonSerDe -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HiveJsonSerDe -> Pair) -> Maybe HiveJsonSerDe -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe HiveJsonSerDe
hiveJsonSerDe
          ]
      )