-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
ilike
and nilike
operators in BigQurey
PR-URL: hasura/graphql-engine-mono#10638 GitOrigin-RevId: 6e97d480282b19ef0c87e08719e6421c09665d15
- Loading branch information
1 parent
d177c6f
commit cc588a1
Showing
7 changed files
with
258 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
217 changes: 217 additions & 0 deletions
217
server/lib/api-tests/src/Test/Databases/BigQuery/Queries/TextFunctionsSpec.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
{-# LANGUAGE QuasiQuotes #-} | ||
|
||
-- | Test text search functions in BigQuery | ||
module Test.Databases.BigQuery.Queries.TextFunctionsSpec (spec) where | ||
|
||
import Data.Aeson (Value) | ||
import Data.List.NonEmpty qualified as NE | ||
import Harness.Backend.BigQuery qualified as BigQuery | ||
import Harness.GraphqlEngine (postGraphql) | ||
import Harness.Quoter.Graphql (graphql) | ||
import Harness.Quoter.Yaml (interpolateYaml) | ||
import Harness.Schema qualified as Schema | ||
import Harness.Test.Fixture qualified as Fixture | ||
import Harness.TestEnvironment (GlobalTestEnvironment, TestEnvironment (..)) | ||
import Harness.Yaml (shouldReturnYaml) | ||
import Hasura.Prelude | ||
import Test.Hspec (SpecWith, describe, it) | ||
|
||
spec :: SpecWith GlobalTestEnvironment | ||
spec = | ||
Fixture.run | ||
( NE.fromList | ||
[ (Fixture.fixture $ Fixture.Backend BigQuery.backendTypeMetadata) | ||
{ Fixture.setupTeardown = \(testEnvironment, _) -> | ||
[ BigQuery.setupTablesAction schema testEnvironment | ||
] | ||
} | ||
] | ||
) | ||
tests | ||
|
||
-------------------------------------------------------------------------------- | ||
-- Schema | ||
|
||
schema :: [Schema.Table] | ||
schema = | ||
[ (Schema.table "languages") | ||
{ Schema.tableColumns = | ||
[ Schema.column "name" Schema.TStr | ||
], | ||
Schema.tablePrimaryKey = [], | ||
Schema.tableData = | ||
[ [Schema.VStr "Python"], | ||
[Schema.VStr "C"], | ||
[Schema.VStr "C++"], | ||
[Schema.VStr "Java"], | ||
[Schema.VStr "C#"], | ||
[Schema.VStr "JavaScript"], | ||
[Schema.VStr "PHP"], | ||
[Schema.VStr "Visual Basic"], | ||
[Schema.VStr "SQL"], | ||
[Schema.VStr "Scratch"], | ||
[Schema.VStr "Go"], | ||
[Schema.VStr "Fortran"], | ||
[Schema.VStr "Delphi"], | ||
[Schema.VStr "MATLAB"], | ||
[Schema.VStr "Assembly"], | ||
[Schema.VStr "Swift"], | ||
[Schema.VStr "Kotlin"], | ||
[Schema.VStr "Ruby"], | ||
[Schema.VStr "Rust"], | ||
[Schema.VStr "COBOL"] | ||
] | ||
} | ||
] | ||
|
||
-------------------------------------------------------------------------------- | ||
-- Tests | ||
|
||
tests :: SpecWith TestEnvironment | ||
tests = do | ||
describe "Text predicates" do | ||
it "ilike" \testEnvironment -> do | ||
let schemaName :: Schema.SchemaName | ||
schemaName = Schema.getSchemaName testEnvironment | ||
|
||
let expected :: Value | ||
expected = | ||
[interpolateYaml| | ||
data: | ||
#{schemaName}_languages: | ||
- name: Assembly | ||
- name: Fortran | ||
- name: Java | ||
- name: JavaScript | ||
- name: MATLAB | ||
- name: Scratch | ||
- name: Visual Basic | ||
|] | ||
|
||
actual :: IO Value | ||
actual = | ||
postGraphql | ||
testEnvironment | ||
[graphql| | ||
query { | ||
#{schemaName}_languages ( | ||
order_by: { name: asc }, | ||
where: { name: { _ilike: "%a%" } } | ||
) { | ||
name | ||
} | ||
} | ||
|] | ||
|
||
shouldReturnYaml testEnvironment actual expected | ||
|
||
it "like" \testEnvironment -> do | ||
let schemaName = Schema.getSchemaName testEnvironment | ||
let expected :: Value | ||
expected = | ||
[interpolateYaml| | ||
data: | ||
#{schemaName}_languages: | ||
- name: Fortran | ||
- name: Java | ||
- name: JavaScript | ||
- name: Scratch | ||
- name: Visual Basic | ||
|] | ||
|
||
actual :: IO Value | ||
actual = | ||
postGraphql | ||
testEnvironment | ||
[graphql| | ||
query { | ||
#{schemaName}_languages ( | ||
order_by: { name: asc }, | ||
where: { name: { _like: "%a%" } } | ||
) { | ||
name | ||
} | ||
} | ||
|] | ||
|
||
shouldReturnYaml testEnvironment actual expected | ||
|
||
it "nlike" \testEnvironment -> do | ||
let schemaName = Schema.getSchemaName testEnvironment | ||
let expected :: Value | ||
expected = | ||
[interpolateYaml| | ||
data: | ||
#{schemaName}_languages: | ||
- name: Assembly | ||
- name: C | ||
- name: C# | ||
- name: C++ | ||
- name: COBOL | ||
- name: Delphi | ||
- name: Go | ||
- name: Kotlin | ||
- name: MATLAB | ||
- name: PHP | ||
- name: Python | ||
- name: Ruby | ||
- name: Rust | ||
- name: SQL | ||
- name: Swift | ||
|] | ||
|
||
actual :: IO Value | ||
actual = | ||
postGraphql | ||
testEnvironment | ||
[graphql| | ||
query { | ||
#{schemaName}_languages ( | ||
order_by: { name: asc }, | ||
where: { name: { _nlike: "%a%" } } | ||
) { | ||
name | ||
} | ||
} | ||
|] | ||
|
||
shouldReturnYaml testEnvironment actual expected | ||
|
||
it "nilike" \testEnvironment -> do | ||
let schemaName = Schema.getSchemaName testEnvironment | ||
let expected :: Value | ||
expected = | ||
[interpolateYaml| | ||
data: | ||
#{schemaName}_languages: | ||
- name: C | ||
- name: C# | ||
- name: C++ | ||
- name: COBOL | ||
- name: Delphi | ||
- name: Go | ||
- name: Kotlin | ||
- name: PHP | ||
- name: Python | ||
- name: Ruby | ||
- name: Rust | ||
- name: SQL | ||
- name: Swift | ||
|] | ||
|
||
actual :: IO Value | ||
actual = | ||
postGraphql | ||
testEnvironment | ||
[graphql| | ||
query { | ||
#{schemaName}_languages ( | ||
order_by: { name: asc }, | ||
where: { name: { _nilike: "%a%" } } | ||
) { | ||
name | ||
} | ||
} | ||
|] | ||
|
||
shouldReturnYaml testEnvironment actual expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters