{-# 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.Athena.Types.ResultSet
-- 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.Athena.Types.ResultSet where

import Amazonka.Athena.Types.ResultSetMetadata
import Amazonka.Athena.Types.Row
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The metadata and rows that comprise a query result set. The metadata
-- describes the column structure and data types. To return a @ResultSet@
-- object, use GetQueryResults.
--
-- /See:/ 'newResultSet' smart constructor.
data ResultSet = ResultSet'
  { -- | The rows in the table.
    ResultSet -> Maybe [Row]
rows :: Prelude.Maybe [Row],
    -- | The metadata that describes the column structure and data types of a
    -- table of query results.
    ResultSet -> Maybe ResultSetMetadata
resultSetMetadata :: Prelude.Maybe ResultSetMetadata
  }
  deriving (ResultSet -> ResultSet -> Bool
(ResultSet -> ResultSet -> Bool)
-> (ResultSet -> ResultSet -> Bool) -> Eq ResultSet
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResultSet -> ResultSet -> Bool
$c/= :: ResultSet -> ResultSet -> Bool
== :: ResultSet -> ResultSet -> Bool
$c== :: ResultSet -> ResultSet -> Bool
Prelude.Eq, ReadPrec [ResultSet]
ReadPrec ResultSet
Int -> ReadS ResultSet
ReadS [ResultSet]
(Int -> ReadS ResultSet)
-> ReadS [ResultSet]
-> ReadPrec ResultSet
-> ReadPrec [ResultSet]
-> Read ResultSet
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResultSet]
$creadListPrec :: ReadPrec [ResultSet]
readPrec :: ReadPrec ResultSet
$creadPrec :: ReadPrec ResultSet
readList :: ReadS [ResultSet]
$creadList :: ReadS [ResultSet]
readsPrec :: Int -> ReadS ResultSet
$creadsPrec :: Int -> ReadS ResultSet
Prelude.Read, Int -> ResultSet -> ShowS
[ResultSet] -> ShowS
ResultSet -> String
(Int -> ResultSet -> ShowS)
-> (ResultSet -> String)
-> ([ResultSet] -> ShowS)
-> Show ResultSet
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResultSet] -> ShowS
$cshowList :: [ResultSet] -> ShowS
show :: ResultSet -> String
$cshow :: ResultSet -> String
showsPrec :: Int -> ResultSet -> ShowS
$cshowsPrec :: Int -> ResultSet -> ShowS
Prelude.Show, (forall x. ResultSet -> Rep ResultSet x)
-> (forall x. Rep ResultSet x -> ResultSet) -> Generic ResultSet
forall x. Rep ResultSet x -> ResultSet
forall x. ResultSet -> Rep ResultSet x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResultSet x -> ResultSet
$cfrom :: forall x. ResultSet -> Rep ResultSet x
Prelude.Generic)

-- |
-- Create a value of 'ResultSet' 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:
--
-- 'rows', 'resultSet_rows' - The rows in the table.
--
-- 'resultSetMetadata', 'resultSet_resultSetMetadata' - The metadata that describes the column structure and data types of a
-- table of query results.
newResultSet ::
  ResultSet
newResultSet :: ResultSet
newResultSet =
  ResultSet' :: Maybe [Row] -> Maybe ResultSetMetadata -> ResultSet
ResultSet'
    { $sel:rows:ResultSet' :: Maybe [Row]
rows = Maybe [Row]
forall a. Maybe a
Prelude.Nothing,
      $sel:resultSetMetadata:ResultSet' :: Maybe ResultSetMetadata
resultSetMetadata = Maybe ResultSetMetadata
forall a. Maybe a
Prelude.Nothing
    }

-- | The rows in the table.
resultSet_rows :: Lens.Lens' ResultSet (Prelude.Maybe [Row])
resultSet_rows :: (Maybe [Row] -> f (Maybe [Row])) -> ResultSet -> f ResultSet
resultSet_rows = (ResultSet -> Maybe [Row])
-> (ResultSet -> Maybe [Row] -> ResultSet)
-> Lens ResultSet ResultSet (Maybe [Row]) (Maybe [Row])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResultSet' {Maybe [Row]
rows :: Maybe [Row]
$sel:rows:ResultSet' :: ResultSet -> Maybe [Row]
rows} -> Maybe [Row]
rows) (\s :: ResultSet
s@ResultSet' {} Maybe [Row]
a -> ResultSet
s {$sel:rows:ResultSet' :: Maybe [Row]
rows = Maybe [Row]
a} :: ResultSet) ((Maybe [Row] -> f (Maybe [Row])) -> ResultSet -> f ResultSet)
-> ((Maybe [Row] -> f (Maybe [Row]))
    -> Maybe [Row] -> f (Maybe [Row]))
-> (Maybe [Row] -> f (Maybe [Row]))
-> ResultSet
-> f ResultSet
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Row] [Row] [Row] [Row]
-> Iso (Maybe [Row]) (Maybe [Row]) (Maybe [Row]) (Maybe [Row])
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 AnIso [Row] [Row] [Row] [Row]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The metadata that describes the column structure and data types of a
-- table of query results.
resultSet_resultSetMetadata :: Lens.Lens' ResultSet (Prelude.Maybe ResultSetMetadata)
resultSet_resultSetMetadata :: (Maybe ResultSetMetadata -> f (Maybe ResultSetMetadata))
-> ResultSet -> f ResultSet
resultSet_resultSetMetadata = (ResultSet -> Maybe ResultSetMetadata)
-> (ResultSet -> Maybe ResultSetMetadata -> ResultSet)
-> Lens
     ResultSet
     ResultSet
     (Maybe ResultSetMetadata)
     (Maybe ResultSetMetadata)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResultSet' {Maybe ResultSetMetadata
resultSetMetadata :: Maybe ResultSetMetadata
$sel:resultSetMetadata:ResultSet' :: ResultSet -> Maybe ResultSetMetadata
resultSetMetadata} -> Maybe ResultSetMetadata
resultSetMetadata) (\s :: ResultSet
s@ResultSet' {} Maybe ResultSetMetadata
a -> ResultSet
s {$sel:resultSetMetadata:ResultSet' :: Maybe ResultSetMetadata
resultSetMetadata = Maybe ResultSetMetadata
a} :: ResultSet)

instance Core.FromJSON ResultSet where
  parseJSON :: Value -> Parser ResultSet
parseJSON =
    String -> (Object -> Parser ResultSet) -> Value -> Parser ResultSet
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ResultSet"
      ( \Object
x ->
          Maybe [Row] -> Maybe ResultSetMetadata -> ResultSet
ResultSet'
            (Maybe [Row] -> Maybe ResultSetMetadata -> ResultSet)
-> Parser (Maybe [Row])
-> Parser (Maybe ResultSetMetadata -> ResultSet)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [Row]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Rows" Parser (Maybe (Maybe [Row])) -> Maybe [Row] -> Parser (Maybe [Row])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Row]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe ResultSetMetadata -> ResultSet)
-> Parser (Maybe ResultSetMetadata) -> Parser ResultSet
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ResultSetMetadata)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ResultSetMetadata")
      )

instance Prelude.Hashable ResultSet

instance Prelude.NFData ResultSet