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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Glue.Types.JoinColumn
import Amazonka.Glue.Types.JoinType
import qualified Amazonka.Prelude as Prelude

-- | Specifies a transform that joins two datasets into one dataset using a
-- comparison phrase on the specified data property keys. You can use
-- inner, outer, left, right, left semi, and left anti joins.
--
-- /See:/ 'newJoin' smart constructor.
data Join = Join'
  { -- | The name of the transform node.
    Join -> Text
name :: Prelude.Text,
    -- | The data inputs identified by their node names.
    Join -> NonEmpty Text
inputs :: Prelude.NonEmpty Prelude.Text,
    -- | Specifies the type of join to be performed on the datasets.
    Join -> JoinType
joinType :: JoinType,
    -- | A list of the two columns to be joined.
    Join -> NonEmpty JoinColumn
columns :: Prelude.NonEmpty JoinColumn
  }
  deriving (Join -> Join -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Join -> Join -> Bool
$c/= :: Join -> Join -> Bool
== :: Join -> Join -> Bool
$c== :: Join -> Join -> Bool
Prelude.Eq, ReadPrec [Join]
ReadPrec Join
Int -> ReadS Join
ReadS [Join]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Join]
$creadListPrec :: ReadPrec [Join]
readPrec :: ReadPrec Join
$creadPrec :: ReadPrec Join
readList :: ReadS [Join]
$creadList :: ReadS [Join]
readsPrec :: Int -> ReadS Join
$creadsPrec :: Int -> ReadS Join
Prelude.Read, Int -> Join -> ShowS
[Join] -> ShowS
Join -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Join] -> ShowS
$cshowList :: [Join] -> ShowS
show :: Join -> String
$cshow :: Join -> String
showsPrec :: Int -> Join -> ShowS
$cshowsPrec :: Int -> Join -> ShowS
Prelude.Show, forall x. Rep Join x -> Join
forall x. Join -> Rep Join x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Join x -> Join
$cfrom :: forall x. Join -> Rep Join x
Prelude.Generic)

-- |
-- Create a value of 'Join' 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', 'join_name' - The name of the transform node.
--
-- 'inputs', 'join_inputs' - The data inputs identified by their node names.
--
-- 'joinType', 'join_joinType' - Specifies the type of join to be performed on the datasets.
--
-- 'columns', 'join_columns' - A list of the two columns to be joined.
newJoin ::
  -- | 'name'
  Prelude.Text ->
  -- | 'inputs'
  Prelude.NonEmpty Prelude.Text ->
  -- | 'joinType'
  JoinType ->
  -- | 'columns'
  Prelude.NonEmpty JoinColumn ->
  Join
newJoin :: Text -> NonEmpty Text -> JoinType -> NonEmpty JoinColumn -> Join
newJoin Text
pName_ NonEmpty Text
pInputs_ JoinType
pJoinType_ NonEmpty JoinColumn
pColumns_ =
  Join'
    { $sel:name:Join' :: Text
name = Text
pName_,
      $sel:inputs:Join' :: 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:joinType:Join' :: JoinType
joinType = JoinType
pJoinType_,
      $sel:columns:Join' :: NonEmpty JoinColumn
columns = 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 JoinColumn
pColumns_
    }

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

-- | The data inputs identified by their node names.
join_inputs :: Lens.Lens' Join (Prelude.NonEmpty Prelude.Text)
join_inputs :: Lens' Join (NonEmpty Text)
join_inputs = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Join' {NonEmpty Text
inputs :: NonEmpty Text
$sel:inputs:Join' :: Join -> NonEmpty Text
inputs} -> NonEmpty Text
inputs) (\s :: Join
s@Join' {} NonEmpty Text
a -> Join
s {$sel:inputs:Join' :: NonEmpty Text
inputs = NonEmpty Text
a} :: Join) 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

-- | Specifies the type of join to be performed on the datasets.
join_joinType :: Lens.Lens' Join JoinType
join_joinType :: Lens' Join JoinType
join_joinType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Join' {JoinType
joinType :: JoinType
$sel:joinType:Join' :: Join -> JoinType
joinType} -> JoinType
joinType) (\s :: Join
s@Join' {} JoinType
a -> Join
s {$sel:joinType:Join' :: JoinType
joinType = JoinType
a} :: Join)

-- | A list of the two columns to be joined.
join_columns :: Lens.Lens' Join (Prelude.NonEmpty JoinColumn)
join_columns :: Lens' Join (NonEmpty JoinColumn)
join_columns = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Join' {NonEmpty JoinColumn
columns :: NonEmpty JoinColumn
$sel:columns:Join' :: Join -> NonEmpty JoinColumn
columns} -> NonEmpty JoinColumn
columns) (\s :: Join
s@Join' {} NonEmpty JoinColumn
a -> Join
s {$sel:columns:Join' :: NonEmpty JoinColumn
columns = NonEmpty JoinColumn
a} :: Join) 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 Join where
  parseJSON :: Value -> Parser Join
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Join"
      ( \Object
x ->
          Text -> NonEmpty Text -> JoinType -> NonEmpty JoinColumn -> Join
Join'
            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 a
Data..: Key
"JoinType")
            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
"Columns")
      )

instance Prelude.Hashable Join where
  hashWithSalt :: Int -> Join -> Int
hashWithSalt Int
_salt Join' {NonEmpty Text
NonEmpty JoinColumn
Text
JoinType
columns :: NonEmpty JoinColumn
joinType :: JoinType
inputs :: NonEmpty Text
name :: Text
$sel:columns:Join' :: Join -> NonEmpty JoinColumn
$sel:joinType:Join' :: Join -> JoinType
$sel:inputs:Join' :: Join -> NonEmpty Text
$sel:name:Join' :: Join -> 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` JoinType
joinType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty JoinColumn
columns

instance Prelude.NFData Join where
  rnf :: Join -> ()
rnf Join' {NonEmpty Text
NonEmpty JoinColumn
Text
JoinType
columns :: NonEmpty JoinColumn
joinType :: JoinType
inputs :: NonEmpty Text
name :: Text
$sel:columns:Join' :: Join -> NonEmpty JoinColumn
$sel:joinType:Join' :: Join -> JoinType
$sel:inputs:Join' :: Join -> NonEmpty Text
$sel:name:Join' :: Join -> 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 JoinType
joinType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty JoinColumn
columns

instance Data.ToJSON Join where
  toJSON :: Join -> Value
toJSON Join' {NonEmpty Text
NonEmpty JoinColumn
Text
JoinType
columns :: NonEmpty JoinColumn
joinType :: JoinType
inputs :: NonEmpty Text
name :: Text
$sel:columns:Join' :: Join -> NonEmpty JoinColumn
$sel:joinType:Join' :: Join -> JoinType
$sel:inputs:Join' :: Join -> NonEmpty Text
$sel:name:Join' :: Join -> 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
"JoinType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= JoinType
joinType),
            forall a. a -> Maybe a
Prelude.Just (Key
"Columns" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty JoinColumn
columns)
          ]
      )