{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.SageMakerFeatureStoreRuntime.PutRecord
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Used for data ingestion into the @FeatureStore@. The @PutRecord@ API
-- writes to both the @OnlineStore@ and @OfflineStore@. If the record is
-- the latest record for the @recordIdentifier@, the record is written to
-- both the @OnlineStore@ and @OfflineStore@. If the record is a historic
-- record, it is written only to the @OfflineStore@.
module Amazonka.SageMakerFeatureStoreRuntime.PutRecord
  ( -- * Creating a Request
    PutRecord (..),
    newPutRecord,

    -- * Request Lenses
    putRecord_targetStores,
    putRecord_featureGroupName,
    putRecord_record,

    -- * Destructuring the Response
    PutRecordResponse (..),
    newPutRecordResponse,
  )
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
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.SageMakerFeatureStoreRuntime.Types

-- | /See:/ 'newPutRecord' smart constructor.
data PutRecord = PutRecord'
  { -- | A list of stores to which you\'re adding the record. By default, Feature
    -- Store adds the record to all of the stores that you\'re using for the
    -- @FeatureGroup@.
    PutRecord -> Maybe (NonEmpty TargetStore)
targetStores :: Prelude.Maybe (Prelude.NonEmpty TargetStore),
    -- | The name of the feature group that you want to insert the record into.
    PutRecord -> Text
featureGroupName :: Prelude.Text,
    -- | List of FeatureValues to be inserted. This will be a full over-write. If
    -- you only want to update few of the feature values, do the following:
    --
    -- -   Use @GetRecord@ to retrieve the latest record.
    --
    -- -   Update the record returned from @GetRecord@.
    --
    -- -   Use @PutRecord@ to update feature values.
    PutRecord -> NonEmpty FeatureValue
record :: Prelude.NonEmpty FeatureValue
  }
  deriving (PutRecord -> PutRecord -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutRecord -> PutRecord -> Bool
$c/= :: PutRecord -> PutRecord -> Bool
== :: PutRecord -> PutRecord -> Bool
$c== :: PutRecord -> PutRecord -> Bool
Prelude.Eq, ReadPrec [PutRecord]
ReadPrec PutRecord
Int -> ReadS PutRecord
ReadS [PutRecord]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutRecord]
$creadListPrec :: ReadPrec [PutRecord]
readPrec :: ReadPrec PutRecord
$creadPrec :: ReadPrec PutRecord
readList :: ReadS [PutRecord]
$creadList :: ReadS [PutRecord]
readsPrec :: Int -> ReadS PutRecord
$creadsPrec :: Int -> ReadS PutRecord
Prelude.Read, Int -> PutRecord -> ShowS
[PutRecord] -> ShowS
PutRecord -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutRecord] -> ShowS
$cshowList :: [PutRecord] -> ShowS
show :: PutRecord -> String
$cshow :: PutRecord -> String
showsPrec :: Int -> PutRecord -> ShowS
$cshowsPrec :: Int -> PutRecord -> ShowS
Prelude.Show, forall x. Rep PutRecord x -> PutRecord
forall x. PutRecord -> Rep PutRecord x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutRecord x -> PutRecord
$cfrom :: forall x. PutRecord -> Rep PutRecord x
Prelude.Generic)

-- |
-- Create a value of 'PutRecord' 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:
--
-- 'targetStores', 'putRecord_targetStores' - A list of stores to which you\'re adding the record. By default, Feature
-- Store adds the record to all of the stores that you\'re using for the
-- @FeatureGroup@.
--
-- 'featureGroupName', 'putRecord_featureGroupName' - The name of the feature group that you want to insert the record into.
--
-- 'record', 'putRecord_record' - List of FeatureValues to be inserted. This will be a full over-write. If
-- you only want to update few of the feature values, do the following:
--
-- -   Use @GetRecord@ to retrieve the latest record.
--
-- -   Update the record returned from @GetRecord@.
--
-- -   Use @PutRecord@ to update feature values.
newPutRecord ::
  -- | 'featureGroupName'
  Prelude.Text ->
  -- | 'record'
  Prelude.NonEmpty FeatureValue ->
  PutRecord
newPutRecord :: Text -> NonEmpty FeatureValue -> PutRecord
newPutRecord Text
pFeatureGroupName_ NonEmpty FeatureValue
pRecord_ =
  PutRecord'
    { $sel:targetStores:PutRecord' :: Maybe (NonEmpty TargetStore)
targetStores = forall a. Maybe a
Prelude.Nothing,
      $sel:featureGroupName:PutRecord' :: Text
featureGroupName = Text
pFeatureGroupName_,
      $sel:record:PutRecord' :: NonEmpty FeatureValue
record = 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 FeatureValue
pRecord_
    }

-- | A list of stores to which you\'re adding the record. By default, Feature
-- Store adds the record to all of the stores that you\'re using for the
-- @FeatureGroup@.
putRecord_targetStores :: Lens.Lens' PutRecord (Prelude.Maybe (Prelude.NonEmpty TargetStore))
putRecord_targetStores :: Lens' PutRecord (Maybe (NonEmpty TargetStore))
putRecord_targetStores = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRecord' {Maybe (NonEmpty TargetStore)
targetStores :: Maybe (NonEmpty TargetStore)
$sel:targetStores:PutRecord' :: PutRecord -> Maybe (NonEmpty TargetStore)
targetStores} -> Maybe (NonEmpty TargetStore)
targetStores) (\s :: PutRecord
s@PutRecord' {} Maybe (NonEmpty TargetStore)
a -> PutRecord
s {$sel:targetStores:PutRecord' :: Maybe (NonEmpty TargetStore)
targetStores = Maybe (NonEmpty TargetStore)
a} :: PutRecord) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the feature group that you want to insert the record into.
putRecord_featureGroupName :: Lens.Lens' PutRecord Prelude.Text
putRecord_featureGroupName :: Lens' PutRecord Text
putRecord_featureGroupName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRecord' {Text
featureGroupName :: Text
$sel:featureGroupName:PutRecord' :: PutRecord -> Text
featureGroupName} -> Text
featureGroupName) (\s :: PutRecord
s@PutRecord' {} Text
a -> PutRecord
s {$sel:featureGroupName:PutRecord' :: Text
featureGroupName = Text
a} :: PutRecord)

-- | List of FeatureValues to be inserted. This will be a full over-write. If
-- you only want to update few of the feature values, do the following:
--
-- -   Use @GetRecord@ to retrieve the latest record.
--
-- -   Update the record returned from @GetRecord@.
--
-- -   Use @PutRecord@ to update feature values.
putRecord_record :: Lens.Lens' PutRecord (Prelude.NonEmpty FeatureValue)
putRecord_record :: Lens' PutRecord (NonEmpty FeatureValue)
putRecord_record = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRecord' {NonEmpty FeatureValue
record :: NonEmpty FeatureValue
$sel:record:PutRecord' :: PutRecord -> NonEmpty FeatureValue
record} -> NonEmpty FeatureValue
record) (\s :: PutRecord
s@PutRecord' {} NonEmpty FeatureValue
a -> PutRecord
s {$sel:record:PutRecord' :: NonEmpty FeatureValue
record = NonEmpty FeatureValue
a} :: PutRecord) 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 Core.AWSRequest PutRecord where
  type AWSResponse PutRecord = PutRecordResponse
  request :: (Service -> Service) -> PutRecord -> Request PutRecord
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy PutRecord
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutRecord)))
response = forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull PutRecordResponse
PutRecordResponse'

instance Prelude.Hashable PutRecord where
  hashWithSalt :: Int -> PutRecord -> Int
hashWithSalt Int
_salt PutRecord' {Maybe (NonEmpty TargetStore)
NonEmpty FeatureValue
Text
record :: NonEmpty FeatureValue
featureGroupName :: Text
targetStores :: Maybe (NonEmpty TargetStore)
$sel:record:PutRecord' :: PutRecord -> NonEmpty FeatureValue
$sel:featureGroupName:PutRecord' :: PutRecord -> Text
$sel:targetStores:PutRecord' :: PutRecord -> Maybe (NonEmpty TargetStore)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty TargetStore)
targetStores
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
featureGroupName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty FeatureValue
record

instance Prelude.NFData PutRecord where
  rnf :: PutRecord -> ()
