Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spec-defined SqlParserTest tests; fix ParseError symbol #10

Merged
merged 3 commits into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion partiql-test-data/fail/parser/select/select-from-where.ion
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ parse::{
name: "SFW without WHERE expression",
statement: "SELECT * FROM foo WHERE",
assert: {
result: ParserError
result: ParseError
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
parse::{
name: "COUNT aggregate function call",
statement: "COUNT(a)",
assert: [
{
result: ParseOk
},
]
}

parse::{
name: "SUM DISTINCT aggregate function call",
statement: "SUM(DISTINCT a)",
assert: [
{
result: ParseOk
},
]
}

parse::{
name: "COUNT star aggregate function call",
statement: "COUNT(*)",
assert: [
{
result: ParseOk
},
]
}

parse::{
name: "COUNT DISTINCT aggregate function call",
statement: "COUNT(DISTINCT a)",
assert: [
{
result: ParseOk
},
]
}
137 changes: 137 additions & 0 deletions partiql-test-data/pass/parser/primitives/call.ion
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
parse::{
name: "call empty",
statement: "foobar()",
assert: [
{
result: ParseOk
},
]
}

parse::{
name: "call one argument",
statement: "foobar(1)",
assert: [
{
result: ParseOk
},
]
}

parse::{
name: "call two arguments",
statement: "foobar(1, 2)",
assert: [
{
result: ParseOk
},
]
}

parse::{
name: "call with multiple",
statement: "foobar(1, 2, 3)",
assert: [
{
result: ParseOk
},
]
}

parse::{
name: "call with case insensitive function name",
statement: "mY_fUnCtIoN(a)",
assert: [
{
result: ParseOk
},
]
}


'substring'::[
parse::{
name: "call SUBSTRING sql92 syntax",
statement: "substring('test' from 100)",
assert: [
{
result: ParseOk
},
]
},
parse::{
name: "call SUBSTRING sql92 syntax with length",
statement: "substring('test' from 100 for 50)",
assert: [
{
result: ParseOk
},
]
},
parse::{
name: "call SUBSTRING normal syntax",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this and other lines that it applies: by normal do we mean PartiQL syntax? If so, how about changing it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking more about this, should we consider porting the sql92, etc. to namespaces?

E.g.:

'sql92'::[
    parse::{
        ...
    }
]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, "normal" referred to the PartiQL function call syntax. I can change to use a more specific term.

Thinking more about this, should we consider porting the sql92, etc. to namespaces?

Good suggestion. I will enclose the sql92-related syntax in its own namespace.

statement: "substring('test', 100)",
assert: [
{
result: ParseOk
},
]
},
parse::{
name: "call SUBSTRING normal syntax with length",
statement: "substring('test', 100, 50)",
assert: [
{
result: ParseOk
},
]
},
]

'trim'::[
parse::{
name: "call TRIM single argument",
statement: "trim('test')",
assert: [
{
result: ParseOk
},
]
},
parse::{
name: "call TRIM two arguments default specification",
statement: "trim(' ' from 'test')",
assert: [
{
result: ParseOk
},
]
},
parse::{
name: "call TRIM two arguments using BOTH",
statement: "trim(both from 'test')",
assert: [
{
result: ParseOk
},
]
},
parse::{
name: "call TRIM two arguments using LEADING",
statement: "trim(leading from 'test')",
assert: [
{
result: ParseOk
},
]
},
parse::{
name: "call TRIM two arguments using TRAILING",
statement: "trim(trailing from 'test')",
assert: [
{
result: ParseOk
},
]
},
]
59 changes: 59 additions & 0 deletions partiql-test-data/pass/parser/primitives/case.ion
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'searched-case'::[
parse::{
name: "searched CASE single WHEN no ELSE",
statement: "CASE WHEN name = 'zoe' THEN 1 END",
assert: [
{
result: ParseOk
},
]
},
parse::{
name: "searched CASE single WHEN with ELSE",
statement: "CASE WHEN name = 'zoe' THEN 1 ELSE 0 END",
assert: [
{
result: ParseOk
},
]
},
parse::{
name: "searched CASE multi WHEN with ELSE",
statement: "CASE WHEN name = 'zoe' THEN 1 WHEN name > 'kumo' THEN 2 ELSE 0 END",
assert: [
{
result: ParseOk
},
]
}
]

'simple-case'::[
parse::{
name: "simple CASE single WHEN no ELSE",
statement: "CASE name WHEN 'zoe' THEN 1 END",
assert: [
{
result: ParseOk
},
]
},
parse::{
name: "simple CASE single WHEN with ELSE",
statement: "CASE name WHEN 'zoe' THEN 1 ELSE 0 END",
assert: [
{
result: ParseOk
},
]
},
parse::{
name: "simple CASE multi WHEN with ELSE ",
statement: "CASE name WHEN 'zoe' THEN 1 WHEN 'kumo' THEN 2 WHEN 'mary' THEN 3 ELSE 0 END",
assert: [
{
result: ParseOk
},
]
}
]
79 changes: 79 additions & 0 deletions partiql-test-data/pass/parser/primitives/cast.ion
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
parse::{
name: "CAST as VARCHAR",
statement: "CAST(5 AS VARCHAR)",
assert: [
{
result: ParseOk
},
]
}

parse::{
name: "CAST as VARCHAR with length",
statement: "CAST(5 AS VARCHAR(5))",
assert: [
{
result: ParseOk
},
]
}

parse::{
name: "CAST as DECIMAL",
statement: "CAST(a AS DECIMAL)",
assert: [
{
result: ParseOk
},
]
}

parse::{
name: "CAST as DECIMAL scale only",
statement: "CAST(a AS DECIMAL(1))",
assert: [
{
result: ParseOk
},
]
}

parse::{
name: "CAST as DECIMAL scale and precision",
statement: "CAST(a AS DECIMAL(1, 2))",
assert: [
{
result: ParseOk
},
]
}

parse::{
name: "CAST as NUMERIC",
statement: "CAST(a AS NUMERIC)",
assert: [
{
result: ParseOk
},
]
}

parse::{
name: "CAST as NUMERIC scale only",
statement: "CAST(a AS NUMERIC(1))",
assert: [
{
result: ParseOk
},
]
}

parse::{
name: "CAST as NUMERIC scale and precision",
statement: "CAST(a AS NUMERIC(1, 2))",
assert: [
{
result: ParseOk
},
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'row-value-constructor'::[
parse::{
name: "row value constructor with simple expressions",
statement: "(1, 2, 3, 4)",
assert: [
{
result: ParseOk
},
]
},
parse::{
name: "row value constructor with row value constructors",
statement: "((1, 2), (3, 4))",
assert: [
{
result: ParseOk
},
]
}
]

'table-value-constructor'::[
parse::{
name: "table value constructor with row value constructors",
statement: "VALUES (1, 2), (3, 4)",
assert: [
{
result: ParseOk
},
]
},
parse::{
name: "table value constructor with singleton row value constructors",
statement: "VALUES (1), (2), (3)",
assert: [
{
result: ParseOk
},
]
}
]
Loading