{-# 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.Glue.Types.SplitFields
-- 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.Glue.Types.SplitFields 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

-- | Specifies a transform that splits data property keys into two
-- @DynamicFrames@. The output is a collection of @DynamicFrames@: one with
-- selected data property keys, and one with the remaining data property
-- keys.
--
-- /See:/ 'newSplitFields' smart constructor.
data SplitFields = SplitFields'
  { -- | The name of the transform node.
    SplitFields -> Text
name :: Prelude.Text,
    -- | The data inputs identified by their node names.
    SplitFields -> NonEmpty Text
inputs :: Prelude.NonEmpty Prelude.Text,
    -- | A JSON path to a variable in the data structure.
    SplitFields -> [[Text]]
paths :: [[Prelude.Text]]
  }
  deriving (SplitFields -> SplitFields -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SplitFields -> SplitFields -> Bool
$c/= :: SplitFields -> SplitFields -> Bool
== :: SplitFields -> SplitFields -> Bool
$c== :: SplitFields -> SplitFields -> Bool
Prelude.Eq, ReadPrec [SplitFields]
ReadPrec SplitFields
Int -> ReadS SplitFields
ReadS [SplitFields]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SplitFields]
$creadListPrec :: ReadPrec [SplitFields]
readPrec :: ReadPrec SplitFields
$creadPrec :: ReadPrec SplitFields
readList :: ReadS [SplitFields]
$creadList :: ReadS [SplitFields]
readsPrec :: Int -> ReadS SplitFields
$creadsPrec :: Int -> ReadS SplitFields
Prelude.Read, Int -> SplitFields -> ShowS
[SplitFields] -> ShowS
SplitFields -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SplitFields] -> ShowS
$cshowList :: [SplitFields] -> ShowS
show :: SplitFields -> String
$cshow :: SplitFields -> String
showsPrec :: Int -> SplitFields -> ShowS
$cshowsPrec :: Int -> SplitFields -> ShowS
Prelude.Show, forall x. Rep SplitFields x -> SplitFields
forall x. SplitFields -> Rep SplitFields x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SplitFields x -> SplitFields
$cfrom :: forall x. SplitFields -> Rep SplitFields x
Prelude.Generic)

-- |
-- Create a value of 'SplitFields' 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:
--
-- 'name', 'splitFields_name' - The name of the transform node.
--
-- 'inputs', 'splitFields_inputs' - The data inputs identified by their node names.
--
-- 'paths', 'splitFields_paths' - A JSON path to a variable in the data structure.
newSplitFields ::
  -- | 'name'
  Prelude.Text ->
  -- | 'inputs'
  Prelude.NonEmpty Prelude.Text ->
  SplitFields
newSplitFields :: Text -> NonEmpty Text -> SplitFields
newSplitFields Text
pName_ NonEmpty Text
pInputs_ =
  SplitFields'
    { $sel:name:SplitFields' :: Text
name = Text
pName_,
      $sel:inputs:SplitFields' :: NonEmpty Text
inputs = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pInputs_,
      $sel:paths:SplitFields' :: [[Text]]
paths = forall a. Monoid a => a
Prelude.mempty
    }

-- | The name of the transform node.
splitFields_name :: Lens.Lens' SplitFields Prelude.Text
splitFields_name :: Lens' SplitFields Text
splitFields_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SplitFields' {Text
name :: Text
$sel:name:SplitFields' :: SplitFields -> Text
name} -> Text
name) (\s :: SplitFields
s@SplitFields' {} Text
a -> SplitFields
s {$sel:name:SplitFields' :: Text
name = Text
a} :: SplitFields)

-- | The data inputs identified by their node names.
splitFields_inputs :: Lens.Lens' SplitFields (Prelude.NonEmpty Prelude.Text)
splitFields_inputs :: Lens' SplitFields (NonEmpty Text)
splitFields_inputs = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SplitFields' {NonEmpty Text
inputs :: NonEmpty Text
$sel:inputs:SplitFields' :: SplitFields -> NonEmpty Text
inputs} -> NonEmpty Text
inputs) (\s :: SplitFields
s@SplitFields' {} NonEmpty Text
a -> SplitFields
s {$sel:inputs:SplitFields' :: NonEmpty Text
inputs = NonEmpty Text
a} :: SplitFields) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A JSON path to a variable in the data structure.
splitFields_paths :: Lens.Lens' SplitFields [[Prelude.Text]]
splitFields_paths :: Lens' SplitFields [[Text]]
splitFields_paths = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SplitFields' {[[Text]]
paths :: [[Text]]
$sel:paths:SplitFields' :: SplitFields -> [[Text]]
paths} -> [[Text]]
paths) (\s :: SplitFields
s@SplitFields' {} [[Text]]
a -> SplitFields
s {$sel:paths:SplitFields' :: [[Text]]
paths = [[Text]]
a} :: SplitFields) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON SplitFields where
  parseJSON :: Value -> Parser SplitFields
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"SplitFields"
      ( \Object
x ->
          Text -> NonEmpty Text -> [[Text]] -> SplitFields
SplitFields'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Name")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Inputs")
            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
"Paths" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable SplitFields where
  hashWithSalt :: Int -> SplitFields -> Int
hashWithSalt Int
_salt SplitFields' {[[Text]]
NonEmpty Text
Text
paths :: [[Text]]
inputs :: NonEmpty Text
name :: Text
$sel:paths:SplitFields' :: SplitFields -> [[Text]]
$sel:inputs:SplitFields' :: SplitFields -> NonEmpty Text
$sel:name:SplitFields' :: SplitFields -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
inputs
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [[Text]]
paths

instance Prelude.NFData SplitFields where
  rnf :: SplitFields -> ()
rnf SplitFields' {[[Text]]
NonEmpty Text
Text
paths :: [[Text]]
inputs :: NonEmpty Text
name :: Text
$sel:paths:SplitFields' :: SplitFields -> [[Text]]
$sel:inputs:SplitFields' :: SplitFields -> NonEmpty Text
$sel:name:SplitFields' :: SplitFields -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Text
inputs
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [[Text]]
paths

instance Data.ToJSON SplitFields where
  toJSON :: SplitFields -> Value
toJSON SplitFields' {[[Text]]
NonEmpty Text
Text
paths :: [[Text]]
inputs :: NonEmpty Text
name :: Text
$sel:paths:SplitFields' :: SplitFields -> [[Text]]
$sel:inputs:SplitFields' :: SplitFields -> NonEmpty Text
$sel:name:SplitFields' :: SplitFields -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"Inputs" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
inputs),
            forall a. a -> Maybe a
Prelude.Just (Key
"Paths" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [[Text]]
paths)
          ]
      )