2021-11-04 19:08:33 +03:00
|
|
|
module Hasura.Backends.BigQuery.DDL.BoolExp
|
|
|
|
( parseBoolExpOperations,
|
|
|
|
)
|
|
|
|
where
|
2021-04-12 13:18:29 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
import Data.Aeson qualified as J
|
2022-06-08 18:31:28 +03:00
|
|
|
import Data.Aeson.Key qualified as K
|
|
|
|
import Data.Aeson.KeyMap qualified as KM
|
2021-09-24 01:56:37 +03:00
|
|
|
import Data.Text.Extended
|
|
|
|
import Hasura.Backends.BigQuery.Types
|
|
|
|
import Hasura.Base.Error
|
|
|
|
import Hasura.Prelude
|
|
|
|
import Hasura.RQL.IR.BoolExp
|
|
|
|
import Hasura.RQL.Types.Column
|
|
|
|
import Hasura.RQL.Types.SchemaCache
|
|
|
|
import Hasura.SQL.Backend
|
|
|
|
import Hasura.SQL.Types
|
|
|
|
|
|
|
|
parseBoolExpOperations ::
|
|
|
|
forall m v.
|
|
|
|
(MonadError QErr m) =>
|
|
|
|
ValueParser 'BigQuery m v ->
|
|
|
|
TableName ->
|
|
|
|
FieldInfoMap (FieldInfo 'BigQuery) ->
|
|
|
|
ColumnReference 'BigQuery ->
|
|
|
|
J.Value ->
|
|
|
|
m [OpExpG 'BigQuery v]
|
2021-07-28 11:09:32 +03:00
|
|
|
parseBoolExpOperations rhsParser _table _fields columnRef value =
|
|
|
|
withPathK (toTxt columnRef) $ parseOperations (columnReferenceType columnRef) value
|
2021-04-12 13:18:29 +03:00
|
|
|
where
|
|
|
|
parseWithTy ty = rhsParser (CollectableTypeScalar ty)
|
|
|
|
|
|
|
|
parseOperations :: ColumnType 'BigQuery -> J.Value -> m [OpExpG 'BigQuery v]
|
|
|
|
parseOperations columnType = \case
|
2022-06-08 18:31:28 +03:00
|
|
|
J.Object o -> mapM (parseOperation columnType . first K.toText) $ KM.toList o
|
2021-09-24 01:56:37 +03:00
|
|
|
v -> pure . AEQ False <$> parseWithTy columnType v
|
2021-04-12 13:18:29 +03:00
|
|
|
|
|
|
|
parseOperation :: ColumnType 'BigQuery -> (Text, J.Value) -> m (OpExpG 'BigQuery v)
|
|
|
|
parseOperation columnType (opStr, val) = withPathK opStr $
|
|
|
|
case opStr of
|
2021-09-24 01:56:37 +03:00
|
|
|
"_eq" -> parseEq
|
|
|
|
"$eq" -> parseEq
|
2021-04-12 13:18:29 +03:00
|
|
|
"_neq" -> parseNeq
|
|
|
|
"$neq" -> parseNeq
|
2021-09-24 01:56:37 +03:00
|
|
|
"$in" -> parseIn
|
|
|
|
"_in" -> parseIn
|
2021-08-06 22:57:37 +03:00
|
|
|
"$nin" -> parseNin
|
|
|
|
"_nin" -> parseNin
|
2021-09-24 01:56:37 +03:00
|
|
|
"_gt" -> parseGt
|
|
|
|
"$gt" -> parseGt
|
|
|
|
"_lt" -> parseLt
|
|
|
|
"$lt" -> parseLt
|
2021-04-12 13:18:29 +03:00
|
|
|
"_gte" -> parseGte
|
|
|
|
"$gte" -> parseGte
|
|
|
|
"_lte" -> parseLte
|
|
|
|
"$lte" -> parseLte
|
|
|
|
-- TODO: support column operators
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
x -> throw400 UnexpectedPayload $ "Unknown operator : " <> x
|
2021-04-12 13:18:29 +03:00
|
|
|
where
|
2021-08-06 22:57:37 +03:00
|
|
|
colTy = columnReferenceType columnRef
|
2021-04-12 13:18:29 +03:00
|
|
|
parseOne = parseWithTy columnType val
|
2021-08-06 22:57:37 +03:00
|
|
|
parseManyWithType ty = rhsParser (CollectableTypeArray ty) val
|
2021-04-12 13:18:29 +03:00
|
|
|
|
|
|
|
parseEq = AEQ False <$> parseOne
|
|
|
|
parseNeq = ANE False <$> parseOne
|
2021-09-24 01:56:37 +03:00
|
|
|
parseIn = AIN <$> parseManyWithType colTy
|
|
|
|
parseNin = ANIN <$> parseManyWithType colTy
|
2021-04-12 13:18:29 +03:00
|
|
|
parseGt = AGT <$> parseOne
|
|
|
|
parseLt = ALT <$> parseOne
|
|
|
|
parseGte = AGTE <$> parseOne
|
|
|
|
parseLte = ALTE <$> parseOne
|