This is an automated email from the ASF dual-hosted git repository. sankarh pushed a commit to branch branch-3 in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/branch-3 by this push: new 6da0c94c0db HIVE-27668: Backport of HIVE-21126: Allow session level queries in LlapBaseInputFormat#getSplits() before actual get_splits() call (Shubham Chaurasia, reviewed by Teddy Choi) 6da0c94c0db is described below commit 6da0c94c0db7e31507245c5ff314cc402fde38dc Author: Aman Raj <104416558+amanraj2...@users.noreply.github.com> AuthorDate: Tue Sep 12 11:05:25 2023 +0530 HIVE-27668: Backport of HIVE-21126: Allow session level queries in LlapBaseInputFormat#getSplits() before actual get_splits() call (Shubham Chaurasia, reviewed by Teddy Choi) Signed-off-by: Sankar Hariappan <sank...@apache.org> Closes (#4663) --- .../apache/hadoop/hive/llap/LlapBaseInputFormat.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/llap-ext-client/src/java/org/apache/hadoop/hive/llap/LlapBaseInputFormat.java b/llap-ext-client/src/java/org/apache/hadoop/hive/llap/LlapBaseInputFormat.java index ef03be660e7..30f372003f0 100644 --- a/llap-ext-client/src/java/org/apache/hadoop/hive/llap/LlapBaseInputFormat.java +++ b/llap-ext-client/src/java/org/apache/hadoop/hive/llap/LlapBaseInputFormat.java @@ -37,6 +37,7 @@ import java.util.Random; import java.util.Set; import java.util.UUID; import java.util.concurrent.LinkedBlockingQueue; +import java.util.regex.Pattern; import org.apache.commons.collections4.ListUtils; import org.apache.hadoop.hive.conf.HiveConf; @@ -114,6 +115,8 @@ public class LlapBaseInputFormat<V extends WritableComparable<?>> public static final String PWD_KEY = "llap.if.pwd"; public static final String HANDLE_ID = "llap.if.handleid"; public static final String DB_KEY = "llap.if.database"; + public static final String SESSION_QUERIES_FOR_GET_NUM_SPLITS = "llap.session.queries.for.get.num.splits"; + public static final Pattern SET_QUERY_PATTERN = Pattern.compile("^\\s*set\\s+.*=.+$", Pattern.CASE_INSENSITIVE); public final String SPLIT_QUERY = "select get_splits(\"%s\",%d)"; public static final LlapServiceInstance[] serviceInstanceArray = new LlapServiceInstance[0]; @@ -259,6 +262,20 @@ public class LlapBaseInputFormat<V extends WritableComparable<?>> if (database != null && !database.isEmpty()) { stmt.execute("USE " + database); } + String sessionQueries = job.get(SESSION_QUERIES_FOR_GET_NUM_SPLITS); + if (sessionQueries != null && !sessionQueries.trim().isEmpty()) { + String[] queries = sessionQueries.trim().split(","); + for (String q : queries) { + //allow only set queries + if (SET_QUERY_PATTERN.matcher(q).matches()) { + LOG.debug("Executing session query: {}", q); + stmt.execute(q); + } else { + LOG.warn("Only SET queries are allowed, not executing this query: {}", q); + } + } + } + ResultSet res = stmt.executeQuery(sql); while (res.next()) { // deserialize split