mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-13 19:33:55 +03:00
Rename DataConnector cross_table capability to subquery
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5980 GitOrigin-RevId: c289b2a7afb4d07214aac2b4d89c9b87a75e98aa
This commit is contained in:
parent
7365838f76
commit
3365a18516
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hasura/dc-api-types",
|
"name": "@hasura/dc-api-types",
|
||||||
"version": "0.6.0",
|
"version": "0.7.0",
|
||||||
"description": "Hasura GraphQL Engine Data Connector Agent API types",
|
"description": "Hasura GraphQL Engine Data Connector Agent API types",
|
||||||
"author": "Hasura (https://github.com/hasura/graphql-engine)",
|
"author": "Hasura (https://github.com/hasura/graphql-engine)",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
@ -294,7 +294,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"RelationshipCapabilities": {},
|
"RelationshipCapabilities": {},
|
||||||
"CrossTableComparisonCapabilities": {
|
"SubqueryComparisonCapabilities": {
|
||||||
"nullable": true,
|
"nullable": true,
|
||||||
"properties": {
|
"properties": {
|
||||||
"supports_relations": {
|
"supports_relations": {
|
||||||
@ -309,8 +309,8 @@
|
|||||||
},
|
},
|
||||||
"ComparisonCapabilities": {
|
"ComparisonCapabilities": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"cross_table": {
|
"subquery": {
|
||||||
"$ref": "#/components/schemas/CrossTableComparisonCapabilities"
|
"$ref": "#/components/schemas/SubqueryComparisonCapabilities"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"type": "object"
|
"type": "object"
|
||||||
|
@ -21,7 +21,6 @@ export type { ComparisonColumn } from './models/ComparisonColumn';
|
|||||||
export type { ComparisonValue } from './models/ComparisonValue';
|
export type { ComparisonValue } from './models/ComparisonValue';
|
||||||
export type { ConfigSchemaResponse } from './models/ConfigSchemaResponse';
|
export type { ConfigSchemaResponse } from './models/ConfigSchemaResponse';
|
||||||
export type { Constraint } from './models/Constraint';
|
export type { Constraint } from './models/Constraint';
|
||||||
export type { CrossTableComparisonCapabilities } from './models/CrossTableComparisonCapabilities';
|
|
||||||
export type { ExistsExpression } from './models/ExistsExpression';
|
export type { ExistsExpression } from './models/ExistsExpression';
|
||||||
export type { ExistsInTable } from './models/ExistsInTable';
|
export type { ExistsInTable } from './models/ExistsInTable';
|
||||||
export type { ExplainCapabilities } from './models/ExplainCapabilities';
|
export type { ExplainCapabilities } from './models/ExplainCapabilities';
|
||||||
@ -65,6 +64,7 @@ export type { SchemaResponse } from './models/SchemaResponse';
|
|||||||
export type { SingleColumnAggregate } from './models/SingleColumnAggregate';
|
export type { SingleColumnAggregate } from './models/SingleColumnAggregate';
|
||||||
export type { SingleColumnAggregateFunction } from './models/SingleColumnAggregateFunction';
|
export type { SingleColumnAggregateFunction } from './models/SingleColumnAggregateFunction';
|
||||||
export type { StarCountAggregate } from './models/StarCountAggregate';
|
export type { StarCountAggregate } from './models/StarCountAggregate';
|
||||||
|
export type { SubqueryComparisonCapabilities } from './models/SubqueryComparisonCapabilities';
|
||||||
export type { SubscriptionCapabilities } from './models/SubscriptionCapabilities';
|
export type { SubscriptionCapabilities } from './models/SubscriptionCapabilities';
|
||||||
export type { TableInfo } from './models/TableInfo';
|
export type { TableInfo } from './models/TableInfo';
|
||||||
export type { TableName } from './models/TableName';
|
export type { TableName } from './models/TableName';
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
/* tslint:disable */
|
/* tslint:disable */
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
|
|
||||||
import type { CrossTableComparisonCapabilities } from './CrossTableComparisonCapabilities';
|
import type { SubqueryComparisonCapabilities } from './SubqueryComparisonCapabilities';
|
||||||
|
|
||||||
export type ComparisonCapabilities = {
|
export type ComparisonCapabilities = {
|
||||||
cross_table?: CrossTableComparisonCapabilities;
|
subquery?: SubqueryComparisonCapabilities;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
/* tslint:disable */
|
/* tslint:disable */
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
|
|
||||||
export type CrossTableComparisonCapabilities = {
|
export type SubqueryComparisonCapabilities = {
|
||||||
/**
|
/**
|
||||||
* Does the agent support comparisons that involve related tables (ie. joins)?
|
* Does the agent support comparisons that involve related tables (ie. joins)?
|
||||||
*/
|
*/
|
10
dc-agents/package-lock.json
generated
10
dc-agents/package-lock.json
generated
@ -24,7 +24,7 @@
|
|||||||
},
|
},
|
||||||
"dc-api-types": {
|
"dc-api-types": {
|
||||||
"name": "@hasura/dc-api-types",
|
"name": "@hasura/dc-api-types",
|
||||||
"version": "0.6.0",
|
"version": "0.7.0",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tsconfig/node16": "^1.0.3",
|
"@tsconfig/node16": "^1.0.3",
|
||||||
@ -631,7 +631,7 @@
|
|||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fastify/cors": "^7.0.0",
|
"@fastify/cors": "^7.0.0",
|
||||||
"@hasura/dc-api-types": "0.6.0",
|
"@hasura/dc-api-types": "0.7.0",
|
||||||
"fastify": "^3.29.0",
|
"fastify": "^3.29.0",
|
||||||
"mathjs": "^11.0.0",
|
"mathjs": "^11.0.0",
|
||||||
"pino-pretty": "^8.0.0",
|
"pino-pretty": "^8.0.0",
|
||||||
@ -1389,7 +1389,7 @@
|
|||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fastify/cors": "^8.1.0",
|
"@fastify/cors": "^8.1.0",
|
||||||
"@hasura/dc-api-types": "0.6.0",
|
"@hasura/dc-api-types": "0.7.0",
|
||||||
"fastify": "^4.4.0",
|
"fastify": "^4.4.0",
|
||||||
"fastify-metrics": "^9.2.1",
|
"fastify-metrics": "^9.2.1",
|
||||||
"nanoid": "^3.3.4",
|
"nanoid": "^3.3.4",
|
||||||
@ -3127,7 +3127,7 @@
|
|||||||
"version": "file:reference",
|
"version": "file:reference",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@fastify/cors": "^7.0.0",
|
"@fastify/cors": "^7.0.0",
|
||||||
"@hasura/dc-api-types": "0.6.0",
|
"@hasura/dc-api-types": "0.7.0",
|
||||||
"@tsconfig/node16": "^1.0.3",
|
"@tsconfig/node16": "^1.0.3",
|
||||||
"@types/node": "^16.11.49",
|
"@types/node": "^16.11.49",
|
||||||
"@types/xml2js": "^0.4.11",
|
"@types/xml2js": "^0.4.11",
|
||||||
@ -3618,7 +3618,7 @@
|
|||||||
"version": "file:sqlite",
|
"version": "file:sqlite",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@fastify/cors": "^8.1.0",
|
"@fastify/cors": "^8.1.0",
|
||||||
"@hasura/dc-api-types": "0.6.0",
|
"@hasura/dc-api-types": "0.7.0",
|
||||||
"@tsconfig/node16": "^1.0.3",
|
"@tsconfig/node16": "^1.0.3",
|
||||||
"@types/node": "^16.11.49",
|
"@types/node": "^16.11.49",
|
||||||
"@types/sqlite3": "^3.1.8",
|
"@types/sqlite3": "^3.1.8",
|
||||||
|
4
dc-agents/reference/package-lock.json
generated
4
dc-agents/reference/package-lock.json
generated
@ -10,7 +10,7 @@
|
|||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fastify/cors": "^7.0.0",
|
"@fastify/cors": "^7.0.0",
|
||||||
"@hasura/dc-api-types": "0.6.0",
|
"@hasura/dc-api-types": "0.7.0",
|
||||||
"fastify": "^3.29.0",
|
"fastify": "^3.29.0",
|
||||||
"mathjs": "^11.0.0",
|
"mathjs": "^11.0.0",
|
||||||
"pino-pretty": "^8.0.0",
|
"pino-pretty": "^8.0.0",
|
||||||
@ -44,7 +44,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@hasura/dc-api-types": {
|
"node_modules/@hasura/dc-api-types": {
|
||||||
"version": "0.6.0",
|
"version": "0.7.0",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tsconfig/node16": "^1.0.3",
|
"@tsconfig/node16": "^1.0.3",
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fastify/cors": "^7.0.0",
|
"@fastify/cors": "^7.0.0",
|
||||||
"@hasura/dc-api-types": "0.6.0",
|
"@hasura/dc-api-types": "0.7.0",
|
||||||
"fastify": "^3.29.0",
|
"fastify": "^3.29.0",
|
||||||
"mathjs": "^11.0.0",
|
"mathjs": "^11.0.0",
|
||||||
"pino-pretty": "^8.0.0",
|
"pino-pretty": "^8.0.0",
|
||||||
|
@ -20,7 +20,7 @@ const scalarTypes: ScalarTypesCapabilities = {
|
|||||||
const capabilities: Capabilities = {
|
const capabilities: Capabilities = {
|
||||||
relationships: {},
|
relationships: {},
|
||||||
comparisons: {
|
comparisons: {
|
||||||
cross_table: {
|
subquery: {
|
||||||
supports_relations: true
|
supports_relations: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
4
dc-agents/sqlite/package-lock.json
generated
4
dc-agents/sqlite/package-lock.json
generated
@ -10,7 +10,7 @@
|
|||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fastify/cors": "^8.1.0",
|
"@fastify/cors": "^8.1.0",
|
||||||
"@hasura/dc-api-types": "0.6.0",
|
"@hasura/dc-api-types": "0.7.0",
|
||||||
"fastify": "^4.4.0",
|
"fastify": "^4.4.0",
|
||||||
"fastify-metrics": "^9.2.1",
|
"fastify-metrics": "^9.2.1",
|
||||||
"nanoid": "^3.3.4",
|
"nanoid": "^3.3.4",
|
||||||
@ -55,7 +55,7 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@hasura/dc-api-types": {
|
"node_modules/@hasura/dc-api-types": {
|
||||||
"version": "0.6.0",
|
"version": "0.7.0",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tsconfig/node16": "^1.0.3",
|
"@tsconfig/node16": "^1.0.3",
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fastify/cors": "^8.1.0",
|
"@fastify/cors": "^8.1.0",
|
||||||
"@hasura/dc-api-types": "0.6.0",
|
"@hasura/dc-api-types": "0.7.0",
|
||||||
"fastify-metrics": "^9.2.1",
|
"fastify-metrics": "^9.2.1",
|
||||||
"fastify": "^4.4.0",
|
"fastify": "^4.4.0",
|
||||||
"nanoid": "^3.3.4",
|
"nanoid": "^3.3.4",
|
||||||
|
@ -10,7 +10,7 @@ export const capabilitiesResponse: CapabilitiesResponse = {
|
|||||||
},
|
},
|
||||||
relationships: {},
|
relationships: {},
|
||||||
comparisons: {
|
comparisons: {
|
||||||
cross_table: {
|
subquery: {
|
||||||
supports_relations: true
|
supports_relations: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -14,7 +14,7 @@ module Hasura.Backends.DataConnector.API.V0.Capabilities
|
|||||||
GraphQLTypeDefinitions,
|
GraphQLTypeDefinitions,
|
||||||
RelationshipCapabilities (..),
|
RelationshipCapabilities (..),
|
||||||
ComparisonCapabilities (..),
|
ComparisonCapabilities (..),
|
||||||
CrossTableComparisonCapabilities (..),
|
SubqueryComparisonCapabilities (..),
|
||||||
MetricsCapabilities (..),
|
MetricsCapabilities (..),
|
||||||
ExplainCapabilities (..),
|
ExplainCapabilities (..),
|
||||||
CapabilitiesResponse (..),
|
CapabilitiesResponse (..),
|
||||||
@ -224,7 +224,7 @@ instance HasCodec GraphQLTypeDefinitions where
|
|||||||
. _gtdTypeDefinitions
|
. _gtdTypeDefinitions
|
||||||
|
|
||||||
data ComparisonCapabilities = ComparisonCapabilities
|
data ComparisonCapabilities = ComparisonCapabilities
|
||||||
{_ccCrossTableComparisonCapabilities :: Maybe CrossTableComparisonCapabilities}
|
{_ccSubqueryComparisonCapabilities :: Maybe SubqueryComparisonCapabilities}
|
||||||
deriving stock (Eq, Ord, Show, Generic, Data)
|
deriving stock (Eq, Ord, Show, Generic, Data)
|
||||||
deriving anyclass (NFData, Hashable)
|
deriving anyclass (NFData, Hashable)
|
||||||
deriving (FromJSON, ToJSON, ToSchema) via Autodocodec ComparisonCapabilities
|
deriving (FromJSON, ToJSON, ToSchema) via Autodocodec ComparisonCapabilities
|
||||||
@ -233,18 +233,18 @@ instance HasCodec ComparisonCapabilities where
|
|||||||
codec =
|
codec =
|
||||||
object "ComparisonCapabilities" $
|
object "ComparisonCapabilities" $
|
||||||
ComparisonCapabilities
|
ComparisonCapabilities
|
||||||
<$> optionalFieldOrNull "cross_table" "The agent supports comparisons that involve tables other than the one being queried" .= _ccCrossTableComparisonCapabilities
|
<$> optionalFieldOrNull "subquery" "The agent supports comparisons that involve tables other than the one being queried" .= _ccSubqueryComparisonCapabilities
|
||||||
|
|
||||||
data CrossTableComparisonCapabilities = CrossTableComparisonCapabilities
|
data SubqueryComparisonCapabilities = SubqueryComparisonCapabilities
|
||||||
{_ctccSupportsRelations :: Bool}
|
{_ctccSupportsRelations :: Bool}
|
||||||
deriving stock (Eq, Ord, Show, Generic, Data)
|
deriving stock (Eq, Ord, Show, Generic, Data)
|
||||||
deriving anyclass (NFData, Hashable)
|
deriving anyclass (NFData, Hashable)
|
||||||
deriving (FromJSON, ToJSON, ToSchema) via Autodocodec CrossTableComparisonCapabilities
|
deriving (FromJSON, ToJSON, ToSchema) via Autodocodec SubqueryComparisonCapabilities
|
||||||
|
|
||||||
instance HasCodec CrossTableComparisonCapabilities where
|
instance HasCodec SubqueryComparisonCapabilities where
|
||||||
codec =
|
codec =
|
||||||
object "CrossTableComparisonCapabilities" $
|
object "SubqueryComparisonCapabilities" $
|
||||||
CrossTableComparisonCapabilities
|
SubqueryComparisonCapabilities
|
||||||
<$> requiredField "supports_relations" "Does the agent support comparisons that involve related tables (ie. joins)?" .= _ctccSupportsRelations
|
<$> requiredField "supports_relations" "Does the agent support comparisons that involve related tables (ie. joins)?" .= _ctccSupportsRelations
|
||||||
|
|
||||||
data MetricsCapabilities = MetricsCapabilities {}
|
data MetricsCapabilities = MetricsCapabilities {}
|
||||||
|
@ -120,11 +120,11 @@ genRelationshipCapabilities = pure RelationshipCapabilities {}
|
|||||||
genComparisonCapabilities :: MonadGen m => m ComparisonCapabilities
|
genComparisonCapabilities :: MonadGen m => m ComparisonCapabilities
|
||||||
genComparisonCapabilities =
|
genComparisonCapabilities =
|
||||||
ComparisonCapabilities
|
ComparisonCapabilities
|
||||||
<$> Gen.maybe genCrossTableComparisonCapabilities
|
<$> Gen.maybe genSubqueryComparisonCapabilities
|
||||||
|
|
||||||
genCrossTableComparisonCapabilities :: MonadGen m => m CrossTableComparisonCapabilities
|
genSubqueryComparisonCapabilities :: MonadGen m => m SubqueryComparisonCapabilities
|
||||||
genCrossTableComparisonCapabilities =
|
genSubqueryComparisonCapabilities =
|
||||||
CrossTableComparisonCapabilities
|
SubqueryComparisonCapabilities
|
||||||
<$> Gen.bool
|
<$> Gen.bool
|
||||||
|
|
||||||
genMetricsCapabilities :: MonadGen m => m MetricsCapabilities
|
genMetricsCapabilities :: MonadGen m => m MetricsCapabilities
|
||||||
|
@ -2,7 +2,7 @@ module Test.QuerySpec (spec) where
|
|||||||
|
|
||||||
import Control.Monad (when)
|
import Control.Monad (when)
|
||||||
import Data.Maybe (isJust)
|
import Data.Maybe (isJust)
|
||||||
import Hasura.Backends.DataConnector.API (Capabilities (..), ComparisonCapabilities (_ccCrossTableComparisonCapabilities), Config, Routes (..), SourceName)
|
import Hasura.Backends.DataConnector.API (Capabilities (..), ComparisonCapabilities (..), Config, Routes (..), SourceName)
|
||||||
import Servant.API (NamedRoutes)
|
import Servant.API (NamedRoutes)
|
||||||
import Servant.Client (Client)
|
import Servant.Client (Client)
|
||||||
import Test.Hspec
|
import Test.Hspec
|
||||||
@ -20,5 +20,5 @@ spec api sourceName config capabilities@Capabilities {..} = do
|
|||||||
Test.QuerySpec.FilteringSpec.spec api sourceName config _cComparisons
|
Test.QuerySpec.FilteringSpec.spec api sourceName config _cComparisons
|
||||||
Test.QuerySpec.OrderBySpec.spec api sourceName config capabilities
|
Test.QuerySpec.OrderBySpec.spec api sourceName config capabilities
|
||||||
when (isJust _cRelationships) $
|
when (isJust _cRelationships) $
|
||||||
Test.QuerySpec.RelationshipsSpec.spec api sourceName config (_cComparisons >>= _ccCrossTableComparisonCapabilities)
|
Test.QuerySpec.RelationshipsSpec.spec api sourceName config (_cComparisons >>= _ccSubqueryComparisonCapabilities)
|
||||||
Test.QuerySpec.AggregatesSpec.spec api sourceName config _cRelationships
|
Test.QuerySpec.AggregatesSpec.spec api sourceName config _cRelationships
|
||||||
|
@ -163,7 +163,7 @@ spec api sourceName config comparisonCapabilities = describe "Filtering in Queri
|
|||||||
Data.responseRows receivedAlbums `rowsShouldBe` expectedAlbums
|
Data.responseRows receivedAlbums `rowsShouldBe` expectedAlbums
|
||||||
_qrAggregates receivedAlbums `jsonShouldBe` Nothing
|
_qrAggregates receivedAlbums `jsonShouldBe` Nothing
|
||||||
|
|
||||||
when (isJust $ comparisonCapabilities >>= _ccCrossTableComparisonCapabilities) $
|
when (isJust $ comparisonCapabilities >>= _ccSubqueryComparisonCapabilities) $
|
||||||
describe "Comparisons in unrelated tables" $ do
|
describe "Comparisons in unrelated tables" $ do
|
||||||
describe "can filter with a condition that requires that matching rows exist in another unrelated table" $ do
|
describe "can filter with a condition that requires that matching rows exist in another unrelated table" $ do
|
||||||
describe "compare against a single column" $ do
|
describe "compare against a single column" $ do
|
||||||
@ -218,92 +218,92 @@ spec api sourceName config comparisonCapabilities = describe "Filtering in Queri
|
|||||||
Data.responseRows receivedAlbums `rowsShouldBe` []
|
Data.responseRows receivedAlbums `rowsShouldBe` []
|
||||||
_qrAggregates receivedAlbums `jsonShouldBe` Nothing
|
_qrAggregates receivedAlbums `jsonShouldBe` Nothing
|
||||||
|
|
||||||
when ((comparisonCapabilities >>= _ccCrossTableComparisonCapabilities <&> _ctccSupportsRelations) == Just True) $
|
when ((comparisonCapabilities >>= _ccSubqueryComparisonCapabilities <&> _ctccSupportsRelations) == Just True) $
|
||||||
describe "Comparisons in related tables" $ do
|
describe "Comparisons in related tables" $ do
|
||||||
it "can filter by comparing against rows in a related table" $ do
|
it "can filter by comparing against rows in a related table" $ do
|
||||||
let where' =
|
let where' =
|
||||||
Exists (RelatedTable Data.artistRelationshipName) $
|
Exists (RelatedTable Data.artistRelationshipName) $
|
||||||
ApplyBinaryComparisonOperator Equal (Data.currentComparisonColumn "Name") (ScalarValue (String "AC/DC"))
|
ApplyBinaryComparisonOperator Equal (Data.currentComparisonColumn "Name") (ScalarValue (String "AC/DC"))
|
||||||
let query =
|
let query =
|
||||||
albumsQueryRequest
|
albumsQueryRequest
|
||||||
& qrTableRelationships .~ [Data.onlyKeepRelationships [Data.artistRelationshipName] Data.albumsTableRelationships]
|
& qrTableRelationships .~ [Data.onlyKeepRelationships [Data.artistRelationshipName] Data.albumsTableRelationships]
|
||||||
& qrQuery . qWhere ?~ where'
|
& qrQuery . qWhere ?~ where'
|
||||||
receivedAlbums <- Data.sortResponseRowsBy "AlbumId" <$> (api // _query) sourceName config query
|
receivedAlbums <- Data.sortResponseRowsBy "AlbumId" <$> (api // _query) sourceName config query
|
||||||
|
|
||||||
let artistId =
|
let artistId =
|
||||||
Data.artistsRows
|
Data.artistsRows
|
||||||
& find (\artist -> (artist ^? Data.field "Name" . Data._ColumnFieldString) == Just "AC/DC")
|
& find (\artist -> (artist ^? Data.field "Name" . Data._ColumnFieldString) == Just "AC/DC")
|
||||||
>>= (^? Data.field "ArtistId" . Data._ColumnFieldNumber)
|
>>= (^? Data.field "ArtistId" . Data._ColumnFieldNumber)
|
||||||
|
|
||||||
let albums =
|
let albums =
|
||||||
Data.albumsRows
|
Data.albumsRows
|
||||||
& filter (\album -> (album ^? Data.field "ArtistId" . Data._ColumnFieldNumber) == artistId)
|
& filter (\album -> (album ^? Data.field "ArtistId" . Data._ColumnFieldNumber) == artistId)
|
||||||
& sortOn (^? Data.field "AlbumId")
|
& sortOn (^? Data.field "AlbumId")
|
||||||
|
|
||||||
Data.responseRows receivedAlbums `rowsShouldBe` albums
|
Data.responseRows receivedAlbums `rowsShouldBe` albums
|
||||||
_qrAggregates receivedAlbums `jsonShouldBe` Nothing
|
_qrAggregates receivedAlbums `jsonShouldBe` Nothing
|
||||||
|
|
||||||
it "can filter by comparing against rows in a deeply related table" $ do
|
it "can filter by comparing against rows in a deeply related table" $ do
|
||||||
let where' =
|
let where' =
|
||||||
Exists (RelatedTable Data.albumsRelationshipName) . Exists (RelatedTable Data.tracksRelationshipName) . Exists (RelatedTable Data.genreRelationshipName) $
|
Exists (RelatedTable Data.albumsRelationshipName) . Exists (RelatedTable Data.tracksRelationshipName) . Exists (RelatedTable Data.genreRelationshipName) $
|
||||||
ApplyBinaryComparisonOperator Equal (Data.currentComparisonColumn "Name") (ScalarValue (String "Metal"))
|
ApplyBinaryComparisonOperator Equal (Data.currentComparisonColumn "Name") (ScalarValue (String "Metal"))
|
||||||
let query =
|
let query =
|
||||||
artistsQueryRequest
|
artistsQueryRequest
|
||||||
& qrTableRelationships
|
& qrTableRelationships
|
||||||
.~ [ Data.onlyKeepRelationships [Data.albumsRelationshipName] Data.artistsTableRelationships,
|
.~ [ Data.onlyKeepRelationships [Data.albumsRelationshipName] Data.artistsTableRelationships,
|
||||||
Data.onlyKeepRelationships [Data.tracksRelationshipName] Data.albumsTableRelationships,
|
Data.onlyKeepRelationships [Data.tracksRelationshipName] Data.albumsTableRelationships,
|
||||||
Data.onlyKeepRelationships [Data.genreRelationshipName] Data.tracksTableRelationships
|
Data.onlyKeepRelationships [Data.genreRelationshipName] Data.tracksTableRelationships
|
||||||
]
|
]
|
||||||
& qrQuery . qWhere ?~ where'
|
& qrQuery . qWhere ?~ where'
|
||||||
receivedArtists <- Data.sortResponseRowsBy "ArtistId" <$> (api // _query) sourceName config query
|
receivedArtists <- Data.sortResponseRowsBy "ArtistId" <$> (api // _query) sourceName config query
|
||||||
|
|
||||||
let genreId =
|
let genreId =
|
||||||
Data.genresRows
|
Data.genresRows
|
||||||
& find (\genre -> (genre ^? Data.field "Name" . Data._ColumnFieldString) == Just "Metal")
|
& find (\genre -> (genre ^? Data.field "Name" . Data._ColumnFieldString) == Just "Metal")
|
||||||
>>= (^? Data.field "GenreId" . Data._ColumnFieldNumber)
|
>>= (^? Data.field "GenreId" . Data._ColumnFieldNumber)
|
||||||
|
|
||||||
let albumIds =
|
let albumIds =
|
||||||
Data.tracksRows
|
Data.tracksRows
|
||||||
& filter (\track -> (track ^? Data.field "GenreId" . Data._ColumnFieldNumber) == genreId)
|
& filter (\track -> (track ^? Data.field "GenreId" . Data._ColumnFieldNumber) == genreId)
|
||||||
& map (\track -> (track ^? Data.field "AlbumId" . Data._ColumnFieldNumber))
|
& map (\track -> (track ^? Data.field "AlbumId" . Data._ColumnFieldNumber))
|
||||||
& HashSet.fromList
|
& HashSet.fromList
|
||||||
|
|
||||||
let artists =
|
let artists =
|
||||||
Data.albumsRows
|
Data.albumsRows
|
||||||
& filter (\album -> HashSet.member (album ^? Data.field "AlbumId" . Data._ColumnFieldNumber) albumIds)
|
& filter (\album -> HashSet.member (album ^? Data.field "AlbumId" . Data._ColumnFieldNumber) albumIds)
|
||||||
& mapMaybe (\album -> album ^? Data.field "ArtistId" . Data._ColumnFieldNumber)
|
& mapMaybe (\album -> album ^? Data.field "ArtistId" . Data._ColumnFieldNumber)
|
||||||
& HashSet.fromList
|
& HashSet.fromList
|
||||||
& HashSet.toList
|
& HashSet.toList
|
||||||
& mapMaybe (\artistId -> HashMap.lookup artistId Data.artistsRowsById)
|
& mapMaybe (\artistId -> HashMap.lookup artistId Data.artistsRowsById)
|
||||||
& sortOn (^? Data.field "ArtistId")
|
& sortOn (^? Data.field "ArtistId")
|
||||||
|
|
||||||
Data.responseRows receivedArtists `rowsShouldBe` artists
|
Data.responseRows receivedArtists `rowsShouldBe` artists
|
||||||
_qrAggregates receivedArtists `jsonShouldBe` Nothing
|
_qrAggregates receivedArtists `jsonShouldBe` Nothing
|
||||||
|
|
||||||
it "can filter by comparing against multiple columns in a related table" $ do
|
it "can filter by comparing against multiple columns in a related table" $ do
|
||||||
let where' =
|
let where' =
|
||||||
Exists (RelatedTable Data.albumsRelationshipName) $
|
Exists (RelatedTable Data.albumsRelationshipName) $
|
||||||
And
|
And
|
||||||
[ ApplyBinaryComparisonOperator Equal (Data.currentComparisonColumn "AlbumId") (ScalarValue (Number 1)),
|
[ ApplyBinaryComparisonOperator Equal (Data.currentComparisonColumn "AlbumId") (ScalarValue (Number 1)),
|
||||||
ApplyBinaryComparisonOperator Equal (Data.currentComparisonColumn "Title") (ScalarValue (String "Let There Be Rock"))
|
ApplyBinaryComparisonOperator Equal (Data.currentComparisonColumn "Title") (ScalarValue (String "Let There Be Rock"))
|
||||||
]
|
]
|
||||||
let query =
|
let query =
|
||||||
artistsQueryRequest
|
artistsQueryRequest
|
||||||
& qrTableRelationships .~ [Data.onlyKeepRelationships [Data.albumsRelationshipName] Data.artistsTableRelationships]
|
& qrTableRelationships .~ [Data.onlyKeepRelationships [Data.albumsRelationshipName] Data.artistsTableRelationships]
|
||||||
& qrQuery . qWhere ?~ where'
|
& qrQuery . qWhere ?~ where'
|
||||||
receivedArtists <- Data.sortResponseRowsBy "ArtistId" <$> (api // _query) sourceName config query
|
receivedArtists <- Data.sortResponseRowsBy "ArtistId" <$> (api // _query) sourceName config query
|
||||||
|
|
||||||
let albums =
|
let albums =
|
||||||
Data.albumsRows
|
Data.albumsRows
|
||||||
& filter (\album -> (album ^? Data.field "AlbumId" . Data._ColumnFieldNumber) == Just 1 && (album ^? Data.field "Title" . Data._ColumnFieldString) == Just "Let There Be Rock")
|
& filter (\album -> (album ^? Data.field "AlbumId" . Data._ColumnFieldNumber) == Just 1 && (album ^? Data.field "Title" . Data._ColumnFieldString) == Just "Let There Be Rock")
|
||||||
|
|
||||||
let artists =
|
let artists =
|
||||||
Data.artistsRows
|
Data.artistsRows
|
||||||
& filter (\artist -> isJust $ find (\album -> (album ^? Data.field "ArtistId" . Data._ColumnFieldNumber) == (artist ^? Data.field "ArtistId" . Data._ColumnFieldNumber)) albums)
|
& filter (\artist -> isJust $ find (\album -> (album ^? Data.field "ArtistId" . Data._ColumnFieldNumber) == (artist ^? Data.field "ArtistId" . Data._ColumnFieldNumber)) albums)
|
||||||
& sortOn (^? Data.field "ArtistId")
|
& sortOn (^? Data.field "ArtistId")
|
||||||
|
|
||||||
Data.responseRows receivedArtists `rowsShouldBe` artists
|
Data.responseRows receivedArtists `rowsShouldBe` artists
|
||||||
_qrAggregates receivedArtists `jsonShouldBe` Nothing
|
_qrAggregates receivedArtists `jsonShouldBe` Nothing
|
||||||
|
|
||||||
artistsQueryRequest :: QueryRequest
|
artistsQueryRequest :: QueryRequest
|
||||||
artistsQueryRequest =
|
artistsQueryRequest =
|
||||||
|
@ -16,8 +16,8 @@ import Test.Expectations (jsonShouldBe, rowsShouldBe)
|
|||||||
import Test.Hspec (Spec, describe, it)
|
import Test.Hspec (Spec, describe, it)
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
spec :: Client IO (NamedRoutes Routes) -> SourceName -> Config -> Maybe CrossTableComparisonCapabilities -> Spec
|
spec :: Client IO (NamedRoutes Routes) -> SourceName -> Config -> Maybe SubqueryComparisonCapabilities -> Spec
|
||||||
spec api sourceName config crossTableComparisonCapabilities = describe "Relationship Queries" $ do
|
spec api sourceName config subqueryComparisonCapabilities = describe "Relationship Queries" $ do
|
||||||
it "perform an object relationship query by joining artist to albums" $ do
|
it "perform an object relationship query by joining artist to albums" $ do
|
||||||
let query = albumsWithArtistQuery id
|
let query = albumsWithArtistQuery id
|
||||||
receivedAlbums <- Data.sortResponseRowsBy "AlbumId" <$> (api // _query) sourceName config query
|
receivedAlbums <- Data.sortResponseRowsBy "AlbumId" <$> (api // _query) sourceName config query
|
||||||
@ -64,7 +64,7 @@ spec api sourceName config crossTableComparisonCapabilities = describe "Relation
|
|||||||
Data.responseRows receivedArtists `rowsShouldBe` expectedAlbums
|
Data.responseRows receivedArtists `rowsShouldBe` expectedAlbums
|
||||||
_qrAggregates receivedArtists `jsonShouldBe` Nothing
|
_qrAggregates receivedArtists `jsonShouldBe` Nothing
|
||||||
|
|
||||||
when ((_ctccSupportsRelations <$> crossTableComparisonCapabilities) == Just True) $
|
when ((_ctccSupportsRelations <$> subqueryComparisonCapabilities) == Just True) $
|
||||||
describe "Cross related table comparisons" $ do
|
describe "Cross related table comparisons" $ do
|
||||||
it "perform an object relationship query by joining employee to customers and filter comparing columns across the object relationship" $ do
|
it "perform an object relationship query by joining employee to customers and filter comparing columns across the object relationship" $ do
|
||||||
-- Join Employee to Customers via SupportRep, and only get those customers that have a rep
|
-- Join Employee to Customers via SupportRep, and only get those customers that have a rep
|
||||||
|
@ -42,7 +42,7 @@ capabilities =
|
|||||||
API._cComparisons =
|
API._cComparisons =
|
||||||
Just
|
Just
|
||||||
API.ComparisonCapabilities
|
API.ComparisonCapabilities
|
||||||
{ API._ccCrossTableComparisonCapabilities = Just API.CrossTableComparisonCapabilities {API._ctccSupportsRelations = True}
|
{ API._ccSubqueryComparisonCapabilities = Just API.SubqueryComparisonCapabilities {API._ctccSupportsRelations = True}
|
||||||
},
|
},
|
||||||
API._cMetrics = Just API.MetricsCapabilities {},
|
API._cMetrics = Just API.MetricsCapabilities {},
|
||||||
API._cExplain = Just API.ExplainCapabilities {}
|
API._cExplain = Just API.ExplainCapabilities {}
|
||||||
|
@ -53,7 +53,7 @@ defaultBackendCapabilities = \case
|
|||||||
[yaml|
|
[yaml|
|
||||||
relationships: {}
|
relationships: {}
|
||||||
comparisons:
|
comparisons:
|
||||||
cross_table:
|
subquery:
|
||||||
supports_relations: true
|
supports_relations: true
|
||||||
explain: {}
|
explain: {}
|
||||||
metrics: {}
|
metrics: {}
|
||||||
@ -71,7 +71,7 @@ defaultBackendCapabilities = \case
|
|||||||
}
|
}
|
||||||
relationships: {}
|
relationships: {}
|
||||||
comparisons:
|
comparisons:
|
||||||
cross_table:
|
subquery:
|
||||||
supports_relations: true
|
supports_relations: true
|
||||||
scalar_types:
|
scalar_types:
|
||||||
DateTime:
|
DateTime:
|
||||||
|
Loading…
Reference in New Issue
Block a user