2021-04-12 13:18:29 +03:00
|
|
|
-- | Planning T-SQL queries and subscriptions.
|
|
|
|
module Hasura.Backends.BigQuery.Plan
|
|
|
|
( planNoPlan,
|
|
|
|
)
|
2021-06-28 16:29:48 +03:00
|
|
|
where
|
2021-05-11 18:18:31 +03:00
|
|
|
|
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 Data.Text.Lazy qualified as LT
|
|
|
|
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-28 16:29:48 +03:00
|
|
|
import Hasura.Base.Error qualified as E
|
2021-05-11 18:18:31 +03:00
|
|
|
import Hasura.Prelude
|
2021-06-11 06:26:50 +03:00
|
|
|
import Hasura.RQL.IR
|
2021-06-28 16:29:48 +03:00
|
|
|
import Hasura.RQL.Types.Column qualified as RQL
|
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 ->
|
2022-05-31 01:07:02 +03:00
|
|
|
QueryDB 'BigQuery Void (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-07-08 18:41:59 +03:00
|
|
|
rootField <- traverse (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
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- 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 ->
|
2022-05-31 01:07:02 +03:00
|
|
|
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
|
2022-05-31 01:07:02 +03:00
|
|
|
UVLiteral x -> pure x
|
|
|
|
UVSession -> pure globalSessionExpression
|
2021-04-12 13:18:29 +03:00
|
|
|
-- To be honest, I'm not sure if it's indeed the JSON_VALUE operator we need here...
|
2022-05-31 01:07:02 +03:00
|
|
|
UVSessionVar typ text ->
|
2021-04-12 13:18:29 +03:00
|
|
|
case typ of
|
|
|
|
CollectableTypeScalar scalarType ->
|
|
|
|
pure
|
|
|
|
( CastExpression
|
|
|
|
( JsonValueExpression
|
|
|
|
globalSessionExpression
|
|
|
|
(FieldPath RootPath (toTxt text))
|
|
|
|
)
|
|
|
|
scalarType
|
2021-09-24 01:56:37 +03:00
|
|
|
)
|
2021-04-12 13:18:29 +03:00
|
|
|
CollectableTypeArray {} ->
|
2021-05-11 18:18:31 +03:00
|
|
|
throwError $ E.internalError "Cannot currently prepare array types in BigQuery."
|
2022-05-31 01:07:02 +03:00
|
|
|
UVParameter _ RQL.ColumnValue {..} -> pure (ValueExpression cvValue)
|
2021-04-12 13:18:29 +03:00
|
|
|
where
|
|
|
|
globalSessionExpression =
|
|
|
|
ValueExpression
|
|
|
|
(StringValue (LT.toStrict (encodeToLazyText sessionVariables)))
|