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

test: add string function test cases #4

Merged
merged 6 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions bft/testers/duckdb/runner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Dict, NamedTuple

import duckdb
from typing import Dict, NamedTuple

from bft.cases.runner import SqlCaseResult, SqlCaseRunner
from bft.cases.types import Case, CaseLiteral
Expand Down
10 changes: 9 additions & 1 deletion bft/testers/sqlite/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"fp32": "REAL",
"fp64": "REAL",
"boolean": "BOOLEAN",
"string": "TEXT",
}


Expand Down Expand Up @@ -53,7 +54,14 @@ def run_sql_case(self, case: Case, mapping: SqlMapping) -> SqlCaseResult:
if mapping.aggregate:
arg_names = [arg_names[0]]
joined_arg_names = ",".join(arg_names)
arg_vals = ",".join([literal_to_str(arg) for arg in case.args])
arg_vals = ",".join(
[
"'" + literal_to_str(arg) + "'"
if arg.type == "string" and arg.value is not None
else literal_to_str(arg)
for arg in case.args
]
)
if mapping.aggregate:
arg_vals_list = ", ".join(f"({val})" for val in arg_vals.split(","))
if arg_vals != "[]":
Expand Down
2 changes: 1 addition & 1 deletion bft/testers/velox/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def is_type_supported(type):
return type in set({"i64", "fp64", "boolean"})
return type in set({"i64", "fp64", "boolean", "string"})


class VeloxRunner(SqlCaseRunner):
Expand Down
42 changes: 42 additions & 0 deletions cases/string/concat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function: concat
cases:
- group:
id: basic
description: Basic examples without any special cases
args:
- value: 'abcd'
type: string
- value: 'efg'
type: string
result:
value: 'abcdefg'
type: string
- group:
id: null_input
description: Examples with null as input
args:
- value: 'abcd'
type: string
- value: null
type: string
result:
value: null
type: string
- group: null_input
args:
- value: null
type: string
- value: 'abcd'
type: string
result:
value: null
type: string
- group: null_input
args:
- value: null
type: string
- value: null
type: string
result:
value: null
type: string
60 changes: 60 additions & 0 deletions cases/string/like.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function: like
cases:
- group:
id: basic
description: Basic examples without any special cases
args:
- value: 'abcdefg'
type: string
- value: 'abcdefg'
type: string
result:
value: true
type: boolean
- group: basic
args:
- value: 'abcdefg'
type: string
- value: 'abc'
type: string
result:
value: false
type: boolean
- group:
id: wildcard
description: Examples using wildcards
args:
- value: 'abcdefg'
type: string
- value: 'abc%'
type: string
result:
value: true
type: boolean
- group: wildcard
args:
- value: 'abcdefg'
type: string
- value: '%efg'
type: string
result:
value: true
type: boolean
- group: wildcard
args:
- value: 'abcdefg'
type: string
- value: '_bcdefg'
type: string
result:
value: true
type: boolean
- group: wildcard
args:
- value: 'abcdefg'
type: string
- value: 'abc_efg'
type: string
result:
value: true
type: boolean
115 changes: 115 additions & 0 deletions cases/string/substring.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
function: substring
cases:
- group:
id: basic
description: Basic examples without any special cases
args:
- value: 'abcdefg'
type: string
- value: 1
type: i32
- value: 5
type: i32
result:
value: 'abcde'
type: string
- group: basic
args:
- value: 'abcdefg'
type: string
- value: 1
type: i64
- value: 5
type: i64
result:
value: 'abcde'
type: string
- group:
id: start_greater_than_length
description: Example where start argument greater than the length of the string
args:
- value: 'abcdefg'
type: string
- value: 10
type: i32
- value: 2
type: i32
result:
value: ''
type: string
- group: start_greater_than_length
args:
- value: 'abcdefg'
type: string
- value: 10
type: i64
- value: 2
type: i64
result:
value: ''
type: string
- group:
id: multi_byte_characters
description: Example where multi byte characters exist in the string
args:
- value: '😊a😊b😊😊'
type: string
- value: 1
type: i32
- value: 3
type: i32
result:
value: '😊a😊'
type: string
- group: multi_byte_characters
args:
- value: '😊a😊b😊😊'
type: string
- value: 1
type: i64
- value: 3
type: i64
result:
value: '😊a😊'
type: string
- group:
id: negative_start
description: Example where start argument is a negative integer
args:
- value: 'abcdefg'
type: string
- value: -3
type: i64
- value: 2
type: i64
options:
negative_start: WRAP_FROM_END
result:
value: 'ef'
type: string
- group: negative_start
args:
- value: 'abcdefg'
type: string
- value: -3
type: i64
- value: 4
type: i64
options:
negative_start: LEFT_OF_BEGINNING
result:
value: ''
type: string
- group: negative_start
args:
- value: 'abcdefg'
type: string
- value: -3
type: i64
- value: 4
type: i64
options:
negative_start: LEFT_OF_BEGINNING
result:
value: 'ab'
type: string
8 changes: 8 additions & 0 deletions dialects/duckdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ scalar_functions:
result: fp32
- name: extract
extract: True
- name: substring
required_options:
negative_start: WRAP_FROM_END
- name: concat
local_name: "||"
infix: True
- name: like
infix: True
aggregate_functions:
- name: min
aggregate: True
Expand Down
14 changes: 14 additions & 0 deletions dialects/postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ scalar_functions:
result: fp64
- name: extract
extract: True
- name: substring
required_options:
negative_start: LEFT_OF_BEGINNING
unsupported_kernels:
- args:
- string
- i64
- i64
result: string
- name: concat
local_name: "||"
infix: True
- name: like
infix: True
aggregate_functions:
- name: min
aggregate: True
Expand Down
8 changes: 8 additions & 0 deletions dialects/sqlite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ scalar_functions:
unsupported: true
- name: extract
unsupported: True
- name: substring
required_options:
negative_start: WRAP_FROM_END
- name: concat
local_name: "||"
infix: True
- name: like
infix: True
aggregate_functions:
- name: min
aggregate: True
Expand Down
13 changes: 13 additions & 0 deletions dialects/velox_presto.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,19 @@ scalar_functions:
result: fp64
- name: extract
unsupported: True
- name: substring
local_name: substr
required_options:
negative_start: WRAP_FROM_END
unsupported_kernels:
- args:
- string
- i32
- i32
result: string
- name: concat
- name: like
unsupported: True
aggregate_functions:
- name: min
unsupported: True
Expand Down