{-# 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.SageMaker.Types.Filter
-- 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.SageMaker.Types.Filter where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SageMaker.Types.Operator

-- | A conditional statement for a search expression that includes a resource
-- property, a Boolean operator, and a value. Resources that match the
-- statement are returned in the results from the Search API.
--
-- If you specify a @Value@, but not an @Operator@, Amazon SageMaker uses
-- the equals operator.
--
-- In search, there are several property types:
--
-- [Metrics]
--     To define a metric filter, enter a value using the form
--     @\"Metrics.\<name>\"@, where @\<name>@ is a metric name. For
--     example, the following filter searches for training jobs with an
--     @\"accuracy\"@ metric greater than @\"0.9\"@:
--
--     @{@
--
--     @\"Name\": \"Metrics.accuracy\",@
--
--     @\"Operator\": \"GreaterThan\",@
--
--     @\"Value\": \"0.9\"@
--
--     @}@
--
-- [HyperParameters]
--     To define a hyperparameter filter, enter a value with the form
--     @\"HyperParameters.\<name>\"@. Decimal hyperparameter values are
--     treated as a decimal in a comparison if the specified @Value@ is
--     also a decimal value. If the specified @Value@ is an integer, the
--     decimal hyperparameter values are treated as integers. For example,
--     the following filter is satisfied by training jobs with a
--     @\"learning_rate\"@ hyperparameter that is less than @\"0.5\"@:
--
--     @ {@
--
--     @ \"Name\": \"HyperParameters.learning_rate\",@
--
--     @ \"Operator\": \"LessThan\",@
--
--     @ \"Value\": \"0.5\"@
--
--     @ }@
--
-- [Tags]
--     To define a tag filter, enter a value with the form @Tags.\<key>@.
--
-- /See:/ 'newFilter' smart constructor.
data Filter = Filter'
  { -- | A Boolean binary operator that is used to evaluate the filter. The
    -- operator field contains one of the following values:
    --
    -- [Equals]
    --     The value of @Name@ equals @Value@.
    --
    -- [NotEquals]
    --     The value of @Name@ doesn\'t equal @Value@.
    --
    -- [Exists]
    --     The @Name@ property exists.
    --
    -- [NotExists]
    --     The @Name@ property does not exist.
    --
    -- [GreaterThan]
    --     The value of @Name@ is greater than @Value@. Not supported for text
    --     properties.
    --
    -- [GreaterThanOrEqualTo]
    --     The value of @Name@ is greater than or equal to @Value@. Not
    --     supported for text properties.
    --
    -- [LessThan]
    --     The value of @Name@ is less than @Value@. Not supported for text
    --     properties.
    --
    -- [LessThanOrEqualTo]
    --     The value of @Name@ is less than or equal to @Value@. Not supported
    --     for text properties.
    --
    -- [In]
    --     The value of @Name@ is one of the comma delimited strings in
    --     @Value@. Only supported for text properties.
    --
    -- [Contains]
    --     The value of @Name@ contains the string @Value@. Only supported for
    --     text properties.
    --
    --     A @SearchExpression@ can include the @Contains@ operator multiple
    --     times when the value of @Name@ is one of the following:
    --
    --     -   @Experiment.DisplayName@
    --
    --     -   @Experiment.ExperimentName@
    --
    --     -   @Experiment.Tags@
    --
    --     -   @Trial.DisplayName@
    --
    --     -   @Trial.TrialName@
    --
    --     -   @Trial.Tags@
    --
    --     -   @TrialComponent.DisplayName@
    --
    --     -   @TrialComponent.TrialComponentName@
    --
    --     -   @TrialComponent.Tags@
    --
    --     -   @TrialComponent.InputArtifacts@
    --
    --     -   @TrialComponent.OutputArtifacts@
    --
    --     A @SearchExpression@ can include only one @Contains@ operator for
    --     all other values of @Name@. In these cases, if you include multiple
    --     @Contains@ operators in the @SearchExpression@, the result is the
    --     following error message:
    --     \"@\'CONTAINS\' operator usage limit of 1 exceeded.@\"
    Filter -> Maybe Operator
operator :: Prelude.Maybe Operator,
    -- | A value used with @Name@ and @Operator@ to determine which resources
    -- satisfy the filter\'s condition. For numerical properties, @Value@ must
    -- be an integer or floating-point decimal. For timestamp properties,
    -- @Value@ must be an ISO 8601 date-time string of the following format:
    -- @YYYY-mm-dd\'T\'HH:MM:SS@.
    Filter -> Maybe Text
value :: Prelude.Maybe Prelude.Text,
    -- | A resource property name. For example, @TrainingJobName@. For valid
    -- property names, see SearchRecord. You must specify a valid property for
    -- the resource.
    Filter -> Text
name :: Prelude.Text
  }
  deriving (Filter -> Filter -> Bool
(Filter -> Filter -> Bool)
-> (Filter -> Filter -> Bool) -> Eq Filter
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]
(Int -> ReadS Filter)
-> ReadS [Filter]
-> ReadPrec Filter
-> ReadPrec [Filter]
-> Read 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
(Int -> Filter -> ShowS)
-> (Filter -> String) -> ([Filter] -> ShowS) -> Show Filter
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. Filter -> Rep Filter x)
-> (forall x. Rep Filter x -> Filter) -> Generic Filter
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:
--
-- 'operator', 'filter_operator' - A Boolean binary operator that is used to evaluate the filter. The
-- operator field contains one of the following values:
--
-- [Equals]
--     The value of @Name@ equals @Value@.
--
-- [NotEquals]
--     The value of @Name@ doesn\'t equal @Value@.
--
-- [Exists]
--     The @Name@ property exists.
--
-- [NotExists]
--     The @Name@ property does not exist.
--
-- [GreaterThan]
--     The value of @Name@ is greater than @Value@. Not supported for text
--     properties.
--
-- [GreaterThanOrEqualTo]
--     The value of @Name@ is greater than or equal to @Value@. Not
--     supported for text properties.
--
-- [LessThan]
--     The value of @Name@ is less than @Value@. Not supported for text
--     properties.
--
-- [LessThanOrEqualTo]
--     The value of @Name@ is less than or equal to @Value@. Not supported
--     for text properties.
--
-- [In]
--     The value of @Name@ is one of the comma delimited strings in
--     @Value@. Only supported for text properties.
--
-- [Contains]
--     The value of @Name@ contains the string @Value@. Only supported for
--     text properties.
--
--     A @SearchExpression@ can include the @Contains@ operator multiple
--     times when the value of @Name@ is one of the following:
--
--     -   @Experiment.DisplayName@
--
--     -   @Experiment.ExperimentName@
--
--     -   @Experiment.Tags@
--
--     -   @Trial.DisplayName@
--
--     -   @Trial.TrialName@
--
--     -   @Trial.Tags@
--
--     -   @TrialComponent.DisplayName@
--
--     -   @TrialComponent.TrialComponentName@
--
--     -   @TrialComponent.Tags@
--
--     -   @TrialComponent.InputArtifacts@
--
--     -   @TrialComponent.OutputArtifacts@
--
--     A @SearchExpression@ can include only one @Contains@ operator for
--     all other values of @Name@. In these cases, if you include multiple
--     @Contains@ operators in the @SearchExpression@, the result is the
--     following error message:
--     \"@\'CONTAINS\' operator usage limit of 1 exceeded.@\"
--
-- 'value', 'filter_value' - A value used with @Name@ and @Operator@ to determine which resources
-- satisfy the filter\'s condition. For numerical properties, @Value@ must
-- be an integer or floating-point decimal. For timestamp properties,
-- @Value@ must be an ISO 8601 date-time string of the following format:
-- @YYYY-mm-dd\'T\'HH:MM:SS@.
--
-- 'name', 'filter_name' - A resource property name. For example, @TrainingJobName@. For valid
-- property names, see SearchRecord. You must specify a valid property for
-- the resource.
newFilter ::
  -- | 'name'
  Prelude.Text ->
  Filter
