From a2bf2fdc8f78a481f7a74ac07b976a4f29a3c92c Mon Sep 17 00:00:00 2001 From: Kirill Zaborsky Date: Thu, 30 Dec 2021 12:59:53 +0300 Subject: [PATCH] Fix aggregates for comparable types in BigQuery PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3211 GitOrigin-RevId: 1a63b0835fc5af687f6caca187968edc9efbb821 --- CHANGELOG.md | 1 + .../src-lib/Hasura/Backends/BigQuery/Types.hs | 19 ++- .../bigquery/select_query_all_types.yaml | 145 +++++++++++++----- 3 files changed, 123 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b90f3b70d22..2f8fbc906a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - server: extend support for insert mutations to tables without primary key constraint in a MSSQL backend - cli: migrate and seed subcommands has an option in prompt to choose and apply operation on all available databases - server: fix parsing FLOAT64s in scientific notation and non-finite ones in BigQuery +- server: extend support for the `min`/`max` aggregates to all comparable types in BigQuery ## v2.1.1 diff --git a/server/src-lib/Hasura/Backends/BigQuery/Types.hs b/server/src-lib/Hasura/Backends/BigQuery/Types.hs index aaae0d15037..e9e4a896536 100644 --- a/server/src-lib/Hasura/Backends/BigQuery/Types.hs +++ b/server/src-lib/Hasura/Backends/BigQuery/Types.hs @@ -869,12 +869,25 @@ parseScalarValue scalarType jValue = case scalarType of parseJValue :: (J.FromJSON a) => J.Value -> Either QErr a parseJValue = runAesonParser J.parseJSON +-- see comparable BigQuery data types in +-- https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types +-- in practice only Geography data type is not comparable +-- as ARRAY isn't a scalar type in the backend isComparableType, isNumType :: ScalarType -> Bool --- TODO: What does this mean? isComparableType = \case - BoolScalarType -> True + StringScalarType -> True BytesScalarType -> True - _ -> False + IntegerScalarType -> True + FloatScalarType -> True + BoolScalarType -> True + TimestampScalarType -> True + DateScalarType -> True + TimeScalarType -> True + DatetimeScalarType -> True + GeographyScalarType -> False + DecimalScalarType -> True + BigDecimalScalarType -> True + StructScalarType -> True isNumType = \case StringScalarType -> False diff --git a/server/tests-py/queries/graphql_query/bigquery/select_query_all_types.yaml b/server/tests-py/queries/graphql_query/bigquery/select_query_all_types.yaml index ceb3b4fc59b..b121640b2c1 100644 --- a/server/tests-py/queries/graphql_query/bigquery/select_query_all_types.yaml +++ b/server/tests-py/queries/graphql_query/bigquery/select_query_all_types.yaml @@ -1,41 +1,108 @@ -description: Simple GraphQL object query on author -url: /v1/graphql -status: 200 -response: - data: - hasura_test_all_types: - - string: STRING - bytes: AAECAwQF - integer: '1' - float: '1.0' - special_floats: - - '1.23E23' - - '-Infinity' - - 'NaN' - numeric: '1' - bignumeric: '1' - boolean: true - timestamp: '2008-12-25T07:30:00Z' - date: '2000-12-30' - time: 07:30:00 - datetime: '1998-10-18T13:45:55' - geography: POINT(1 1) -query: - query: | - query { - hasura_test_all_types { - string - bytes - integer - float +- description: Simple GraphQL select of all types + url: /v1/graphql + status: 200 + response: + data: + hasura_test_all_types: + - string: STRING + bytes: AAECAwQF + integer: '1' + float: '1.0' + special_floats: + - '1.23E23' + - '-Infinity' + - 'NaN' + numeric: '1' + bignumeric: '1' + boolean: true + timestamp: '2008-12-25T07:30:00Z' + date: '2000-12-30' + time: 07:30:00 + datetime: '1998-10-18T13:45:55' + geography: POINT(1 1) + query: + query: | + query { + hasura_test_all_types { + string + bytes + integer + float special_floats - numeric - bignumeric - boolean - timestamp - date - time - datetime - geography + numeric + bignumeric + boolean + timestamp + date + time + datetime + geography + } } - } + +- description: Simple GraphQL aggregate select (min/max) of all comparable types + url: /v1/graphql + status: 200 + response: + data: + hasura_test_all_types_aggregate: + aggregate: + max: + string: STRING + bytes: AAECAwQF + integer: '1' + float: '1.0' + numeric: '1' + bignumeric: '1' + boolean: true + timestamp: '2008-12-25T07:30:00Z' + date: '2000-12-30' + time: '07:30:00' + datetime: '1998-10-18T13:45:55' + min: + string: STRING + bytes: AAECAwQF + integer: '1' + float: '1.0' + numeric: '1' + bignumeric: '1' + boolean: true + timestamp: '2008-12-25T07:30:00Z' + date: '2000-12-30' + time: '07:30:00' + datetime: '1998-10-18T13:45:55' + query: + query: | + query { + hasura_test_all_types_aggregate { + aggregate { + max { + string + bytes + integer + float + numeric + bignumeric + boolean + timestamp + date + time + datetime + } + min { + string + bytes + integer + float + numeric + bignumeric + boolean + timestamp + date + time + datetime + } + } + } + } +