2021-04-12 13:18:29 +03:00
|
|
|
-- | Planning T-SQL queries and subscriptions.
|
|
|
|
|
|
|
|
module Hasura.Backends.BigQuery.Plan
|
|
|
|
( planNoPlan
|
|
|
|
) where
|
|
|
|
|
2021-05-11 18:18:31 +03:00
|
|
|
import Hasura.Prelude
|
2021-04-12 13:18:29 +03:00
|
|
|
|
2021-06-28 16:29:48 +03:00
|
|
|
import qualified Data.Text.Lazy as LT
|
2021-04-12 13:18:29 +03:00
|
|
|
|
|
|
|
import Control.Monad.Validate
|
2021-05-11 18:18:31 +03:00
|
|
|
import Data.Aeson.Text
|
2021-04-12 13:18:29 +03:00
|
|
|
import Data.Text.Extended
|
|
|
|
|
2021-06-28 16:29:48 +03:00
|
|
|
import qualified Hasura.Base.Error as E
|
|
|
|
import qualified Hasura.GraphQL.Parser as GraphQL
|
|
|
|
import qualified Hasura.RQL.Types.Column as RQL
|
2021-04-12 13:18:29 +03:00
|
|
|
|
2021-06-28 16:29:48 +03:00
|
|
|
import Hasura.Backends.BigQuery.FromIr as BigQuery
|
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
|
|
|
import Hasura.Backends.BigQuery.Types
|
2021-06-11 06:26:50 +03:00
|
|
|
import Hasura.RQL.IR
|
2021-04-12 13:18:29 +03:00
|
|
|
import Hasura.SQL.Backend
|
2021-05-11 18:18:31 +03:00
|
|
|
import Hasura.SQL.Types
|
|
|
|
import Hasura.Session
|
|
|
|
|
2021-04-12 13:18:29 +03:00
|
|
|
|
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Top-level planner
|
2021-04-12 13:18:29 +03:00
|
|
|
|
|
|
|
planNoPlan ::
|
2021-05-11 18:18:31 +03:00
|
|
|
MonadError E.QErr m
|
2021-06-25 16:35:39 +03:00
|
|
|
=> FromIrConfig
|
|
|
|
-> UserInfo
|
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
|
|
|
-> QueryDB 'BigQuery (Const Void) (GraphQL.UnpreparedValue 'BigQuery)
|
2021-04-12 13:18:29 +03:00
|
|
|
-> m Select
|
2021-06-25 16:35:39 +03:00
|
|
|
planNoPlan fromIrConfig userInfo queryDB = do
|
2021-04-12 13:18:29 +03:00
|
|
|
rootField <- traverseQueryDB (prepareValueNoPlan (_uiSession userInfo)) queryDB
|
2021-06-25 16:35:39 +03:00
|
|
|
runValidate (BigQuery.runFromIr fromIrConfig (BigQuery.fromRootField rootField))
|
2021-05-11 18:18:31 +03:00
|
|
|
`onLeft` (E.throw400 E.NotSupported . (tshow :: NonEmpty Error -> Text))
|
2021-04-12 13:18:29 +03:00
|
|
|
|
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
|
|
|
|
2021-04-12 13:18:29 +03:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Resolving values
|
|
|
|
|
|
|
|
-- | Prepare a value without any query planning; we just execute the
|
|
|
|
-- query with the values embedded.
|
|
|
|
prepareValueNoPlan ::
|
2021-05-11 18:18:31 +03:00
|
|
|
(MonadError E.QErr m)
|
2021-04-12 13:18:29 +03:00
|
|
|
=> SessionVariables
|
|
|
|
-> GraphQL.UnpreparedValue 'BigQuery
|
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
|
|
|
-> m Expression
|
2021-04-12 13:18:29 +03:00
|
|
|
prepareValueNoPlan sessionVariables =
|
|
|
|
\case
|
|
|
|
GraphQL.UVLiteral x -> pure x
|
|
|
|
GraphQL.UVSession -> pure globalSessionExpression
|
|
|
|
-- To be honest, I'm not sure if it's indeed the JSON_VALUE operator we need here...
|
|
|
|
GraphQL.UVSessionVar typ text ->
|
|
|
|
case typ of
|
|
|
|
CollectableTypeScalar scalarType ->
|
|
|
|
pure
|
|
|
|
(CastExpression
|
|
|
|
(JsonValueExpression
|
|
|
|
globalSessionExpression
|
|
|
|
(FieldPath RootPath (toTxt text)))
|
|
|
|
scalarType)
|
|
|
|
CollectableTypeArray {} ->
|
2021-05-11 18:18:31 +03:00
|
|
|
throwError $ E.internalError "Cannot currently prepare array types in BigQuery."
|
2021-04-12 13:18:29 +03:00
|
|
|
GraphQL.UVParameter _ RQL.ColumnValue {..} -> pure (ValueExpression cvValue)
|
|
|
|
where
|
|
|
|
globalSessionExpression =
|
|
|
|
ValueExpression
|
|
|
|
(StringValue (LT.toStrict (encodeToLazyText sessionVariables)))
|