Skip to content

Commit

Permalink
add like test
Browse files Browse the repository at this point in the history
  • Loading branch information
b41sh committed Jun 14, 2021
1 parent f4e6d5f commit b645c19
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
54 changes: 54 additions & 0 deletions common/datavalues/src/data_array_comparison_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,28 @@ fn test_array_comparison() {
expect: vec![Arc::new(BooleanArray::from(vec![false, false, true, true]))],
error: vec![""],
},
ArrayTest {
name: "like-passed",
args: vec![vec![
Arc::new(StringArray::from(vec!["abc", "abd", "abe", "abf"])),
Arc::new(StringArray::from(vec!["abc", "a%", "_b_", "f"])),
]],
op: DataValueComparisonOperator::Like,
expect: vec![Arc::new(BooleanArray::from(vec![true, true, true, false]))],
error: vec![""],
},
ArrayTest {
name: "not-like-passed",
args: vec![vec![
Arc::new(StringArray::from(vec!["abc", "abd", "abe", "abf"])),
Arc::new(StringArray::from(vec!["abc", "a%", "_b_", "f"])),
]],
op: DataValueComparisonOperator::NotLike,
expect: vec![Arc::new(BooleanArray::from(vec![
false, false, false, true,
]))],
error: vec![""],
},
];

for t in tests {
Expand Down Expand Up @@ -185,6 +207,22 @@ fn test_array_scalar_comparison() {
expect: Arc::new(BooleanArray::from(vec![true, true, false, false])),
error: "",
},
ArrayTest {
name: "like-passed",
array: Arc::new(StringArray::from(vec!["abc", "abd", "bae", "baf"])),
scalar: DataValue::Utf8(Some("a%".to_string())),
op: DataValueComparisonOperator::Like,
expect: Arc::new(BooleanArray::from(vec![true, true, false, false])),
error: "",
},
ArrayTest {
name: "not-like-passed",
array: Arc::new(StringArray::from(vec!["abc", "abd", "bae", "baf"])),
scalar: DataValue::Utf8(Some("a%".to_string())),
op: DataValueComparisonOperator::NotLike,
expect: Arc::new(BooleanArray::from(vec![false, false, true, true])),
error: "",
},
];

for t in tests {
Expand Down Expand Up @@ -265,6 +303,22 @@ fn test_scalar_array_comparison() {
expect: Arc::new(BooleanArray::from(vec![false, true, true, true])),
error: "",
},
ArrayTest {
name: "like-passed",
array: Arc::new(StringArray::from(vec!["abc", "abd", "bae", "baf"])),
scalar: DataValue::Utf8(Some("a%".to_string())),
op: DataValueComparisonOperator::Like,
expect: Arc::new(BooleanArray::from(vec![true, true, false, false])),
error: "",
},
ArrayTest {
name: "not-like-passed",
array: Arc::new(StringArray::from(vec!["abc", "abd", "bae", "baf"])),
scalar: DataValue::Utf8(Some("a%".to_string())),
op: DataValueComparisonOperator::NotLike,
expect: Arc::new(BooleanArray::from(vec![false, false, true, true])),
error: "",
},
];

for t in tests {
Expand Down
26 changes: 26 additions & 0 deletions common/functions/src/comparisons/comparison_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,32 @@ fn test_comparison_function() -> Result<()> {
expect: Arc::new(BooleanArray::from(vec![true, true, true, false])),
error: "",
},
Test {
name: "like-passed",
display: "LIKE",
nullable: false,
func: ComparisonLikeFunction::try_create_func("")?,
arg_names: vec!["a", "b"],
columns: vec![
Arc::new(StringArray::from(vec!["abc", "abd", "abe", "abf"])).into(),
Arc::new(StringArray::from(vec!["a%", "_b_", "abe", "a"])).into(),
],
expect: Arc::new(BooleanArray::from(vec![true, true, true, false])),
error: "",
},
Test {
name: "not-like-passed",
display: "NOT LIKE",
nullable: false,
func: ComparisonNotLikeFunction::try_create_func("")?,
arg_names: vec!["a", "b"],
columns: vec![
Arc::new(StringArray::from(vec!["abc", "abd", "abe", "abf"])).into(),
Arc::new(StringArray::from(vec!["a%", "_b_", "abe", "a"])).into(),
],
expect: Arc::new(BooleanArray::from(vec![false, false, false, true])),
error: "",
},
];

for t in tests {
Expand Down
40 changes: 40 additions & 0 deletions tests/suites/0_stateless/02_0005_function_compare.result
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,43 @@ select number from numbers_mt(10) where number between 4 + 0.1 and 8 - 0.1 o
| 6 |
| 7 |
+--------+
--------------
select * from system.databases where name like '%sys%'
--------------

+--------+
| name |
+--------+
| system |
+--------+
--------------
select * from system.databases where name like '_ef_ul_'
--------------

+---------+
| name |
+---------+
| default |
+---------+
--------------
select * from system.databases where name not like '%sys%' order by name
--------------

+----------+
| name |
+----------+
| default |
| for_test |
| local |
+----------+
--------------
select * from system.databases where name not like '_ef_ul_' order by name
--------------

+----------+
| name |
+----------+
| for_test |
| local |
| system |
+----------+
7 changes: 7 additions & 0 deletions tests/suites/0_stateless/02_0005_function_compare.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ SELECT number ,number-1 , number*100 , 1> 100 ,1 < 10 FROM numbers_mt (10) order
select number from numbers_mt(10) where number not between 4 + 0.1 and 8 - 0.1 order by number;
select number from numbers_mt(10) where number between 4 + 0.1 and 8 - 0.1 order by number;

-- like
select * from system.databases where name like '%sys%';
select * from system.databases where name like '_ef_ul_';

-- not like
select * from system.databases where name not like '%sys%' order by name;
select * from system.databases where name not like '_ef_ul_' order by name;

0 comments on commit b645c19

Please sign in to comment.