[feature-wip](array-type) Add codes and UT for array_contains and array_position functions (#8401) (#8589)
array_contains function Usage example: 1. create table with ARRAY column, and insert some data: ``` > select * from array_test; +------+------+--------+ | k1 | k2 | k3 | +------+------+--------+ | 1 | 2 | [1, 2] | | 2 | 3 | NULL | | 4 | NULL | [] | | 3 | NULL | NULL | +------+------+--------+ ``` 2. enable vectorized: ``` > set enable_vectorized_engine=true; ``` 3. select with array_contains: ``` > select k1,array_contains(k3,1) from array_test; +------+-------------------------+ | k1 | array_contains(`k3`, 1) | +------+-------------------------+ | 3 | NULL | | 1 | 1 | | 2 | NULL | | 4 | 0 | +------+-------------------------+ ``` 4. also we can use array_contains in where condition ``` > select * from array_test where array_contains(k3,1); +------+------+--------+ | k1 | k2 | k3 | +------+------+--------+ | 1 | 2 | [1, 2] | +------+------+--------+ ``` 5. array_position usage example ``` > select k1,k3,array_position(k3,2) from array_test; +------+--------+-------------------------+ | k1 | k3 | array_position(`k3`, 2) | +------+--------+-------------------------+ | 3 | NULL | NULL | | 1 | [1, 2] | 2 | | 2 | NULL | NULL | | 4 | [] | 0 | +------+--------+-------------------------+ ```
This commit is contained in:
@ -66,9 +66,13 @@ public class ArrayType extends Type {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Array(Null) is a virtual Array type, can match any Array(...) type
|
||||
if (itemType.isNull()) {
|
||||
return true;
|
||||
}
|
||||
if (((ArrayType) t).getItemType().isNull()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return itemType.matchesType(((ArrayType) t).itemType);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user