kgyrtkirk commented on code in PR #15836:
URL: https://github.com/apache/druid/pull/15836#discussion_r1483067396


##########
sql/src/main/codegen/includes/common.ftl:
##########
@@ -18,58 +18,52 @@
  */
 
 // Using fully qualified name for Pair class, since Calcite also has a same 
class name being used in the Parser.jj
-org.apache.druid.java.util.common.Pair<Granularity, String> 
PartitionGranularity() :
+SqlNode PartitionGranularity() :
 {
   SqlNode e;
   Granularity granularity;
-  String unparseString;
+  SqlNode result;
 }
 {
   (
     <HOUR>
     {
-      granularity = Granularities.HOUR;
-      unparseString = "HOUR";
+      result = 
SqlLiteral.createSymbol(DruidSqlParserUtils.GranularityGrain.HOUR_GRAIN, 
getPos());
     }
   |
     <DAY>
     {
-      granularity = Granularities.DAY;
-      unparseString = "DAY";
+      result = 
SqlLiteral.createSymbol(DruidSqlParserUtils.GranularityGrain.DAY_GRAIN, 
getPos());
     }
   |
     <MONTH>
     {
-      granularity = Granularities.MONTH;
-      unparseString = "MONTH";
+      result = 
SqlLiteral.createSymbol(DruidSqlParserUtils.GranularityGrain.MONTH_GRAIN, 
getPos());
     }
   |
     <YEAR>
     {
-      granularity = Granularities.YEAR;
-      unparseString = "YEAR";
+      result = 
SqlLiteral.createSymbol(DruidSqlParserUtils.GranularityGrain.YEAR_GRAIN, 
getPos());
     }
   |
     <ALL>
     {
-      granularity = Granularities.ALL;
-      unparseString = "ALL";
+      result = 
SqlLiteral.createSymbol(DruidSqlParserUtils.GranularityGrain.ALL_GRAIN, 
getPos());
     }
     [
       <TIME>
       {
-        unparseString += " TIME";
+        result = 
SqlLiteral.createSymbol(DruidSqlParserUtils.GranularityGrain.ALL_TIME_GRAIN, 
getPos());
       }
     ]
   |
     e = Expression(ExprContext.ACCEPT_SUB_QUERY)
     {
-      granularity = 
DruidSqlParserUtils.convertSqlNodeToGranularityThrowingParseExceptions(e);

Review Comment:
   ok - but why not do the conversion here - I think you might also able to do 
similar thing on all the other branches 
   
   ```
   result = new 
SqlLiteral(DruidSqlParserUtils.convertSqlNodeToGranularityThrowingParseExceptions(e),
 SYMBOL, getPos());
   ```
   
   you could shortcut the transient String + Symbol stuff



##########
sql/src/main/codegen/includes/common.ftl:
##########
@@ -17,59 +17,53 @@
  * under the License.
  */
 
-// Using fully qualified name for Pair class, since Calcite also has a same 
class name being used in the Parser.jj
-org.apache.druid.java.util.common.Pair<Granularity, String> 
PartitionGranularity() :
+SqlNode PartitionGranularity() :
 {
   SqlNode e;
-  Granularity granularity;
-  String unparseString;
+  SqlNode result;
 }
 {
   (
     <HOUR>
     {
-      granularity = Granularities.HOUR;
-      unparseString = "HOUR";
+      result = SqlLiteral.createSymbol(GranularityType.HOUR, getPos());
     }
   |
     <DAY>
     {
-      granularity = Granularities.DAY;
-      unparseString = "DAY";
+      result = SqlLiteral.createSymbol(GranularityType.DAY, getPos());
     }
   |
     <MONTH>
     {
-      granularity = Granularities.MONTH;
-      unparseString = "MONTH";
+      result = SqlLiteral.createSymbol(GranularityType.MONTH, getPos());
     }
   |
     <YEAR>
     {
-      granularity = Granularities.YEAR;
-      unparseString = "YEAR";
+      result = SqlLiteral.createSymbol(GranularityType.YEAR, getPos());
     }
   |
     <ALL>
     {
-      granularity = Granularities.ALL;
-      unparseString = "ALL";
+      result = SqlLiteral.createSymbol(GranularityType.ALL, getPos());
     }
     [
       <TIME>
       {
-        unparseString += " TIME";
+        result = SqlLiteral.createSymbol(GranularityType.ALL, getPos());

Review Comment:
   if they are the same - I think you could ignore the `TIME` keyword by:
   ```
   <ALL> (<TIME>)?
   ```



-- 
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]

Reply via email to