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

Automate sqllogictest for String, LargeString and StringView behavior #12525

Merged
merged 4 commits into from
Sep 20, 2024
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
44 changes: 44 additions & 0 deletions datafusion/sqllogictest/test_files/string/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!---
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

# String Test Files

This directory contains test files for the `string` test suite.
To ensure consistent behavior across different string types, we should run the same tests with the same inputs on all string types.
There is a framework in place to execute the same tests across different string types.

See [#12415](https://github.com/apache/datafusion/issues/12415) for more background.

## Directory Structure

```
string/
- init_data.slt.part // generate the testing data
- string_query.slt.part // the sharing tests for all string type
- string.slt // the entrypoint for string type
- large_string.slt // the entrypoint for large_string type
- string_view.slt // the entrypoint for string_view type and the string_view specific tests
- string_literal.slt // the tests for string literal
```

## Pattern for Test Entry Point Files

Any entry point file should include `init_data.slt.part` and `string_query.slt.part`.

Planning-related tests (e.g., EXPLAIN ...) should be placed in their own entry point file (e.g., `string_view.slt`) as they are only used to assert planning behavior specific to that type.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
# specific language governing permissions and limitations
# under the License.

# --------------------------------------
# Test `substr()` with literal arguments
# --------------------------------------
include ./substr_literal.slt.part
statement ok
create table test_source as values
('Andrew', 'X', 'datafusion📊🔥', '🔥'),
('Xiangpeng', 'Xiangpeng', 'datafusion数据融合', 'datafusion数据融合'),
('Raphael', 'R', 'datafusionДатаФусион', 'аФус'),
(NULL, 'R', NULL, '🔥');
Comment on lines +19 to +23
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we started to implement some ASCII-faster paths, I think we should always consider testing both ASCII-only and Unicode cases.


# --------------------------------------
# Setup test tables with different physical string types (Utf8/Utf8View/LargeUtf8)
Expand All @@ -29,44 +31,3 @@ create table test_substr_base (
col1 VARCHAR
) as values ('foo'), ('hello🌏世界'), ('💩'), ('ThisIsAVeryLongASCIIString'), (''), (NULL);

#
# Run1: Utf8
#
statement ok
create table test_substr as
select arrow_cast(col1, 'Utf8') as c1 from test_substr_base;

include ./substr_table.slt.part

statement ok
drop table test_substr;

#
# Run2: Utf8View
#
statement ok
create table test_substr as
select arrow_cast(col1, 'Utf8View') as c1 from test_substr_base;

include ./substr_table.slt.part

statement ok
drop table test_substr;

#
# Run3: LargeUtf8
#
statement ok
create table test_substr as
select arrow_cast(col1, 'LargeUtf8') as c1 from test_substr_base;

include ./substr_table.slt.part

statement ok
drop table test_substr;

# --------------------------------------
# Cleanup
# --------------------------------------
statement ok
drop table test_substr_base;
50 changes: 50 additions & 0 deletions datafusion/sqllogictest/test_files/string/large_string.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

include ./init_data.slt.part

# --------------------------------------
# Setup test tables with different physical string types
# and repeat tests in `string_query.slt.part`
# --------------------------------------
statement ok
create table test_basic_operator as
select
arrow_cast(column1, 'LargeUtf8') as ascii_1,
arrow_cast(column2, 'LargeUtf8') as ascii_2,
arrow_cast(column3, 'LargeUtf8') as unicode_1,
arrow_cast(column4, 'LargeUtf8') as unicode_2
from test_source;

statement ok
create table test_substr as
select arrow_cast(col1, 'LargeUtf8') as c1 from test_substr_base;

#
# common test for string-like functions and operators
#
include ./string_query.slt.part

#
# Clean up
#

statement ok
drop table test_basic_operator;

statement ok
drop table test_substr_base;
50 changes: 50 additions & 0 deletions datafusion/sqllogictest/test_files/string/string.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

include ./init_data.slt.part

# --------------------------------------
# Setup test tables with different physical string types
# and repeat tests in `string_query.slt.part`
# --------------------------------------
statement ok
create table test_basic_operator as
select
arrow_cast(column1, 'Utf8') as ascii_1,
arrow_cast(column2, 'Utf8') as ascii_2,
arrow_cast(column3, 'Utf8') as unicode_1,
arrow_cast(column4, 'Utf8') as unicode_2
from test_source;

statement ok
create table test_substr as
select arrow_cast(col1, 'Utf8') as c1 from test_substr_base;

#
# common test for string-like functions and operators
#
include ./string_query.slt.part

#
# Clean up
#

statement ok
drop table test_basic_operator;

statement ok
drop table test_substr;
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ SELECT substr('alphabet', 3, 20)
phabet

query TT
select
substr(arrow_cast('alphabet', 'LargeUtf8'), 3, 20),
select
substr(arrow_cast('alphabet', 'LargeUtf8'), 3, 20),
substr(arrow_cast('alphabet', 'Utf8View'), 3, 20);
----
phabet phabet
Expand Down Expand Up @@ -99,7 +99,7 @@ SELECT

# Nulls
query TTTTTTTTTT
SELECT
SELECT
substr('alphabet', NULL),
substr(NULL, 1),
substr(NULL, NULL),
Expand Down Expand Up @@ -134,3 +134,14 @@ select substr(arrow_cast('foo', 'Utf8View'), 1, -1);

statement error Execution error: negative substring length not allowed
select substr('', 1, -1);

# StringView scalar to StringView scalar

query BBBB
select
arrow_cast('NULL', 'Utf8View') = arrow_cast('Andrew', 'Utf8View'),
arrow_cast('NULL', 'Utf8View') <> arrow_cast('Andrew', 'Utf8View'),
arrow_cast('Andrew', 'Utf8View') = arrow_cast('Andrew', 'Utf8View'),
arrow_cast('Xiangpeng', 'Utf8View') <> arrow_cast('Andrew', 'Utf8View');
----
false true true true
Loading