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-06-15 18:05:41 +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-07-28 11:09:32 +03:00
|
|
|
import Data.Text.Extended
|
2021-04-12 13:18:29 +03:00
|
|
|
import Hasura.Backends.BigQuery.Types
|
2021-05-11 18:18:31 +03:00
|
|
|
import Hasura.Base.Error
|
2021-04-12 13:18:29 +03:00
|
|
|
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
|
2021-09-24 01:56:37 +03:00
|
|
|
|
2021-04-12 13:18:29 +03:00
|
|
|
parseBoolExpOperations ::
|
|
|
|
forall m v.
|
|
|
|
(MonadError QErr m) =>
|
|
|
|
ValueParser 'BigQuery m v ->
|
2021-04-19 15:16:10 +03:00
|
|
|
TableName ->
|
2021-04-12 13:18:29 +03:00
|
|
|
FieldInfoMap (FieldInfo 'BigQuery) ->
|
2021-07-28 11:09:32 +03:00
|
|
|
ColumnReference 'BigQuery ->
|
2021-04-12 13:18:29 +03:00
|
|
|
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-04-12 13:18:29 +03:00
|
|
|
v -> pure . AEQ False <$> parseWithTy columnType v
|
|
|
|
|
|
|
|
parseOperation :: ColumnType 'BigQuery -> (Text, J.Value) -> m (OpExpG 'BigQuery v)
|
|
|
|
parseOperation columnType (opStr, val) = withPathK opStr $
|
|
|
|
case opStr of
|
|
|
|
"_eq" -> parseEq
|
|
|
|
"$eq" -> parseEq
|
|
|
|
"_neq" -> parseNeq
|
|
|
|
"$neq" -> parseNeq
|
2021-08-06 22:57:37 +03:00
|
|
|
"$in" -> parseIn
|
|
|
|
"_in" -> parseIn
|
|
|
|
"$nin" -> parseNin
|
|
|
|
"_nin" -> parseNin
|
2021-04-12 13:18:29 +03:00
|
|
|
"_gt" -> parseGt
|
|
|
|
"$gt" -> parseGt
|
|
|
|
"_lt" -> parseLt
|
|
|
|
"$lt" -> parseLt
|
|
|
|
"_gte" -> parseGte
|
|
|
|
"$gte" -> parseGte
|
|
|
|
"_lte" -> parseLte
|
|
|
|
"$lte" -> parseLte
|
|
|
|
-- TODO: support column operators
|
|
|
|
|
2022-10-01 17:47:12 +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-08-06 22:57: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
|