-
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.
The draft of the test code has not been implemented1
- Loading branch information
1 parent
e6607b8
commit 1fca6b6
Showing
6 changed files
with
258 additions
and
7 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
81 changes: 81 additions & 0 deletions
81
...re/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/NextDay.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,81 @@ | ||
// 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.PropagateNullableOnDateLikeV2Args; | ||
import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; | ||
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 com.google.common.base.Preconditions; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
/** | ||
* ScalarFunction 'next_day'. This class is generated by GenerateFunction. | ||
*/ | ||
public class NextDay extends ScalarFunction | ||
implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { | ||
|
||
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of( | ||
FunctionSignature.ret(DateV2Type.INSTANCE).args(DateV2Type.INSTANCE), | ||
FunctionSignature.ret(DateV2Type.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT), | ||
FunctionSignature.ret(DateType.INSTANCE).args(DateType.INSTANCE), | ||
FunctionSignature.ret(DateType.INSTANCE).args(DateTimeType.INSTANCE) | ||
); | ||
|
||
/** | ||
* Constructor with 1 argument. | ||
*/ | ||
public NextDay(Expression arg) { | ||
super("next_day", arg); | ||
} | ||
|
||
/** | ||
* withChildren. | ||
*/ | ||
@Override | ||
public NextDay withChildren(List<Expression> children) { | ||
Preconditions.checkArgument(children.size() == 1); | ||
return new NextDay(children.get(0)); | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { | ||
return calculateNextDay(visitor, context); | ||
} | ||
|
||
private <R, C> R calculateNextDay(ExpressionVisitor<R, C> visitor, C context) { | ||
LocalDate currentDate = toJavaDateType().toLocalDate(); | ||
LocalDate nextDay = currentDate.plusDays(1); | ||
return (R) new DateLiteral(nextDay.getYear(), nextDay.getMonthValue(), nextDay.getDayOfMonth()); | ||
} | ||
|
||
@Override | ||
public List<FunctionSignature> getSignatures() { | ||
return SIGNATURES; | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...rc/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/PreviousDay.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,81 @@ | ||
// 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.PropagateNullableOnDateLikeV2Args; | ||
import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; | ||
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 com.google.common.base.Preconditions; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
/** | ||
* ScalarFunction 'previous_day'. This class is generated by GenerateFunction. | ||
*/ | ||
public class PreviousDay extends ScalarFunction | ||
implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullableOnDateLikeV2Args { | ||
|
||
public static final List<FunctionSignature> SIGNATURES = ImmutableList.of( | ||
FunctionSignature.ret(DateV2Type.INSTANCE).args(DateV2Type.INSTANCE), | ||
FunctionSignature.ret(DateV2Type.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT), | ||
FunctionSignature.ret(DateType.INSTANCE).args(DateType.INSTANCE), | ||
FunctionSignature.ret(DateType.INSTANCE).args(DateTimeType.INSTANCE) | ||
); | ||
|
||
/** | ||
* Constructor with 1 argument. | ||
*/ | ||
public PreviousDay(Expression arg) { | ||
super("previous_day", arg); | ||
} | ||
|
||
/** | ||
* withChildren. | ||
*/ | ||
@Override | ||
public PreviousDay withChildren(List<Expression> children) { | ||
Preconditions.checkArgument(children.size() == 1); | ||
return new PreviousDay(children.get(0)); | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { | ||
return calculatePreviousDay(visitor, context); | ||
} | ||
|
||
private <R, C> R calculatePreviousDay(ExpressionVisitor<R, C> visitor, C context) { | ||
LocalDate currentDate = toJavaDateType().toLocalDate(); | ||
LocalDate previousDay = currentDate.minusDays(1); | ||
return (R) new DateLiteral(previousDay.getYear(), previousDay.getMonthValue(), previousDay.getDayOfMonth()); | ||
} | ||
|
||
@Override | ||
public List<FunctionSignature> getSignatures() { | ||
return SIGNATURES; | ||
} | ||
} |