rnf PutRecord' {Maybe (NonEmpty TargetStore)
NonEmpty FeatureValue
Text
record :: NonEmpty FeatureValue
featureGroupName :: Text
targetStores :: Maybe (NonEmpty TargetStore)
$sel:record:PutRecord' :: PutRecord -> NonEmpty FeatureValue
$sel:featureGroupName:PutRecord' :: PutRecord -> Text
$sel:targetStores:PutRecord' :: PutRecord -> Maybe (NonEmpty TargetStore)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty TargetStore)
targetStores
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
featureGroupName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty FeatureValue
record

instance Data.ToHeaders PutRecord where
  toHeaders :: PutRecord -> [Header]
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> [Header]
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON PutRecord where
  toJSON :: PutRecord -> Value
toJSON PutRecord' {Maybe (NonEmpty TargetStore)
NonEmpty FeatureValue
Text
record :: NonEmpty FeatureValue
featureGroupName :: Text
targetStores :: Maybe (NonEmpty TargetStore)
$sel:record:PutRecord' :: PutRecord -> NonEmpty FeatureValue
$sel:featureGroupName:PutRecord' :: PutRecord -> Text
$sel:targetStores:PutRecord' :: PutRecord -> Maybe (NonEmpty TargetStore)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"TargetStores" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty TargetStore)
targetStores,
            forall a. a -> Maybe a
Prelude.Just (Key
"Record" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty FeatureValue
record)
          ]
      )

instance Data.ToPath PutRecord where
  toPath :: PutRecord -> ByteString
toPath PutRecord' {Maybe (NonEmpty TargetStore)
NonEmpty FeatureValue
Text
record :: NonEmpty FeatureValue
featureGroupName :: Text
targetStores :: Maybe (NonEmpty TargetStore)
$sel:record:PutRecord' :: PutRecord -> NonEmpty FeatureValue
$sel:featureGroupName:PutRecord' :: PutRecord -> Text
$sel:targetStores:PutRecord' :: PutRecord -> Maybe (NonEmpty TargetStore)
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/FeatureGroup/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
featureGroupName]

instance Data.ToQuery PutRecord where
  toQuery :: PutRecord -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newPutRecordResponse' smart constructor.
data PutRecordResponse = PutRecordResponse'
  {
  }
  deriving (PutRecordResponse -> PutRecordResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutRecordResponse -> PutRecordResponse -> Bool
$c/= :: PutRecordResponse -> PutRecordResponse -> Bool
== :: PutRecordResponse -> PutRecordResponse -> Bool
$c== :: PutRecordResponse -> PutRecordResponse -> Bool
Prelude.Eq, ReadPrec [PutRecordResponse]
ReadPrec PutRecordResponse
Int -> ReadS PutRecordResponse
ReadS [PutRecordResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutRecordResponse]
$creadListPrec :: ReadPrec [PutRecordResponse]
readPrec :: ReadPrec PutRecordResponse
$creadPrec :: ReadPrec PutRecordResponse
readList :: ReadS [PutRecordResponse]
$creadList :: ReadS [PutRecordResponse]
readsPrec :: Int -> ReadS PutRecordResponse
$creadsPrec :: Int -> ReadS PutRecordResponse
Prelude.Read, Int -> PutRecordResponse -> ShowS
[PutRecordResponse] -> ShowS
PutRecordResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutRecordResponse] -> ShowS
$cshowList :: [PutRecordResponse] -> ShowS
show :: PutRecordResponse -> String
$cshow :: PutRecordResponse -> String
showsPrec :: Int -> PutRecordResponse -> ShowS
$cshowsPrec :: Int -> PutRecordResponse -> ShowS
Prelude.Show, forall x. Rep PutRecordResponse x -> PutRecordResponse
forall x. PutRecordResponse -> Rep PutRecordResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutRecordResponse x -> PutRecordResponse
$cfrom :: forall x. PutRecordResponse -> Rep PutRecordResponse x
Prelude.Generic)

-- |
-- Create a value of 'PutRecordResponse' 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.
newPutRecordResponse ::
  PutRecordResponse
newPutRecordResponse :: PutRecordResponse
newPutRecordResponse = PutRecordResponse
PutRecordResponse'

instance Prelude.NFData PutRecordResponse where
  rnf :: PutRecordResponse -> ()
rnf PutRecordResponse
_ = ()