{-# 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.Filter
-- 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.Filter 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.FilterExpression
import Amazonka.Glue.Types.FilterLogicalOperator
import qualified Amazonka.Prelude as Prelude

-- | Specifies a transform that splits a dataset into two, based on a filter
-- condition.
--
-- /See:/ 'newFilter' smart constructor.
data Filter = Filter'
  { -- | The name of the transform node.
    Filter -> Text
name :: Prelude.Text,
    -- | The data inputs identified by their node names.
    Filter -> NonEmpty Text
inputs :: Prelude.NonEmpty Prelude.Text,
    -- | The operator used to filter rows by comparing the key value to a
    -- specified value.
    Filter -> FilterLogicalOperator
logicalOperator :: FilterLogicalOperator,
    -- | Specifies a filter expression.
    Filter -> [FilterExpression]
filters :: [FilterExpression]
  }
  deriving (Filter -> Filter -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Filter -> Filter -> Bool
$c/= :: Filter -> Filter -> Bool
== :: Filter -> Filter -> Bool
$c== :: Filter -> Filter -> Bool
Prelude.Eq, ReadPrec [Filter]
ReadPrec Filter
Int -> ReadS Filter
ReadS [Filter]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Filter]
$creadListPrec :: ReadPrec [Filter]
readPrec :: ReadPrec Filter
$creadPrec :: ReadPrec Filter
readList :: ReadS [Filter]
$creadList :: ReadS [Filter]
readsPrec :: Int -> ReadS Filter
$creadsPrec :: Int -> ReadS Filter
Prelude.Read, Int -> Filter -> ShowS
[Filter] -> ShowS
Filter -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Filter] -> ShowS
$cshowList :: [Filter] -> ShowS
show :: Filter -> String
$cshow :: Filter -> String
showsPrec :: Int -> Filter -> ShowS
$cshowsPrec :: Int -> Filter -> ShowS
Prelude.Show, forall x. Rep Filter x -> Filter
forall x. Filter -> Rep Filter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Filter x -> Filter
$cfrom :: forall x. Filter -> Rep Filter x
Prelude.Generic)

-- |
-- Create a value of 'Filter' 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', 'filter_name' - The name of the transform node.
--
-- 'inputs', 'filter_inputs' - The data inputs identified by their node names.
--
-- 'logicalOperator', 'filter_logicalOperator' - The operator used to filter rows by comparing the key value to a
-- specified value.
--
-- 'filters', 'filter_filters' - Specifies a filter expression.
newFilter ::
  -- | 'name'
  Prelude.Text ->
  -- | 'inputs'
  Prelude.NonEmpty Prelude.Text ->
  -- | 'logicalOperator'
  FilterLogicalOperator ->
  Filter
newFilter :: Text -> NonEmpty Text -> FilterLogicalOperator -> Filter
newFilter Text
pName_ NonEmpty Text
pInputs_ FilterLogicalOperator
pLogicalOperator_ =
  Filter'
    { $sel:name:Filter' :: Text
name = Text
pName_,
      $sel:inputs:Filter' :: 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:logicalOperator:Filter' :: FilterLogicalOperator
logicalOperator = FilterLogicalOperator
pLogicalOperator_,
      $sel:filters:Filter' :: [FilterExpression]
filters = forall a. Monoid a => a
Prelude.mempty
    }

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

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

-- | The operator used to filter rows by comparing the key value to a
-- specified value.
filter_logicalOperator :: Lens.Lens' Filter FilterLogicalOperator
filter_logicalOperator :: Lens' Filter FilterLogicalOperator
filter_logicalOperator = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Filter' {FilterLogicalOperator
logicalOperator :: FilterLogicalOperator
$sel:logicalOperator:Filter' :: Filter -> FilterLogicalOperator
logicalOperator} -> FilterLogicalOperator
logicalOperator) (\s :: Filter
s@Filter' {} FilterLogicalOperator
a -> Filter
s {$sel:logicalOperator:Filter' :: FilterLogicalOperator
logicalOperator = FilterLogicalOperator
a} :: Filter)

-- | Specifies a filter expression.
filter_filters :: Lens.Lens' Filter [FilterExpression]
filter_filters :: Lens' Filter [FilterExpression]
filter_filters = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Filter' {[FilterExpression]
filters :: [FilterExpression]
$sel:filters:Filter' :: Filter -> [FilterExpression]
filters} -> [FilterExpression]
filters) (\s :: Filter
s@Filter' {} [FilterExpression]
a -> Filter
s {$sel:filters:Filter' :: [FilterExpression]
filters = [FilterExpression]
a} :: Filter) 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 Filter where
  parseJSON :: Value -> Parser Filter
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Filter"
      ( \Object
x ->
          Text
-> NonEmpty Text
-> FilterLogicalOperator
-> [FilterExpression]
-> Filter
Filter'
            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
"LogicalOperator")
            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
"Filters" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable Filter where
  hashWithSalt :: Int -> Filter -> Int
hashWithSalt Int
_salt Filter' {[FilterExpression]
NonEmpty Text
Text
FilterLogicalOperator
filters :: [FilterExpression]
logicalOperator :: FilterLogicalOperator
inputs :: NonEmpty Text
name :: Text
$sel:filters:Filter' :: Filter -> [FilterExpression]
$sel:logicalOperator:Filter' :: Filter -> FilterLogicalOperator
$sel:inputs:Filter' :: Filter -> NonEmpty Text
$sel:name:Filter' :: Filter -> 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` FilterLogicalOperator
logicalOperator
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [FilterExpression]
filters

instance Prelude.NFData Filter where
  rnf :: Filter -> ()
rnf Filter' {[FilterExpression]
NonEmpty Text
Text
FilterLogicalOperator
filters :: [FilterExpression]
logicalOperator :: FilterLogicalOperator
inputs :: NonEmpty Text
name :: Text
$sel:filters:Filter' :: Filter -> [FilterExpression]
$sel:logicalOperator:Filter' :: Filter -> FilterLogicalOperator
$sel:inputs:Filter' :: Filter -> NonEmpty Text
$sel:name:Filter' :: Filter -> 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 FilterLogicalOperator
logicalOperator
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [FilterExpression]
filters

instance Data.ToJSON Filter where
  toJSON :: Filter -> Value
toJSON Filter' {[FilterExpression]
NonEmpty Text
Text
FilterLogicalOperator
filters :: [FilterExpression]
logicalOperator :: FilterLogicalOperator
inputs :: NonEmpty Text
name :: Text
$sel:filters:Filter' :: Filter -> [FilterExpression]
$sel:logicalOperator:Filter' :: Filter -> FilterLogicalOperator
$sel:inputs:Filter' :: Filter -> NonEmpty Text
$sel:name:Filter' :: Filter -> 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
"LogicalOperator" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= FilterLogicalOperator
logicalOperator),
            forall a. a -> Maybe a
Prelude.Just (Key
"Filters" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [FilterExpression]
filters)
          ]
      )