forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature](function)support count_substrings functions (apache#42055)
support count_substrings functions doc: apache/doris-website#1211 <!--Describe your changes.-->
- Loading branch information
1 parent
8a79ad6
commit 527a475
Showing
8 changed files
with
418 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/CountSubstring.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// 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. | ||
|
||
package org.apache.doris.nereids.trees.expressions.functions.scalar; | ||
|
||
import org.apache.doris.catalog.FunctionSignature; | ||
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.shape.BinaryExpression; | ||
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; | ||
import org.apache.doris.nereids.types.IntegerType; | ||
import org.apache.doris.nereids.types.StringType; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* ScalarFunction 'count_substrings'. | ||
*/ | ||
public class CountSubstring extends ScalarFunction | ||
implements BinaryExpression, ExplicitlyCastableSignature, PropagateNullable { | ||
|
||
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of( | ||
FunctionSignature.ret(IntegerType.INSTANCE) | ||
.args(StringType.INSTANCE, StringType.INSTANCE) | ||
); | ||
|
||
/** | ||
* constructor with 2 arguments. | ||
*/ | ||
public CountSubstring(Expression arg0, Expression arg1) { | ||
super("count_substrings", arg0, arg1); | ||
} | ||
|
||
/** | ||
* withChildren. | ||
*/ | ||
@Override | ||
public CountSubstring withChildren(List<Expression> children) { | ||
Preconditions.checkArgument(children.size() == 2); | ||
return new CountSubstring(children.get(0), children.get(1)); | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { | ||
return visitor.visitCountSubstring(this, context); | ||
} | ||
|
||
@Override | ||
public List<FunctionSignature> getSignatures() { | ||
return SIGNATURES; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
regression-test/data/query_p0/sql_functions/string_functions/test_count_substrings.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
-- This file is automatically generated. You should know what you did if you want to edit this | ||
-- !select1 -- | ||
\N | ||
|
||
-- !select2 -- | ||
\N | ||
|
||
-- !select3 -- | ||
\N | ||
|
||
-- !select4 -- | ||
2 | ||
|
||
-- !select5 -- | ||
6 | ||
|
||
-- !select6 -- | ||
1 | ||
|
||
-- !select4_empty -- | ||
|
||
-- !select5_empty -- | ||
|
||
-- !select6_empty -- | ||
|
||
-- !select7_empty -- | ||
|
||
-- !select5_null_null -- | ||
abcde 0 | ||
0 | ||
a 0 | ||
\N \N \N | ||
asdasd a 2 | ||
a1b1c1d 1 3 | ||
,,, # 0 | ||
a,b,c v 0 | ||
a,b,c, \N \N | ||
\N asd \N | ||
a,b,c,12345 5 1 | ||
a,b,c,12345 a 1 | ||
a,你,你,1我2你4我5 你 3 | ||
|
||
-- !select6_null_not -- | ||
abcde 0 | ||
0 | ||
a 0 | ||
\N \N | ||
asdasd a 2 | ||
a1b1c1d 1 3 | ||
,,, # 0 | ||
a,b,c v 0 | ||
a,b,c, 0 | ||
\N asd \N | ||
a,b,c,12345 5 1 | ||
a,b,c,12345 a 1 | ||
a,你,你,1我2你4我5 我 2 | ||
|
||
-- !select7_not_null -- | ||
abcde 0 | ||
0 | ||
a 0 | ||
\N \N | ||
asdasd a 2 | ||
a1b1c1d 1 3 | ||
,,, # 0 | ||
a,b,c v 0 | ||
a,b,c \N \N | ||
asd 0 | ||
a,b,c,12345 5 1 | ||
a,b,c,12345 a 1 | ||
a你,你,1我2你4我5 你 3 | ||
|
||
-- !select8_not_not -- | ||
abcde 0 | ||
0 | ||
a 0 | ||
0 | ||
asdasd a 2 | ||
a1b1c1d 1 3 | ||
,,, # 0 | ||
a,b,c v 0 | ||
a,b,c 0 | ||
asd 0 | ||
a,b,c,12345 5 1 | ||
a,b,c,12345 a 1 | ||
a你,你,1我2你4我5 我 2 | ||
|
||
-- !select9_null_const -- | ||
abcde a 1 | ||
a 0 | ||
a 0 | ||
\N a \N | ||
asdasd a 2 | ||
a1b1c1d a 1 | ||
,,, a 0 | ||
a,b,c a 1 | ||
a,b,c, a 1 | ||
\N a \N | ||
a,b,c,12345 a 1 | ||
a,b,c,12345 a 1 | ||
a,你,你,1我2你4我5 a 1 | ||
|
||
-- !select10_not_null_const -- | ||
abcde a 1 | ||
a 0 | ||
a 0 | ||
a 0 | ||
asdasd a 2 | ||
a1b1c1d a 1 | ||
,,, a 0 | ||
a,b,c a 1 | ||
a,b,c a 1 | ||
a 0 | ||
a,b,c,12345 a 1 | ||
a,b,c,12345 a 1 | ||
a你,你,1我2你4我5 a 1 | ||
|
||
-- !select11_const_null -- | ||
a 0 | ||
a 0 | ||
a a 1 | ||
a \N \N | ||
a a 1 | ||
a 1 0 | ||
a # 0 | ||
a v 0 | ||
a \N \N | ||
a asd 0 | ||
a 5 0 | ||
a a 1 | ||
a 你 0 | ||
|
||
-- !select12_const_not_null -- | ||
a 0 | ||
a 0 | ||
a a 1 | ||
a 0 | ||
a a 1 | ||
a 1 0 | ||
a # 0 | ||
a v 0 | ||
a 0 | ||
a asd 0 | ||
a 5 0 | ||
a a 1 | ||
a 我 0 | ||
|
Oops, something went wrong.