2021-04-12 13:18:29 +03:00
|
|
|
module Hasura.Backends.BigQuery.DDL.BoolExp where
|
|
|
|
|
|
|
|
import Hasura.Prelude
|
|
|
|
|
2021-06-15 18:05:41 +03:00
|
|
|
import qualified Data.Aeson as J
|
|
|
|
import qualified Data.HashMap.Strict as Map
|
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.RQL.IR.BoolExp
|
|
|
|
import Hasura.RQL.Types.Column
|
|
|
|
import Hasura.RQL.Types.SchemaCache
|
|
|
|
import Hasura.SQL.Backend
|
|
|
|
import Hasura.SQL.Types
|
|
|
|
|
2021-05-11 18:18:31 +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)
|
|
|
|
-> ColumnInfo 'BigQuery
|
|
|
|
-> J.Value
|
|
|
|
-> m [OpExpG 'BigQuery v]
|
2021-04-19 15:16:10 +03:00
|
|
|
parseBoolExpOperations rhsParser _table _fields columnInfo value =
|
2021-04-12 13:18:29 +03:00
|
|
|
withPathK (columnName $ pgiColumn columnInfo) $
|
|
|
|
parseOperations (pgiType columnInfo) value
|
|
|
|
where
|
|
|
|
parseWithTy ty = rhsParser (CollectableTypeScalar ty)
|
|
|
|
|
|
|
|
parseOperations :: ColumnType 'BigQuery -> J.Value -> m [OpExpG 'BigQuery v]
|
|
|
|
parseOperations columnType = \case
|
|
|
|
J.Object o -> mapM (parseOperation columnType) $ Map.toList o
|
|
|
|
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
|
|
|
|
|
|
|
|
"_gt" -> parseGt
|
|
|
|
"$gt" -> parseGt
|
|
|
|
|
|
|
|
"_lt" -> parseLt
|
|
|
|
"$lt" -> parseLt
|
|
|
|
|
|
|
|
"_gte" -> parseGte
|
|
|
|
"$gte" -> parseGte
|
|
|
|
|
|
|
|
"_lte" -> parseLte
|
|
|
|
"$lte" -> parseLte
|
|
|
|
|
|
|
|
-- TODO: support column operators
|
|
|
|
|
|
|
|
x -> throw400 UnexpectedPayload $ "Unknown operator : " <> x
|
|
|
|
|
|
|
|
where
|
|
|
|
parseOne = parseWithTy columnType val
|
|
|
|
|
|
|
|
parseEq = AEQ False <$> parseOne
|
|
|
|
parseNeq = ANE False <$> parseOne
|
|
|
|
parseGt = AGT <$> parseOne
|
|
|
|
parseLt = ALT <$> parseOne
|
|
|
|
parseGte = AGTE <$> parseOne
|
|
|
|
parseLte = ALTE <$> parseOne
|