morrySnow commented on code in PR #14753:
URL: https://github.com/apache/doris/pull/14753#discussion_r1037750358
##########
fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4:
##########
@@ -143,13 +144,16 @@ CURRENT_TIME: 'CURRENT_TIME';
CURRENT_TIMESTAMP: 'CURRENT_TIMESTAMP';
CURRENT_USER: 'CURRENT_USER';
DAY: 'DAY';
+DAYS_ADD: 'DAYS_ADD';
+DAYS_SUB: 'DAYS_SUB';
DATA: 'DATA';
DATABASE: 'DATABASE';
DATABASES: 'DATABASES';
DATE: 'DATE';
DATEADD: 'DATEADD';
Review Comment:
do we have `DATEADD` and `DATESUB`
##########
fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4:
##########
@@ -90,6 +90,7 @@ RIGHT_BRACKET: ']';
//============================
//--DORIS-KEYWORD-LIST-START
ADD: 'ADD';
+ADDDATE:'ADDDATE';
Review Comment:
// We use IDENT for the temporal unit to avoid making DAY, YEAR, etc.
keywords.
// This way we do not need to change existing uses of IDENT.
// We chose not to make DATE_ADD and DATE_SUB keywords for the same reason.
these words are not keywords in the legacy planner. we should follow it
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ExpressionTrait.java:
##########
@@ -48,6 +48,6 @@ default DataType getDataType() throws UnboundException {
}
default String toSql() throws UnboundException {
- throw new UnboundException("sql");
+ throw new UnboundException(this.toString());
Review Comment:
change back to "sql", the whole error msg want to say u call a **SQL**
method on unbound object
##########
regression-test/suites/nereids_syntax_p0/test_date_add.groovy:
##########
@@ -0,0 +1,53 @@
+// 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.
+
+suite("test_date_add") {
+ sql "set enable_nereids_planner=true"
+ sql "set enable_fallback_to_original_planner=false"
+
+
+ qt_select """
+ SELECT TIMESTAMPADD('2003-02-01', interval 2 year)
Review Comment:
we need to test four types: `date`, `datev2`, `datetime`, `datetimev2`
##########
fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4:
##########
@@ -270,6 +270,12 @@ primaryExpression
startTimestamp=valueExpression COMMA
endTimestamp=valueExpression
RIGHT_PAREN
#timestampdiff
+ | name=(TIMESTAMPADD | ADDDATE | DAYS_ADD | DATE_ADD)
+ LEFT_PAREN timestamp=valueExpression
+ COMMA (INTERVAL unitsAmount=valueExpression unit=datetimeUnit |
unitsAmount=valueExpression) RIGHT_PAREN #date_add
Review Comment:
let statement alias have same indent for easy reading
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysAdd.java:
##########
@@ -0,0 +1,65 @@
+// 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.AlwaysNullable;
+import
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
+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.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 'days_add'.
+ */
+public class DaysAdd extends ScalarFunction implements BinaryExpression,
ExplicitlyCastableSignature, AlwaysNullable {
+ public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
+
FunctionSignature.ret(DateTimeType.INSTANCE).args(DateTimeType.INSTANCE,
IntegerType.INSTANCE),
+
FunctionSignature.ret(DateTimeType.INSTANCE).args(DateTimeV2Type.INSTANCE,
IntegerType.INSTANCE),
+
FunctionSignature.ret(DateTimeType.INSTANCE).args(DateV2Type.INSTANCE,
IntegerType.INSTANCE)
Review Comment:
arg could be date, right?
##########
fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java:
##########
@@ -65,7 +65,6 @@ public enum Operator {
BITXOR("^", "bitxor", OperatorPosition.BINARY_INFIX,
TExprOpcode.BITXOR),
BITNOT("~", "bitnot", OperatorPosition.UNARY_PREFIX,
TExprOpcode.BITNOT),
FACTORIAL("!", "factorial", OperatorPosition.UNARY_POSTFIX,
TExprOpcode.FACTORIAL);
-
Review Comment:
add this line back
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DaysAdd.java:
##########
@@ -0,0 +1,65 @@
+// 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.AlwaysNullable;
+import
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
+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.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 'days_add'.
+ */
+public class DaysAdd extends ScalarFunction implements BinaryExpression,
ExplicitlyCastableSignature, AlwaysNullable {
+ public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
+
FunctionSignature.ret(DateTimeType.INSTANCE).args(DateTimeType.INSTANCE,
IntegerType.INSTANCE),
+
FunctionSignature.ret(DateTimeType.INSTANCE).args(DateTimeV2Type.INSTANCE,
IntegerType.INSTANCE),
Review Comment:
if arg is DateTimeV2Type, the return type should be DateTimeV2Type too
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]