From 04c9427596008ca68239f44a202f6e0884011cdf Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Fri, 21 Jul 2017 00:11:01 +0300 Subject: [PATCH] Pass jdbc fetch size to the scroller Original commit: elastic/x-pack-elasticsearch@2309a43980f06f7c9a8f1fdcf625d556e634dae7 --- .../elasticsearch/xpack/sql/jdbc/jdbc/JdbcResultSet.java | 3 +++ .../xpack/sql/execution/search/Scroller.java | 7 ++++--- .../xpack/sql/plan/physical/EsQueryExec.java | 8 ++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/jdbc/JdbcResultSet.java b/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/jdbc/JdbcResultSet.java index fdef6bf37ba..6e7719153d8 100644 --- a/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/jdbc/JdbcResultSet.java +++ b/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/jdbc/JdbcResultSet.java @@ -388,6 +388,9 @@ class JdbcResultSet implements ResultSet, JdbcWrapper { if (rows < 0) { throw new SQLException("Rows is negative"); } + if (rows != getFetchSize()) { + throw new SQLException("Fetch size cannot be changed"); + } // ignore fetch size since scrolls cannot be changed in flight } diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/execution/search/Scroller.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/execution/search/Scroller.java index 06a4c433faf..aa1f7759163 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/execution/search/Scroller.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/execution/search/Scroller.java @@ -35,6 +35,7 @@ import org.elasticsearch.xpack.sql.querydsl.container.SearchHitFieldRef; import org.elasticsearch.xpack.sql.querydsl.container.TotalCountRef; import org.elasticsearch.xpack.sql.session.RowSetCursor; import org.elasticsearch.xpack.sql.session.Rows; +import org.elasticsearch.xpack.sql.session.SqlSettings; import org.elasticsearch.xpack.sql.type.Schema; import org.elasticsearch.xpack.sql.util.ObjectUtils; @@ -51,9 +52,9 @@ public class Scroller { private final int size; private final Client client; - public Scroller(Client client) { - // TODO: use better defaults? - this(client, TimeValue.timeValueSeconds(90), TimeValue.timeValueSeconds(45), 100); + public Scroller(Client client, SqlSettings settings) { + // TODO: use better defaults (maybe use the sql settings)? + this(client, TimeValue.timeValueSeconds(90), TimeValue.timeValueSeconds(45), settings.pageSize()); } public Scroller(Client client, TimeValue keepAlive, TimeValue timeout, int size) { diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/plan/physical/EsQueryExec.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/plan/physical/EsQueryExec.java index 4418837a294..ff56d2ebb88 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/plan/physical/EsQueryExec.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/plan/physical/EsQueryExec.java @@ -5,9 +5,6 @@ */ package org.elasticsearch.xpack.sql.plan.physical; -import java.util.List; -import java.util.Objects; - import org.elasticsearch.action.ActionListener; import org.elasticsearch.xpack.sql.execution.search.Scroller; import org.elasticsearch.xpack.sql.expression.Attribute; @@ -17,6 +14,9 @@ import org.elasticsearch.xpack.sql.session.Rows; import org.elasticsearch.xpack.sql.session.SqlSession; import org.elasticsearch.xpack.sql.tree.Location; +import java.util.List; +import java.util.Objects; + public class EsQueryExec extends LeafExec { private final String index, type; @@ -55,7 +55,7 @@ public class EsQueryExec extends LeafExec { @Override public void execute(SqlSession session, ActionListener listener) { - Scroller scroller = new Scroller(session.client()); + Scroller scroller = new Scroller(session.client(), session.settings()); scroller.scroll(Rows.schema(output), queryContainer, index, type, listener); }