newFilter :: Text -> Filter
newFilter Text
pName_ =
  Filter' :: Maybe Operator -> Maybe Text -> Text -> Filter
Filter'
    { $sel:operator:Filter' :: Maybe Operator
operator = Maybe Operator
forall a. Maybe a
Prelude.Nothing,
      $sel:value:Filter' :: Maybe Text
value = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Filter' :: Text
name = Text
pName_
    }

-- | A Boolean binary operator that is used to evaluate the filter. The
-- operator field contains one of the following values:
--
-- [Equals]
--     The value of @Name@ equals @Value@.
--
-- [NotEquals]
--     The value of @Name@ doesn\'t equal @Value@.
--
-- [Exists]
--     The @Name@ property exists.
--
-- [NotExists]
--     The @Name@ property does not exist.
--
-- [GreaterThan]
--     The value of @Name@ is greater than @Value@. Not supported for text
--     properties.
--
-- [GreaterThanOrEqualTo]
--     The value of @Name@ is greater than or equal to @Value@. Not
--     supported for text properties.
--
-- [LessThan]
--     The value of @Name@ is less than @Value@. Not supported for text
--     properties.
--
-- [LessThanOrEqualTo]
--     The value of @Name@ is less than or equal to @Value@. Not supported
--     for text properties.
--
-- [In]
--     The value of @Name@ is one of the comma delimited strings in
--     @Value@. Only supported for text properties.
--
-- [Contains]
--     The value of @Name@ contains the string @Value@. Only supported for
--     text properties.
--
--     A @SearchExpression@ can include the @Contains@ operator multiple
--     times when the value of @Name@ is one of the following:
--
--     -   @Experiment.DisplayName@
--
--     -   @Experiment.ExperimentName@
--
--     -   @Experiment.Tags@
--
--     -   @Trial.DisplayName@
--
--     -   @Trial.TrialName@
--
--     -   @Trial.Tags@
--
--     -   @TrialComponent.DisplayName@
--
--     -   @TrialComponent.TrialComponentName@
--
--     -   @TrialComponent.Tags@
--
--     -   @TrialComponent.InputArtifacts@
--
--     -   @TrialComponent.OutputArtifacts@
--
--     A @SearchExpression@ can include only one @Contains@ operator for
--     all other values of @Name@. In these cases, if you include multiple
--     @Contains@ operators in the @SearchExpression@, the result is the
--     following error message:
--     \"@\'CONTAINS\' operator usage limit of 1 exceeded.@\"
filter_operator :: Lens.Lens' Filter (Prelude.Maybe Operator)
filter_operator :: (Maybe Operator -> f (Maybe Operator)) -> Filter -> f Filter
filter_operator = (Filter -> Maybe Operator)
-> (Filter -> Maybe Operator -> Filter)
-> Lens Filter Filter (Maybe Operator) (Maybe Operator)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Filter' {Maybe Operator
operator :: Maybe Operator
$sel:operator:Filter' :: Filter -> Maybe Operator
operator} -> Maybe Operator
operator) (\s :: Filter
s@Filter' {} Maybe Operator
a -> Filter
s {$sel:operator:Filter' :: Maybe Operator
operator = Maybe Operator
a} :: Filter)

