-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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 function quarters_add/sub for nereids (#4…
…5370) ### What problem does this PR solve? Issue Number: close #xxx Related PR: #xxx Problem Summary: 1. BE already has its implementation. now add nereids function signatures. ```sql mysql> select quarters_add("2020-12-12", 1); +-----------------------------------------------+ | quarters_add(cast('2020-12-12' as DATEV2), 1) | +-----------------------------------------------+ | 2021-03-12 | +-----------------------------------------------+ 1 row in set (0.10 sec) mysql> select date_sub("2020-12-12", interval 10 quarter); +------------------------------------------------+ | quarters_sub(cast('2020-12-12' as DATEV2), 10) | +------------------------------------------------+ | 2018-06-12 | +------------------------------------------------+ 1 row in set (0.11 sec) ``` 2. for date operations' template implementations in BE, we choose years_add to cover its standard testcases to test the base template.
- Loading branch information
Showing
14 changed files
with
1,228 additions
and
10 deletions.
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
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
80 changes: 80 additions & 0 deletions
80
...rc/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/QuartersAdd.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,80 @@ | ||
// 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.common.Config; | ||
import org.apache.doris.nereids.trees.expressions.Expression; | ||
import org.apache.doris.nereids.trees.expressions.functions.ComputeSignatureForDateArithmetic; | ||
import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; | ||
import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; | ||
import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; | ||
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; | ||
import org.apache.doris.nereids.types.DateTimeType; | ||
import org.apache.doris.nereids.types.DateTimeV2Type; | ||
import org.apache.doris.nereids.types.DateType; | ||
import org.apache.doris.nereids.types.DateV2Type; | ||
import org.apache.doris.nereids.types.IntegerType; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* ScalarFunction 'quarters_add'. | ||
*/ | ||
public class QuartersAdd extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, | ||
ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args { | ||
|
||
// When enable_date_conversion is true, we prefer to V2 signature. | ||
// This preference follows original planner. refer to ScalarType.getDefaultDateType() | ||
private static final List<FunctionSignature> SIGNATURES = Config.enable_date_conversion | ||
? ImmutableList.of( | ||
FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(DateTimeV2Type.SYSTEM_DEFAULT, | ||
IntegerType.INSTANCE), | ||
FunctionSignature.ret(DateV2Type.INSTANCE).args(DateV2Type.INSTANCE, IntegerType.INSTANCE), | ||
FunctionSignature.ret(DateTimeType.INSTANCE).args(DateTimeType.INSTANCE, IntegerType.INSTANCE), | ||
FunctionSignature.ret(DateType.INSTANCE).args(DateType.INSTANCE, IntegerType.INSTANCE)) | ||
: ImmutableList.of( | ||
FunctionSignature.ret(DateTimeType.INSTANCE).args(DateTimeType.INSTANCE, IntegerType.INSTANCE), | ||
FunctionSignature.ret(DateType.INSTANCE).args(DateType.INSTANCE, IntegerType.INSTANCE), | ||
FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(DateTimeV2Type.SYSTEM_DEFAULT, | ||
IntegerType.INSTANCE), | ||
FunctionSignature.ret(DateV2Type.INSTANCE).args(DateV2Type.INSTANCE, IntegerType.INSTANCE)); | ||
|
||
public QuartersAdd(Expression arg0, Expression arg1) { | ||
super("quarters_add", arg0, arg1); | ||
} | ||
|
||
@Override | ||
public QuartersAdd withChildren(List<Expression> children) { | ||
Preconditions.checkArgument(children.size() == 2); | ||
return new QuartersAdd(children.get(0), children.get(1)); | ||
} | ||
|
||
@Override | ||
public List<FunctionSignature> getSignatures() { | ||
return SIGNATURES; | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { | ||
return visitor.visitQuartersAdd(this, context); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...rc/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/QuartersSub.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,80 @@ | ||
// 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.common.Config; | ||
import org.apache.doris.nereids.trees.expressions.Expression; | ||
import org.apache.doris.nereids.trees.expressions.functions.ComputeSignatureForDateArithmetic; | ||
import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; | ||
import org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args; | ||
import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; | ||
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; | ||
import org.apache.doris.nereids.types.DateTimeType; | ||
import org.apache.doris.nereids.types.DateTimeV2Type; | ||
import org.apache.doris.nereids.types.DateType; | ||
import org.apache.doris.nereids.types.DateV2Type; | ||
import org.apache.doris.nereids.types.IntegerType; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* ScalarFunction 'quarters_sub'. | ||
*/ | ||
public class QuartersSub extends ScalarFunction implements BinaryExpression, ExplicitlyCastableSignature, | ||
ComputeSignatureForDateArithmetic, PropagateNullableOnDateLikeV2Args { | ||
|
||
// When enable_date_conversion is true, we prefer to V2 signature. | ||
// This preference follows original planner. refer to ScalarType.getDefaultDateType() | ||
private static final List<FunctionSignature> SIGNATURES = Config.enable_date_conversion | ||
? ImmutableList.of( | ||
FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(DateTimeV2Type.SYSTEM_DEFAULT, | ||
IntegerType.INSTANCE), | ||
FunctionSignature.ret(DateV2Type.INSTANCE).args(DateV2Type.INSTANCE, IntegerType.INSTANCE), | ||
FunctionSignature.ret(DateTimeType.INSTANCE).args(DateTimeType.INSTANCE, IntegerType.INSTANCE), | ||
FunctionSignature.ret(DateType.INSTANCE).args(DateType.INSTANCE, IntegerType.INSTANCE)) | ||
: ImmutableList.of( | ||
FunctionSignature.ret(DateTimeType.INSTANCE).args(DateTimeType.INSTANCE, IntegerType.INSTANCE), | ||
FunctionSignature.ret(DateType.INSTANCE).args(DateType.INSTANCE, IntegerType.INSTANCE), | ||
FunctionSignature.ret(DateTimeV2Type.SYSTEM_DEFAULT).args(DateTimeV2Type.SYSTEM_DEFAULT, | ||
IntegerType.INSTANCE), | ||
FunctionSignature.ret(DateV2Type.INSTANCE).args(DateV2Type.INSTANCE, IntegerType.INSTANCE)); | ||
|
||
public QuartersSub(Expression arg0, Expression arg1) { | ||
super("quarters_sub", arg0, arg1); | ||
} | ||
|
||
@Override | ||
public QuartersSub withChildren(List<Expression> children) { | ||
Preconditions.checkArgument(children.size() == 2); | ||
return new QuartersSub(children.get(0), children.get(1)); | ||
} | ||
|
||
@Override | ||
public List<FunctionSignature> getSignatures() { | ||
return SIGNATURES; | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { | ||
return visitor.visitQuartersSub(this, context); | ||
} | ||
} |
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
Oops, something went wrong.