[opt](Nereids) match predicate support array as first arg (#25172)

This commit is contained in:
morrySnow
2023-10-09 17:17:27 +08:00
committed by GitHub
parent 4de3df6a46
commit d02ef36631
3 changed files with 45 additions and 2 deletions

View File

@ -315,9 +315,11 @@ public class FunctionBinder extends AbstractExpressionRewriteRule {
Expression left = match.left().accept(this, context);
Expression right = match.right().accept(this, context);
// check child type
if (!left.getDataType().isStringLikeType()) {
if (!left.getDataType().isStringLikeType()
&& !(left.getDataType() instanceof ArrayType
&& ((ArrayType) left.getDataType()).getItemType().isStringLikeType())) {
throw new AnalysisException(String.format(
"left operand '%s' part of predicate " + "'%s' should return type 'STRING' but "
"left operand '%s' part of predicate " + "'%s' should return type 'STRING' or 'ARRAY<STRING>' but "
+ "returns type '%s'.",
left.toSql(), match.toSql(), left.getDataType()));
}

View File

@ -69,3 +69,29 @@
-- !sql --
2 [20, 30, 40] ["i", "love", "north korea"]
-- !sql --
1 [10, 20, 30] ["i", "love", "china"]
-- !sql --
1 [10, 20, 30] ["i", "love", "china"]
2 [20, 30, 40] ["i", "love", "north korea"]
-- !sql --
2 [20, 30, 40] ["i", "love", "north korea"]
-- !sql --
2 [20, 30, 40] ["i", "love", "north korea"]
-- !sql --
1 [10, 20, 30] ["i", "love", "china"]
-- !sql --
1 [10, 20, 30] ["i", "love", "china"]
2 [20, 30, 40] ["i", "love", "north korea"]
-- !sql --
2 [20, 30, 40] ["i", "love", "north korea"]
-- !sql --
2 [20, 30, 40] ["i", "love", "north korea"]

View File

@ -65,9 +65,24 @@ suite("test_array_index"){
qt_sql "SELECT * FROM $indexTblName WHERE int_array element_eq 50 ORDER BY id;"
qt_sql "SELECT * FROM $indexTblName WHERE int_array element_eq 60 ORDER BY id;"
sql "set enable_fallback_to_original_planner=false"
qt_sql "SELECT * FROM $indexTblName WHERE c_array MATCH 'china' ORDER BY id;"
qt_sql "SELECT * FROM $indexTblName WHERE c_array MATCH 'love' ORDER BY id;"
qt_sql "SELECT * FROM $indexTblName WHERE c_array MATCH 'north' ORDER BY id;"
qt_sql "SELECT * FROM $indexTblName WHERE c_array MATCH 'korea' ORDER BY id;"
sql "set enable_fallback_to_original_planner=true"
sql " ALTER TABLE $indexTblName drop index c_array_idx; "
qt_sql "SELECT * FROM $indexTblName WHERE c_array MATCH 'china' ORDER BY id;"
qt_sql "SELECT * FROM $indexTblName WHERE c_array MATCH 'love' ORDER BY id;"
qt_sql "SELECT * FROM $indexTblName WHERE c_array MATCH 'north' ORDER BY id;"
qt_sql "SELECT * FROM $indexTblName WHERE c_array MATCH 'korea' ORDER BY id;"
sql "set enable_fallback_to_original_planner=false"
qt_sql "SELECT * FROM $indexTblName WHERE c_array MATCH 'china' ORDER BY id;"
qt_sql "SELECT * FROM $indexTblName WHERE c_array MATCH 'love' ORDER BY id;"
qt_sql "SELECT * FROM $indexTblName WHERE c_array MATCH 'north' ORDER BY id;"
qt_sql "SELECT * FROM $indexTblName WHERE c_array MATCH 'korea' ORDER BY id;"
sql "set enable_fallback_to_original_planner=true"
}