Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
import org.apache.doris.nereids.trees.expressions.literal.IntegerLikeLiteral;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DoubleType;
import org.apache.doris.nereids.types.IntegerType;
Expand All @@ -47,19 +48,28 @@ public class NgramSearch extends ScalarFunction
*/
public NgramSearch(Expression arg0, Expression arg1, Expression arg2) {
super("ngram_search", arg0, arg1, arg2);
if (!(arg1.isConstant())) {
}

/** constructor for withChildren and reuse signature */
private NgramSearch(ScalarFunctionParams functionParams) {
super(functionParams);
}

@Override
public void checkLegalityBeforeTypeCoercion() {
if (!child(1).isConstant()) {
throw new AnalysisException(
"ngram_search(text,pattern,gram_num): pattern support const value only.");
}
if (!(arg2.isConstant())) {
Expression gramNum = child(2);
if (!gramNum.isConstant()) {
throw new AnalysisException(
"ngram_search(text,pattern,gram_num): gram_num support const value only.");
}
}

/** constructor for withChildren and reuse signature */
private NgramSearch(ScalarFunctionParams functionParams) {
super(functionParams);
if (!(gramNum instanceof IntegerLikeLiteral) || ((IntegerLikeLiteral) gramNum).getIntValue() <= 0) {
throw new AnalysisException(
"ngram_search(text,pattern,gram_num): gram_num must be a positive constant.");
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,14 @@ suite("test_string_function", "arrow_flight_sql") {
qt_ngram_search2 """select ngram_search('abc','abc1313131',3); """
qt_ngram_search3 """select ngram_search('abc1313131','abc1313131',3); """
qt_ngram_search3 """select ngram_search('1313131','abc1313131',3); """
test {
sql "select ngram_search('abc', 'abc', 0);"
exception "gram_num must be a positive constant"
}
test {
sql "select ngram_search('abc', 'abc', -1);"
exception "gram_num must be a positive constant"
}


sql "drop table if exists test_function_ngram_search;";
Expand Down