ChinmaySKulkarni commented on a change in pull request #671: PHOENIX-4845 
Support using Row Value Constructors in OFFSET clause fo…
URL: https://github.com/apache/phoenix/pull/671#discussion_r363572130
 
 

 ##########
 File path: 
phoenix-core/src/main/java/org/apache/phoenix/compile/OffsetCompiler.java
 ##########
 @@ -62,23 +82,233 @@ public SortOrder getSortOrder() {
 
     private OffsetCompiler() {}
 
-    public static Integer compile(StatementContext context, 
FilterableStatement statement) throws SQLException {
+    // eager initialization
+    final private static OffsetCompiler OFFSET_COMPILER = getInstance();
+
+    private static OffsetCompiler getInstance() {
+        return new OffsetCompiler();
+    }
+
+    public static OffsetCompiler getOffsetCompiler() {
+        return OFFSET_COMPILER;
+    }
+
+    public CompiledOffset compile(StatementContext context, 
FilterableStatement statement) throws SQLException {
         OffsetNode offsetNode = statement.getOffset();
-        if (offsetNode == null) { return null; }
-        OffsetParseNodeVisitor visitor = new OffsetParseNodeVisitor(context);
-        offsetNode.getOffsetParseNode().accept(visitor);
-        return visitor.getOffset();
+        if (offsetNode == null) { return new 
CompiledOffset(Optional.<Integer>absent(), Optional.<byte[]>absent()); }
+        if (offsetNode.isIntegerOffset()) {
+            OffsetParseNodeVisitor visitor = new 
OffsetParseNodeVisitor(context);
+            offsetNode.getOffsetParseNode().accept(visitor);
+            Integer offset = visitor.getOffset();
+            return new CompiledOffset(Optional.fromNullable(offset), 
Optional.<byte[]>absent());
+        } else {
+            // We have a RVC offset. See PHOENIX-4845
+
+            // This is a EqualParseNode with LHS and RHS 
RowValueConstructorParseNodes
+            // This is enforced as part of the grammar
+            EqualParseNode equalParseNode = 
(EqualParseNode)offsetNode.getOffsetParseNode();
+
+            RowValueConstructorParseNode rvcColumnsParseNode = 
(RowValueConstructorParseNode)equalParseNode.getLHS();
+            RowValueConstructorParseNode rvcConstantParseNode = 
(RowValueConstructorParseNode)equalParseNode.getRHS();
+
+            // disallow use with aggregations
+            if (statement.isAggregate()) { throw new SQLException("RVC Offset 
not allowed in Aggregates"); }
 
 Review comment:
   Given that there are now a bunch of cases where offset usage could lead to 
SQLException, is it worth it creating a new `RVCOffsetSQLException` class or 
something instead?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to