You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@metamodel.apache.org by GitBox <gi...@apache.org> on 2019/02/24 22:08:08 UTC

[GitHub] kaspersorensen commented on a change in pull request #208: the result of column.getNativeType() may be null and add pagination function to the Hive sql.

kaspersorensen commented on a change in pull request #208:  the result of column.getNativeType() may be null and add pagination function to the Hive sql.
URL: https://github.com/apache/metamodel/pull/208#discussion_r259643332
 
 

 ##########
 File path: jdbc/src/main/java/org/apache/metamodel/jdbc/dialects/HiveQueryRewriter.java
 ##########
 @@ -18,18 +18,46 @@
  */
 package org.apache.metamodel.jdbc.dialects;
 
+import java.util.List;
+import org.apache.metamodel.MetaModelException;
 import org.apache.metamodel.jdbc.JdbcDataContext;
+import org.apache.metamodel.query.FromItem;
+import org.apache.metamodel.query.Query;
+import org.apache.metamodel.query.SelectItem;
 import org.apache.metamodel.schema.ColumnType;
 
 /**
  * Query rewriter for Apache Hive
  */
-public class HiveQueryRewriter extends DefaultQueryRewriter {
+public class HiveQueryRewriter extends RowNumberQueryRewriter {
 
     public HiveQueryRewriter(JdbcDataContext dataContext) {
         super(dataContext);
     }
 
+    @Override
+    public String rewriteQuery(Query query) {
+
+        Integer maxRows = query.getMaxRows();
+        Integer firstRow = query.getFirstRow();
+
+        if (maxRows == null && (firstRow == null || firstRow.intValue() == 1)) {
+            return super.rewriteQuery(query);
+        }
+
+        if ((firstRow == null || firstRow.intValue() == 1) && maxRows != null && maxRows > 0) {
+            // We prefer to use the "LIMIT n" approach, if
+            // firstRow is not specified.
+            return super.rewriteQuery(query) + " LIMIT " + maxRows;
+        } else {
+            return getRowNumberSql(query, maxRows, firstRow);
+        }
+
+    }
+
+
 
 Review comment:
   No need for the 4 line breaks

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services