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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | 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.
--
-- /See:/ 'newHiveJsonSerDe' smart constructor.
data HiveJsonSerDe = HiveJsonSerDe'
  { -- | Indicates how you want Kinesis Data Firehose to parse the date and
    -- timestamps that may be present in your input data JSON. To specify these
    -- format strings, follow the pattern syntax of JodaTime\'s DateTimeFormat
    -- format strings. For more information, see
    -- <https://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html Class DateTimeFormat>.
    -- You can also use the special value @millis@ to parse timestamps in epoch
    -- milliseconds. If you don\'t specify a format, Kinesis Data Firehose uses
    -- @java.sql.Timestamp::valueOf@ by default.
    HiveJsonSerDe -> Maybe [Text]
timestampFormats :: Prelude.Maybe [Prelude.Text]
  }
  deriving (HiveJsonSerDe -> HiveJsonSerDe -> Bool
(HiveJsonSerDe -> HiveJsonSerDe -> Bool)
-> (HiveJsonSerDe -> HiveJsonSerDe -> Bool) -> Eq HiveJsonSerDe
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HiveJsonSerDe -> HiveJsonSerDe -> Bool
$c/= :: HiveJsonSerDe -> HiveJsonSerDe -> Bool
== :: HiveJsonSerDe -> HiveJsonSerDe -> Bool
$c== :: HiveJsonSerDe -> HiveJsonSerDe -> Bool
Prelude.Eq, ReadPrec [HiveJsonSerDe]
ReadPrec HiveJsonSerDe
Int -> ReadS HiveJsonSerDe
ReadS [HiveJsonSerDe]
(Int -> ReadS HiveJsonSerDe)
-> ReadS [HiveJsonSerDe]
-> ReadPrec HiveJsonSerDe
-> ReadPrec [HiveJsonSerDe]
-> Read HiveJsonSerDe
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HiveJsonSerDe]
$creadListPrec :: ReadPrec [HiveJsonSerDe]
readPrec :: ReadPrec HiveJsonSerDe
$creadPrec :: ReadPrec HiveJsonSerDe
readList :: ReadS [HiveJsonSerDe]
$creadList :: ReadS [HiveJsonSerDe]
readsPrec :: Int -> ReadS HiveJsonSerDe
$creadsPrec :: Int -> ReadS HiveJsonSerDe
Prelude.Read, Int -> HiveJsonSerDe -> ShowS
[HiveJsonSerDe] -> ShowS
HiveJsonSerDe -> String
(Int -> HiveJsonSerDe -> ShowS)
-> (HiveJsonSerDe -> String)
-> ([HiveJsonSerDe] -> ShowS)
-> Show HiveJsonSerDe
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HiveJsonSerDe] -> ShowS
$cshowList :: [HiveJsonSerDe] -> ShowS
show :: HiveJsonSerDe -> String
$cshow :: HiveJsonSerDe -> String
showsPrec :: Int -> HiveJsonSerDe -> ShowS
$cshowsPrec :: Int -> HiveJsonSerDe -> ShowS
Prelude.Show, (forall x. HiveJsonSerDe -> Rep HiveJsonSerDe x)
-> (forall x. Rep HiveJsonSerDe x -> HiveJsonSerDe)
-> Generic HiveJsonSerDe
forall x. Rep HiveJsonSerDe x -> HiveJsonSerDe
forall x. HiveJsonSerDe -> Rep HiveJsonSerDe x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HiveJsonSerDe x -> HiveJsonSerDe
$cfrom :: forall x. HiveJsonSerDe -> Rep HiveJsonSerDe x
Prelude.Generic)

-- |
-- Create a value of 'HiveJsonSerDe' 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:
--
-- 'timestampFormats', 'hiveJsonSerDe_timestampFormats' - Indicates how you want Kinesis Data Firehose to parse the date and
-- timestamps that may be present in your input data JSON. To specify these
-- format strings, follow the pattern syntax of JodaTime\'s DateTimeFormat
-- format strings. For more information, see
-- <https://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html Class DateTimeFormat>.
-- You can also use the special value @millis@ to parse timestamps in epoch
-- milliseconds. If you don\'t specify a format, Kinesis Data Firehose uses
-- @java.sql.Timestamp::valueOf@ by default.
newHiveJsonSerDe ::
  HiveJsonSerDe
newHiveJsonSerDe :: HiveJsonSerDe
newHiveJsonSerDe =
  HiveJsonSerDe' :: Maybe [Text] -> HiveJsonSerDe
HiveJsonSerDe' {$sel:timestampFormats:HiveJsonSerDe' :: Maybe [Text]
timestampFormats = Maybe [Text]
forall a. Maybe a
Prelude.Nothing}

-- | Indicates how you want Kinesis Data Firehose to parse the date and
-- timestamps that may be present in your input data JSON. To specify these
-- format strings, follow the pattern syntax of JodaTime\'s DateTimeFormat
-- format strings. For more information, see
-- <https://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html Class DateTimeFormat>.
-- You can also use the special value @millis@ to parse timestamps in epoch
-- milliseconds. If you don\'t specify a format, Kinesis Data Firehose uses
-- @java.sql.Timestamp::valueOf@ by default.
hiveJsonSerDe_timestampFormats :: Lens.Lens' HiveJsonSerDe (Prelude.Maybe [Prelude.Text])
hiveJsonSerDe_timestampFormats :: (Maybe [Text] -> f (Maybe [Text]))
-> HiveJsonSerDe -> f HiveJsonSerDe
hiveJsonSerDe_timestampFormats = (HiveJsonSerDe -> Maybe [Text])
-> (HiveJsonSerDe -> Maybe [Text] -> HiveJsonSerDe)
-> Lens HiveJsonSerDe HiveJsonSerDe (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HiveJsonSerDe' {Maybe [Text]
timestampFormats :: Maybe [Text]
$sel:timestampFormats:HiveJsonSerDe' :: HiveJsonSerDe -> Maybe [Text]
timestampFormats} -> Maybe [Text]
timestampFormats) (\s :: HiveJsonSerDe
s@HiveJsonSerDe' {} Maybe [Text]
a -> HiveJsonSerDe
s {$sel:timestampFormats:HiveJsonSerDe' :: Maybe [Text]
timestampFormats = Maybe [Text]
a} :: HiveJsonSerDe) ((Maybe [Text] -> f (Maybe [Text]))
 -> HiveJsonSerDe -> f HiveJsonSerDe)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> HiveJsonSerDe
-> f HiveJsonSerDe
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [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 [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON HiveJsonSerDe where
  parseJSON :: Value -> Parser HiveJsonSerDe
parseJSON =
    String
-> (Object -> Parser HiveJsonSerDe)
-> Value
-> Parser HiveJsonSerDe
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"HiveJsonSerDe"
      ( \Object
x ->
          Maybe [Text] -> HiveJsonSerDe
HiveJsonSerDe'
            (Maybe [Text] -> HiveJsonSerDe)
-> Parser (Maybe [Text]) -> Parser HiveJsonSerDe
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"TimestampFormats"
                            Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable HiveJsonSerDe

instance Prelude.NFData HiveJsonSerDe

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