|
31 | 31 | import org.apache.doris.nereids.DorisParser.ComparisonContext; |
32 | 32 | import org.apache.doris.nereids.DorisParser.CreateRowPolicyContext; |
33 | 33 | import org.apache.doris.nereids.DorisParser.CteContext; |
| 34 | +import org.apache.doris.nereids.DorisParser.Date_addContext; |
| 35 | +import org.apache.doris.nereids.DorisParser.Date_subContext; |
34 | 36 | import org.apache.doris.nereids.DorisParser.DecimalLiteralContext; |
35 | 37 | import org.apache.doris.nereids.DorisParser.DereferenceContext; |
36 | 38 | import org.apache.doris.nereids.DorisParser.ExistContext; |
37 | 39 | import org.apache.doris.nereids.DorisParser.ExplainContext; |
| 40 | +import org.apache.doris.nereids.DorisParser.ExpressionContext; |
38 | 41 | import org.apache.doris.nereids.DorisParser.FromClauseContext; |
39 | 42 | import org.apache.doris.nereids.DorisParser.GroupingElementContext; |
40 | 43 | import org.apache.doris.nereids.DorisParser.GroupingSetContext; |
|
126 | 129 | import org.apache.doris.nereids.trees.expressions.TVFProperties; |
127 | 130 | import org.apache.doris.nereids.trees.expressions.TimestampArithmetic; |
128 | 131 | import org.apache.doris.nereids.trees.expressions.WhenClause; |
| 132 | +import org.apache.doris.nereids.trees.expressions.functions.scalar.DaysAdd; |
129 | 133 | import org.apache.doris.nereids.trees.expressions.functions.scalar.DaysDiff; |
| 134 | +import org.apache.doris.nereids.trees.expressions.functions.scalar.DaysSub; |
| 135 | +import org.apache.doris.nereids.trees.expressions.functions.scalar.HoursAdd; |
130 | 136 | import org.apache.doris.nereids.trees.expressions.functions.scalar.HoursDiff; |
| 137 | +import org.apache.doris.nereids.trees.expressions.functions.scalar.HoursSub; |
| 138 | +import org.apache.doris.nereids.trees.expressions.functions.scalar.MinutesAdd; |
131 | 139 | import org.apache.doris.nereids.trees.expressions.functions.scalar.MinutesDiff; |
| 140 | +import org.apache.doris.nereids.trees.expressions.functions.scalar.MinutesSub; |
| 141 | +import org.apache.doris.nereids.trees.expressions.functions.scalar.MonthsAdd; |
132 | 142 | import org.apache.doris.nereids.trees.expressions.functions.scalar.MonthsDiff; |
| 143 | +import org.apache.doris.nereids.trees.expressions.functions.scalar.MonthsSub; |
| 144 | +import org.apache.doris.nereids.trees.expressions.functions.scalar.SecondsAdd; |
133 | 145 | import org.apache.doris.nereids.trees.expressions.functions.scalar.SecondsDiff; |
| 146 | +import org.apache.doris.nereids.trees.expressions.functions.scalar.SecondsSub; |
| 147 | +import org.apache.doris.nereids.trees.expressions.functions.scalar.YearsAdd; |
134 | 148 | import org.apache.doris.nereids.trees.expressions.functions.scalar.YearsDiff; |
| 149 | +import org.apache.doris.nereids.trees.expressions.functions.scalar.YearsSub; |
135 | 150 | import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral; |
136 | 151 | import org.apache.doris.nereids.trees.expressions.literal.BooleanLiteral; |
137 | 152 | import org.apache.doris.nereids.trees.expressions.literal.DateLiteral; |
|
167 | 182 | import org.apache.doris.nereids.trees.plans.logical.LogicalSubQueryAlias; |
168 | 183 | import org.apache.doris.nereids.trees.plans.logical.RelationUtil; |
169 | 184 | import org.apache.doris.nereids.types.DataType; |
| 185 | +import org.apache.doris.nereids.types.IntegerType; |
| 186 | +import org.apache.doris.nereids.types.TinyIntType; |
170 | 187 | import org.apache.doris.nereids.util.ExpressionUtils; |
171 | 188 | import org.apache.doris.policy.PolicyTypeEnum; |
172 | 189 | import org.apache.doris.qe.ConnectContext; |
@@ -577,10 +594,82 @@ public Expression visitTimestampdiff(TimestampdiffContext ctx) { |
577 | 594 | } else if ("SECOND".equalsIgnoreCase(unit)) { |
578 | 595 | return new SecondsDiff(end, start); |
579 | 596 | } |
580 | | - throw new ParseException("Unsupported time stamp diff time unit: " + unit, ctx); |
| 597 | + throw new ParseException("Unsupported time stamp diff time unit: " + unit |
| 598 | + + ", supported time unit: YEAR/MONTH/DAY/HOUR/MINUTE/SECOND", ctx); |
581 | 599 |
|
582 | 600 | } |
583 | 601 |
|
| 602 | + @Override |
| 603 | + public Expression visitDate_add(Date_addContext ctx) { |
| 604 | + Expression timeStamp = (Expression) visit(ctx.timestamp); |
| 605 | + Expression amount = (Expression) visit(ctx.unitsAmount); |
| 606 | + if (ctx.unit == null) { |
| 607 | + if ("days_add".equalsIgnoreCase(ctx.name.getText())) { |
| 608 | + return new DaysAdd(timeStamp, amount); |
| 609 | + } |
| 610 | + throw new ParseException("Unsupported signature: " + ctx.name |
| 611 | + + " needs time unit (YEAR/MONTH/DAY/HOUR/MINUTE/SECOND)", ctx); |
| 612 | + } |
| 613 | + |
| 614 | + if ("DAY".equalsIgnoreCase(ctx.unit.getText())) { |
| 615 | + return new DaysAdd(timeStamp, amount); |
| 616 | + } |
| 617 | + if ("MONTH".equalsIgnoreCase(ctx.unit.getText())) { |
| 618 | + return new MonthsAdd(timeStamp, amount); |
| 619 | + } |
| 620 | + if ("Year".equalsIgnoreCase(ctx.unit.getText())) { |
| 621 | + return new YearsAdd(timeStamp, amount); |
| 622 | + } |
| 623 | + if ("Hour".equalsIgnoreCase(ctx.unit.getText())) { |
| 624 | + return new HoursAdd(timeStamp, amount); |
| 625 | + } |
| 626 | + if ("Minute".equalsIgnoreCase(ctx.unit.getText())) { |
| 627 | + return new MinutesAdd(timeStamp, amount); |
| 628 | + } |
| 629 | + if ("Second".equalsIgnoreCase(ctx.unit.getText())) { |
| 630 | + return new SecondsAdd(timeStamp, amount); |
| 631 | + } |
| 632 | + throw new ParseException("Unsupported time unit: " + ctx.unit |
| 633 | + + ", supported time unit: YEAR/MONTH/DAY/HOUR/MINUTE/SECOND", ctx); |
| 634 | + } |
| 635 | + |
| 636 | + @Override |
| 637 | + public Expression visitDate_sub(Date_subContext ctx) { |
| 638 | + Expression timeStamp = (Expression) visit(ctx.timestamp); |
| 639 | + Expression amount = (Expression) visit(ctx.unitsAmount); |
| 640 | + if (! (amount.getDataType() instanceof TinyIntType)) { |
| 641 | + amount = new Cast(amount, IntegerType.INSTANCE); |
| 642 | + } |
| 643 | + if (ctx.unit == null) { |
| 644 | + if ("days_sub".equalsIgnoreCase(ctx.name.getText())) { |
| 645 | + return new DaysSub(timeStamp, amount); |
| 646 | + } |
| 647 | + throw new ParseException("Unsupported signature: " + ctx.name |
| 648 | + + " needs time unit (YEAR/MONTH/DAY/HOUR/MINUTE/SECOND)", ctx); |
| 649 | + } |
| 650 | + |
| 651 | + if ("DAY".equalsIgnoreCase(ctx.unit.getText())) { |
| 652 | + return new DaysSub(timeStamp, amount); |
| 653 | + } |
| 654 | + if ("MONTH".equalsIgnoreCase(ctx.unit.getText())) { |
| 655 | + return new MonthsSub(timeStamp, amount); |
| 656 | + } |
| 657 | + if ("Year".equalsIgnoreCase(ctx.unit.getText())) { |
| 658 | + return new YearsSub(timeStamp, amount); |
| 659 | + } |
| 660 | + if ("Hour".equalsIgnoreCase(ctx.unit.getText())) { |
| 661 | + return new HoursSub(timeStamp, amount); |
| 662 | + } |
| 663 | + if ("Minute".equalsIgnoreCase(ctx.unit.getText())) { |
| 664 | + return new MinutesSub(timeStamp, amount); |
| 665 | + } |
| 666 | + if ("Second".equalsIgnoreCase(ctx.unit.getText())) { |
| 667 | + return new SecondsSub(timeStamp, amount); |
| 668 | + } |
| 669 | + throw new ParseException("Unsupported time unit: " + ctx.unit |
| 670 | + + ", supported time unit: YEAR/MONTH/DAY/HOUR/MINUTE/SECOND", ctx); |
| 671 | + } |
| 672 | + |
584 | 673 | /** |
585 | 674 | * Create a value based [[CaseWhen]] expression. This has the following SQL form: |
586 | 675 | * {{{ |
@@ -648,7 +737,8 @@ public UnboundFunction visitFunctionCall(DorisParser.FunctionCallContext ctx) { |
648 | 737 | // the function information is obtained by parsing the catalog. This method is more scalable. |
649 | 738 | String functionName = ctx.identifier().getText(); |
650 | 739 | boolean isDistinct = ctx.DISTINCT() != null; |
651 | | - List<Expression> params = visit(ctx.expression(), Expression.class); |
| 740 | + List<ExpressionContext> expressionContexts = ctx.expression(); |
| 741 | + List<Expression> params = visit(expressionContexts, Expression.class); |
652 | 742 | for (Expression expression : params) { |
653 | 743 | if (expression instanceof UnboundStar && functionName.equalsIgnoreCase("count") && !isDistinct) { |
654 | 744 | return new UnboundFunction(functionName, false, true, new ArrayList<>()); |
|
0 commit comments