466466import com .starrocks .sql .ast .TruncateTableStmt ;
467467import com .starrocks .sql .ast .UninstallPluginStmt ;
468468import com .starrocks .sql .ast .UnionRelation ;
469- import com .starrocks .sql .ast .UnitBoundary ;
470469import com .starrocks .sql .ast .UnitIdentifier ;
471470import com .starrocks .sql .ast .UnsupportedStmt ;
472471import com .starrocks .sql .ast .UpdateFailPointStatusStatement ;
@@ -589,6 +588,13 @@ public class AstBuilder extends StarRocksBaseVisitor<ParseNode> {
589588 Lists .newArrayList (FunctionSet .SUBSTR , FunctionSet .SUBSTRING ,
590589 FunctionSet .FROM_UNIXTIME , FunctionSet .FROM_UNIXTIME_MS ,
591590 FunctionSet .STR2DATE );
591+
592+ // Boundary keywords accepted as the third argument of time_slice / date_slice
593+ // (e.g. time_slice(dt, interval 5 minute, FLOOR)); the lower-case form is what the
594+ // function implementation expects.
595+ private static final String TIME_SLICE_BOUNDARY_FLOOR = "floor" ;
596+ private static final String TIME_SLICE_BOUNDARY_CEIL = "ceil" ;
597+
592598 // rewriter
593599 private static final CompoundPredicateExprRewriter COMPOUND_PREDICATE_EXPR_REWRITER = new CompoundPredicateExprRewriter ();
594600
@@ -7311,6 +7317,23 @@ private static void addArgumentUseTypeInt(Expr value, List<Expr> exprs) {
73117317 }
73127318 }
73137319
7320+ // time_slice / date_slice accept FLOOR or CEIL (case-insensitive) as their boundary argument,
7321+ // e.g. time_slice(dt, interval 5 minute, FLOOR). FLOOR and CEIL are non-reserved keywords, so the
7322+ // parser builds a column reference (SlotRef) for the bare keyword; recognize it here and normalize
7323+ // to the lower-case string the function implementation expects.
7324+ private static String getTimeSliceBoundary (ParseNode boundaryArg , String functionName ) {
7325+ if (boundaryArg instanceof SlotRef ) {
7326+ SlotRef slotRef = (SlotRef ) boundaryArg ;
7327+ if (slotRef .getTblNameWithoutAnalyzed () == null && slotRef .getColumnName () != null ) {
7328+ String boundary = slotRef .getColumnName ().toLowerCase ();
7329+ if (boundary .equals (TIME_SLICE_BOUNDARY_FLOOR ) || boundary .equals (TIME_SLICE_BOUNDARY_CEIL )) {
7330+ return boundary ;
7331+ }
7332+ }
7333+ }
7334+ throw new ParsingException (PARSER_ERROR_MSG .wrongTypeOfArgs (functionName ), boundaryArg .getPos ());
7335+ }
7336+
73147337 @ Override
73157338 public ParseNode visitSimpleFunctionCall (StarRocksParser .SimpleFunctionCallContext context ) {
73167339 String fullFunctionName = getQualifiedName (context .qualifiedName ()).toString ();
@@ -7328,7 +7351,7 @@ public ParseNode visitSimpleFunctionCall(StarRocksParser.SimpleFunctionCallConte
73287351 IntervalLiteral intervalLiteral = (IntervalLiteral ) e2 ;
73297352 FunctionCallExpr functionCallExpr = new FunctionCallExpr (fnName , getArgumentsForTimeSlice (e1 ,
73307353 intervalLiteral .getValue (), intervalLiteral .getUnitIdentifier ().getDescription ().toLowerCase (),
7331- "floor" ), pos );
7354+ TIME_SLICE_BOUNDARY_FLOOR ), pos );
73327355
73337356 return functionCallExpr ;
73347357 } else if (context .expression ().size () == 3 ) {
@@ -7340,13 +7363,10 @@ public ParseNode visitSimpleFunctionCall(StarRocksParser.SimpleFunctionCallConte
73407363 IntervalLiteral intervalLiteral = (IntervalLiteral ) e2 ;
73417364
73427365 ParseNode e3 = visit (context .expression (2 ));
7343- if (!(e3 instanceof UnitBoundary )) {
7344- throw new ParsingException (PARSER_ERROR_MSG .wrongTypeOfArgs (functionName ), e3 .getPos ());
7345- }
7346- UnitBoundary unitBoundary = (UnitBoundary ) e3 ;
7366+ String boundary = getTimeSliceBoundary (e3 , functionName );
73477367 FunctionCallExpr functionCallExpr = new FunctionCallExpr (fnName , getArgumentsForTimeSlice (e1 ,
73487368 intervalLiteral .getValue (), intervalLiteral .getUnitIdentifier ().getDescription ().toLowerCase (),
7349- unitBoundary . getDescription (). toLowerCase () ), pos );
7369+ boundary ), pos );
73507370
73517371 return functionCallExpr ;
73527372 } else if (context .expression ().size () == 4 ) {
@@ -8042,11 +8062,6 @@ public ParseNode visitUnitIdentifier(StarRocksParser.UnitIdentifierContext conte
80428062 return new UnitIdentifier (context .getText (), createPos (context ));
80438063 }
80448064
8045- @ Override
8046- public ParseNode visitUnitBoundary (StarRocksParser .UnitBoundaryContext context ) {
8047- return new UnitBoundary (context .getText (), createPos (context ));
8048- }
8049-
80508065 @ Override
80518066 public ParseNode visitDereference (StarRocksParser .DereferenceContext ctx ) {
80528067 Expr base = (Expr ) visit (ctx .base );
0 commit comments