-- | A value used with @Name@ and @Operator@ to determine which resources
-- satisfy the filter\'s condition. For numerical properties, @Value@ must
-- be an integer or floating-point decimal. For timestamp properties,
-- @Value@ must be an ISO 8601 date-time string of the following format:
-- @YYYY-mm-dd\'T\'HH:MM:SS@.
filter_value :: Lens.Lens' Filter (Prelude.Maybe Prelude.Text)
filter_value :: (Maybe Text -> f (Maybe Text)) -> Filter -> f Filter
filter_value = (Filter -> Maybe Text)
-> (Filter -> Maybe Text -> Filter)
-> Lens Filter Filter (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Filter' {Maybe Text
value :: Maybe Text
$sel:value:Filter' :: Filter -> Maybe Text
value} -> Maybe Text
value) (\s :: Filter
s@Filter' {} Maybe Text
a -> Filter
s {$sel:value:Filter' :: Maybe Text
value = Maybe Text
a} :: Filter)

-- | A resource property name. For example, @TrainingJobName@. For valid
-- property names, see SearchRecord. You must specify a valid property for
-- the resource.
filter_name :: Lens.Lens' Filter Prelude.Text
filter_name :: (Text -> f Text) -> Filter -> f Filter
filter_name = (Filter -> Text)
-> (Filter -> Text -> Filter) -> Lens Filter Filter Text Text
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)

instance Prelude.Hashable Filter

instance Prelude.NFData Filter

instance Core.ToJSON Filter where
  toJSON :: Filter -> Value
toJSON Filter' {Maybe Text
Maybe Operator
Text
name :: Text
value :: Maybe Text
operator :: Maybe Operator
$sel:name:Filter' :: Filter -> Text
$sel:value:Filter' :: Filter -> Maybe Text
$sel:operator:Filter' :: Filter -> Maybe Operator
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Operator" Text -> Operator -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Operator -> Pair) -> Maybe Operator -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Operator
operator,
            (Text
"Value" 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
value,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name)
          ]
      )