You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ch...@apache.org on 2021/11/18 02:46:06 UTC
[incubator-kyuubi] branch master updated: [KYUUBI #1384] Introduce spotless and google java format for java code
This is an automated email from the ASF dual-hosted git repository.
chengpan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-kyuubi.git
The following commit(s) were added to refs/heads/master by this push:
new 2baabf4 [KYUUBI #1384] Introduce spotless and google java format for java code
2baabf4 is described below
commit 2baabf46cacf745e5ceaf78192f9f2359dc9e477
Author: yanghua <ya...@gmail.com>
AuthorDate: Thu Nov 18 10:45:51 2021 +0800
[KYUUBI #1384] Introduce spotless and google java format for java code
<!--
Thanks for sending a pull request!
Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://kyuubi.readthedocs.io/en/latest/community/contributions.html
2. If the PR is related to an issue in https://github.com/apache/incubator-kyuubi/issues, add '[KYUUBI #XXXX]' in your PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'.
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][KYUUBI #XXXX] Your PR title ...'.
-->
### _Why are the changes needed?_
<!--
Please clarify why the changes are needed. For instance,
1. If you add a feature, you can talk about the use case of it.
2. If you fix a bug, you can clarify why it is a bug.
-->
### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible
- [ ] Add screenshots for manual tests if appropriate
- [ ] [Run test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests) locally before make a pull request
Closes #1403 from yanghua/KYUUBI-1384.
Closes #1384
e4e12088 [yanghua] address review suggestion
17a4cb86 [yanghua] reformat all the java files based on the offical google java code style
10a2ca04 [yanghua] [KYUUBI #1384] Introduce Java code style and formatter
Authored-by: yanghua <ya...@gmail.com>
Signed-off-by: Cheng Pan <ch...@apache.org>
---
.../java/org/apache/kyuubi/tags/DeltaTest.java | 3 +-
.../org/apache/kyuubi/tags/ExtendedSQLTest.java | 5 +-
.../test/java/org/apache/kyuubi/tags/HudiTest.java | 3 +-
.../java/org/apache/kyuubi/tags/IcebergTest.java | 3 +-
.../java/org/apache/kyuubi/jdbc/KyuubiDriver.java | 7 +-
.../org/apache/kyuubi/jdbc/KyuubiHiveDriver.java | 52 +--
.../hive/ClosedOrCancelledStatementException.java | 6 +-
.../kyuubi/jdbc/hive/HttpBasicAuthInterceptor.java | 19 +-
.../jdbc/hive/HttpKerberosRequestInterceptor.java | 32 +-
.../jdbc/hive/HttpRequestInterceptorBase.java | 24 +-
.../kyuubi/jdbc/hive/HttpTokenAuthInterceptor.java | 20 +-
.../org/apache/kyuubi/jdbc/hive/JdbcColumn.java | 264 +++++------
.../kyuubi/jdbc/hive/JdbcColumnAttributes.java | 4 +-
.../org/apache/kyuubi/jdbc/hive/JdbcTable.java | 5 +-
.../kyuubi/jdbc/hive/JdbcUriParseException.java | 9 +-
.../kyuubi/jdbc/hive/KyuubiBaseResultSet.java | 111 +++--
.../kyuubi/jdbc/hive/KyuubiCallableStatement.java | 150 +++----
.../apache/kyuubi/jdbc/hive/KyuubiConnection.java | 489 +++++++++++----------
.../apache/kyuubi/jdbc/hive/KyuubiDataSource.java | 16 +-
.../kyuubi/jdbc/hive/KyuubiDatabaseMetaData.java | 454 +++++++++++--------
.../kyuubi/jdbc/hive/KyuubiMetaDataResultSet.java | 22 +-
.../kyuubi/jdbc/hive/KyuubiPreparedStatement.java | 147 +++----
.../kyuubi/jdbc/hive/KyuubiQueryResultSet.java | 66 ++-
.../kyuubi/jdbc/hive/KyuubiResultSetMetaData.java | 33 +-
.../apache/kyuubi/jdbc/hive/KyuubiStatement.java | 220 ++++-----
.../java/org/apache/kyuubi/jdbc/hive/Utils.java | 211 +++++----
.../jdbc/hive/XsrfHttpRequestInterceptor.java | 7 +-
.../jdbc/hive/ZooKeeperHiveClientException.java | 9 +-
.../jdbc/hive/ZooKeeperHiveClientHelper.java | 77 ++--
.../kyuubi/jdbc/hive/logs/InPlaceUpdateStream.java | 22 +-
.../kyuubi/jdbc/hive/KyuubiStatementTest.java | 5 +-
.../apache/kyuubi/jdbc/hive/TestJdbcDriver.java | 52 +--
.../jdbc/hive/TestKyuubiPreparedStatement.java | 221 +++++-----
pom.xml | 32 ++
34 files changed, 1419 insertions(+), 1381 deletions(-)
diff --git a/kyuubi-common/src/test/java/org/apache/kyuubi/tags/DeltaTest.java b/kyuubi-common/src/test/java/org/apache/kyuubi/tags/DeltaTest.java
index 6c91d41..1b4b6d0 100644
--- a/kyuubi-common/src/test/java/org/apache/kyuubi/tags/DeltaTest.java
+++ b/kyuubi-common/src/test/java/org/apache/kyuubi/tags/DeltaTest.java
@@ -17,12 +17,11 @@
package org.apache.kyuubi.tags;
-import org.scalatest.TagAnnotation;
-
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import org.scalatest.TagAnnotation;
@TagAnnotation
@Retention(RetentionPolicy.RUNTIME)
diff --git a/kyuubi-common/src/test/java/org/apache/kyuubi/tags/ExtendedSQLTest.java b/kyuubi-common/src/test/java/org/apache/kyuubi/tags/ExtendedSQLTest.java
index d041042..60b0a28 100644
--- a/kyuubi-common/src/test/java/org/apache/kyuubi/tags/ExtendedSQLTest.java
+++ b/kyuubi-common/src/test/java/org/apache/kyuubi/tags/ExtendedSQLTest.java
@@ -17,14 +17,13 @@
package org.apache.kyuubi.tags;
-import org.scalatest.TagAnnotation;
-
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import org.scalatest.TagAnnotation;
@TagAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
-public @interface ExtendedSQLTest { }
+public @interface ExtendedSQLTest {}
diff --git a/kyuubi-common/src/test/java/org/apache/kyuubi/tags/HudiTest.java b/kyuubi-common/src/test/java/org/apache/kyuubi/tags/HudiTest.java
index d52fd94..346f146 100644
--- a/kyuubi-common/src/test/java/org/apache/kyuubi/tags/HudiTest.java
+++ b/kyuubi-common/src/test/java/org/apache/kyuubi/tags/HudiTest.java
@@ -17,12 +17,11 @@
package org.apache.kyuubi.tags;
-import org.scalatest.TagAnnotation;
-
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import org.scalatest.TagAnnotation;
@TagAnnotation
@Retention(RetentionPolicy.RUNTIME)
diff --git a/kyuubi-common/src/test/java/org/apache/kyuubi/tags/IcebergTest.java b/kyuubi-common/src/test/java/org/apache/kyuubi/tags/IcebergTest.java
index 0e11f6e..bb598ad 100644
--- a/kyuubi-common/src/test/java/org/apache/kyuubi/tags/IcebergTest.java
+++ b/kyuubi-common/src/test/java/org/apache/kyuubi/tags/IcebergTest.java
@@ -17,12 +17,11 @@
package org.apache.kyuubi.tags;
-import org.scalatest.TagAnnotation;
-
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import org.scalatest.TagAnnotation;
@TagAnnotation
@Retention(RetentionPolicy.RUNTIME)
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiDriver.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiDriver.java
index 4238d52..8e8014a 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiDriver.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiDriver.java
@@ -17,9 +17,6 @@
package org.apache.kyuubi.jdbc;
-/**
- * @deprecated Use `KyuubiHiveDriver` instead.
- */
+/** @deprecated Use `KyuubiHiveDriver` instead. */
@Deprecated
-public class KyuubiDriver extends KyuubiHiveDriver {
-}
+public class KyuubiDriver extends KyuubiHiveDriver {}
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiHiveDriver.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiHiveDriver.java
index ad689e6..46014d7 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiHiveDriver.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiHiveDriver.java
@@ -25,13 +25,10 @@ import java.util.Properties;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.logging.Logger;
-
-import org.apache.kyuubi.jdbc.hive.Utils;
import org.apache.kyuubi.jdbc.hive.KyuubiConnection;
+import org.apache.kyuubi.jdbc.hive.Utils;
-/**
- * Kyuubi JDBC driver to connect to Kyuubi server via HiveServer2 thrift protocol.
- */
+/** Kyuubi JDBC driver to connect to Kyuubi server via HiveServer2 thrift protocol. */
public class KyuubiHiveDriver implements Driver {
static {
try {
@@ -84,18 +81,19 @@ public class KyuubiHiveDriver implements Driver {
info = parseURLForPropertyInfo(url, info);
}
- DriverPropertyInfo hostProp = new DriverPropertyInfo(HOST_PROPERTY_KEY,
- info.getProperty(HOST_PROPERTY_KEY, ""));
+ DriverPropertyInfo hostProp =
+ new DriverPropertyInfo(HOST_PROPERTY_KEY, info.getProperty(HOST_PROPERTY_KEY, ""));
hostProp.required = false;
hostProp.description = "Hostname of Kyuubi Server";
- DriverPropertyInfo portProp = new DriverPropertyInfo(PORT_PROPERTY_KEY,
- info.getProperty(PORT_PROPERTY_KEY, ""));
+ DriverPropertyInfo portProp =
+ new DriverPropertyInfo(PORT_PROPERTY_KEY, info.getProperty(PORT_PROPERTY_KEY, ""));
portProp.required = false;
portProp.description = "Port number of Kyuubi Server";
- DriverPropertyInfo dbProp = new DriverPropertyInfo(DBNAME_PROPERTY_KEY,
- info.getProperty(DBNAME_PROPERTY_KEY, "default"));
+ DriverPropertyInfo dbProp =
+ new DriverPropertyInfo(
+ DBNAME_PROPERTY_KEY, info.getProperty(DBNAME_PROPERTY_KEY, "default"));
dbProp.required = false;
dbProp.description = "Database name";
@@ -108,20 +106,17 @@ public class KyuubiHiveDriver implements Driver {
return dpi;
}
- /**
- * Returns whether the driver is JDBC compliant.
- */
+ /** Returns whether the driver is JDBC compliant. */
@Override
public boolean jdbcCompliant() {
return false;
}
-
/**
- * Takes a url in the form of jdbc:hive://[hostname]:[port]/[db_name] and
- * parses it. Everything after jdbc:hive// is optional.
- * <p>
- * The output from Utils.parseUrl() is massaged for the needs of getPropertyInfo
+ * Takes a url in the form of jdbc:hive://[hostname]:[port]/[db_name] and parses it. Everything
+ * after jdbc:hive// is optional.
+ *
+ * <p>The output from Utils.parseUrl() is massaged for the needs of getPropertyInfo
*/
private Properties parseURLForPropertyInfo(String url, Properties defaults) throws SQLException {
Properties urlProps = (defaults != null) ? new Properties(defaults) : new Properties();
@@ -132,7 +127,8 @@ public class KyuubiHiveDriver implements Driver {
Utils.JdbcConnectionParams params;
try {
- Method parseURLMethod = Utils.class.getDeclaredMethod("parseURL", String.class, Properties.class);
+ Method parseURLMethod =
+ Utils.class.getDeclaredMethod("parseURL", String.class, Properties.class);
parseURLMethod.setAccessible(true);
params = (Utils.JdbcConnectionParams) parseURLMethod.invoke(null, url, defaults);
} catch (Exception e) {
@@ -156,14 +152,10 @@ public class KyuubiHiveDriver implements Driver {
return urlProps;
}
- /**
- * Lazy-load manifest attributes as needed.
- */
+ /** Lazy-load manifest attributes as needed. */
private static Attributes manifestAttributes = null;
- /**
- * Loads the manifest attributes from the jar.
- */
+ /** Loads the manifest attributes from the jar. */
private static synchronized void loadManifestAttributes() throws IOException {
if (manifestAttributes != null) {
return;
@@ -176,8 +168,8 @@ public class KyuubiHiveDriver implements Driver {
}
/**
- * Package scoped to allow manifest fetching from other KyuubiHiveDriver classes
- * Helper to initialize attributes and return one.
+ * Package scoped to allow manifest fetching from other KyuubiHiveDriver classes Helper to
+ * initialize attributes and return one.
*/
public static String fetchManifestAttribute(Attributes.Name attributeName) throws SQLException {
try {
@@ -192,7 +184,7 @@ public class KyuubiHiveDriver implements Driver {
* Package scoped access to the Driver's Major Version
*
* @return The Major version number of the driver. -1 if it cannot be determined from the
- * manifest.mf file.
+ * manifest.mf file.
*/
public static int getMajorDriverVersion() {
int version = -1;
@@ -215,7 +207,7 @@ public class KyuubiHiveDriver implements Driver {
* Package scoped access to the Driver's Minor Version
*
* @return The Minor version number of the driver. -1 if it cannot be determined from the
- * manifest.mf file.
+ * manifest.mf file.
*/
public static int getMinorDriverVersion() {
int version = -1;
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/ClosedOrCancelledStatementException.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/ClosedOrCancelledStatementException.java
index 099830a..bda6a0e 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/ClosedOrCancelledStatementException.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/ClosedOrCancelledStatementException.java
@@ -19,13 +19,11 @@ package org.apache.kyuubi.jdbc.hive;
import java.sql.SQLException;
-public class ClosedOrCancelledStatementException extends SQLException{
+public class ClosedOrCancelledStatementException extends SQLException {
private static final long serialVersionUID = 0;
- /**
- * @param msg (exception message)
- */
+ /** @param msg (exception message) */
public ClosedOrCancelledStatementException(String msg) {
super(msg);
}
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/HttpBasicAuthInterceptor.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/HttpBasicAuthInterceptor.java
index 2ee735b..b7d3d65 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/HttpBasicAuthInterceptor.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/HttpBasicAuthInterceptor.java
@@ -18,7 +18,6 @@
package org.apache.kyuubi.jdbc.hive;
import java.util.Map;
-
import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.apache.http.auth.UsernamePasswordCredentials;
@@ -28,26 +27,30 @@ import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.protocol.HttpContext;
/**
- * The class is instantiated with the username and password, it is then
- * used to add header with these credentials to HTTP requests
- *
+ * The class is instantiated with the username and password, it is then used to add header with
+ * these credentials to HTTP requests
*/
public class HttpBasicAuthInterceptor extends HttpRequestInterceptorBase {
UsernamePasswordCredentials credentials;
AuthSchemeBase authScheme;
- public HttpBasicAuthInterceptor(String username, String password, CookieStore cookieStore,
- String cn, boolean isSSL, Map<String, String> additionalHeaders) {
+ public HttpBasicAuthInterceptor(
+ String username,
+ String password,
+ CookieStore cookieStore,
+ String cn,
+ boolean isSSL,
+ Map<String, String> additionalHeaders) {
super(cookieStore, cn, isSSL, additionalHeaders);
this.authScheme = new BasicScheme();
- if (username != null){
+ if (username != null) {
this.credentials = new UsernamePasswordCredentials(username, password);
}
}
@Override
protected void addHttpAuthHeader(HttpRequest httpRequest, HttpContext httpContext)
- throws Exception {
+ throws Exception {
Header basicAuthHeader = authScheme.authenticate(credentials, httpRequest, httpContext);
httpRequest.addHeader(basicAuthHeader);
}
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/HttpKerberosRequestInterceptor.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/HttpKerberosRequestInterceptor.java
index 60d0a14..6b8b291 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/HttpKerberosRequestInterceptor.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/HttpKerberosRequestInterceptor.java
@@ -19,7 +19,6 @@ package org.apache.kyuubi.jdbc.hive;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
-
import org.apache.hive.service.auth.HttpAuthUtils;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
@@ -27,9 +26,8 @@ import org.apache.http.client.CookieStore;
import org.apache.http.protocol.HttpContext;
/**
- * Authentication interceptor which adds Base64 encoded payload,
- * containing the username and kerberos service ticket,
- * to the outgoing http request header.
+ * Authentication interceptor which adds Base64 encoded payload, containing the username and
+ * kerberos service ticket, to the outgoing http request header.
*/
public class HttpKerberosRequestInterceptor extends HttpRequestInterceptorBase {
@@ -41,9 +39,15 @@ public class HttpKerberosRequestInterceptor extends HttpRequestInterceptorBase {
// A fair reentrant lock
private static ReentrantLock kerberosLock = new ReentrantLock(true);
- public HttpKerberosRequestInterceptor(String principal, String host,
- String serverHttpUrl, boolean assumeSubject, CookieStore cs, String cn,
- boolean isSSL, Map<String, String> additionalHeaders) {
+ public HttpKerberosRequestInterceptor(
+ String principal,
+ String host,
+ String serverHttpUrl,
+ boolean assumeSubject,
+ CookieStore cs,
+ String cn,
+ boolean isSSL,
+ Map<String, String> additionalHeaders) {
super(cs, cn, isSSL, additionalHeaders);
this.principal = principal;
this.host = host;
@@ -52,17 +56,17 @@ public class HttpKerberosRequestInterceptor extends HttpRequestInterceptorBase {
}
@Override
- protected void addHttpAuthHeader(HttpRequest httpRequest,
- HttpContext httpContext) throws Exception {
- try {
+ protected void addHttpAuthHeader(HttpRequest httpRequest, HttpContext httpContext)
+ throws Exception {
+ try {
// Generate the service ticket for sending to the server.
// Locking ensures the tokens are unique in case of concurrent requests
kerberosLock.lock();
- String kerberosAuthHeader = HttpAuthUtils.getKerberosServiceTicket(
- principal, host, serverHttpUrl, assumeSubject);
+ String kerberosAuthHeader =
+ HttpAuthUtils.getKerberosServiceTicket(principal, host, serverHttpUrl, assumeSubject);
// Set the session key token (Base64 encoded) in the headers
- httpRequest.addHeader(HttpAuthUtils.AUTHORIZATION + ": " +
- HttpAuthUtils.NEGOTIATE + " ", kerberosAuthHeader);
+ httpRequest.addHeader(
+ HttpAuthUtils.AUTHORIZATION + ": " + HttpAuthUtils.NEGOTIATE + " ", kerberosAuthHeader);
} catch (Exception e) {
throw new HttpException(e.getMessage(), e);
} finally {
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/HttpRequestInterceptorBase.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/HttpRequestInterceptorBase.java
index f83664f..2a02769 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/HttpRequestInterceptorBase.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/HttpRequestInterceptorBase.java
@@ -19,7 +19,6 @@ package org.apache.kyuubi.jdbc.hive;
import java.io.IOException;
import java.util.Map;
-
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
@@ -36,10 +35,10 @@ public abstract class HttpRequestInterceptorBase implements HttpRequestIntercept
// Abstract function to add HttpAuth Header
protected abstract void addHttpAuthHeader(HttpRequest httpRequest, HttpContext httpContext)
- throws Exception;
+ throws Exception;
- public HttpRequestInterceptorBase(CookieStore cs, String cn, boolean isSSL,
- Map<String, String> additionalHeaders) {
+ public HttpRequestInterceptorBase(
+ CookieStore cs, String cn, boolean isSSL, Map<String, String> additionalHeaders) {
this.cookieStore = cs;
this.isCookieEnabled = (cs != null);
this.cookieName = cn;
@@ -49,7 +48,7 @@ public abstract class HttpRequestInterceptorBase implements HttpRequestIntercept
@Override
public void process(HttpRequest httpRequest, HttpContext httpContext)
- throws HttpException, IOException {
+ throws HttpException, IOException {
try {
// If cookie based authentication is allowed, generate ticket only when necessary.
// The necessary condition is either when there are no server side cookies in the
@@ -63,12 +62,15 @@ public abstract class HttpRequestInterceptorBase implements HttpRequestIntercept
// 2. The first time when the request is sent OR
// 3. The server returns a 401, which sometimes means the cookie has expired
// 4. The cookie is secured where as the client connect does not use SSL
- if (!isCookieEnabled || ((httpContext.getAttribute(Utils.HIVE_SERVER2_RETRY_KEY) == null &&
- (cookieStore == null || (cookieStore != null &&
- Utils.needToSendCredentials(cookieStore, cookieName, isSSL)))) ||
- (httpContext.getAttribute(Utils.HIVE_SERVER2_RETRY_KEY) != null &&
- httpContext.getAttribute(Utils.HIVE_SERVER2_RETRY_KEY).
- equals(Utils.HIVE_SERVER2_RETRY_TRUE)))) {
+ if (!isCookieEnabled
+ || ((httpContext.getAttribute(Utils.HIVE_SERVER2_RETRY_KEY) == null
+ && (cookieStore == null
+ || (cookieStore != null
+ && Utils.needToSendCredentials(cookieStore, cookieName, isSSL))))
+ || (httpContext.getAttribute(Utils.HIVE_SERVER2_RETRY_KEY) != null
+ && httpContext
+ .getAttribute(Utils.HIVE_SERVER2_RETRY_KEY)
+ .equals(Utils.HIVE_SERVER2_RETRY_TRUE)))) {
addHttpAuthHeader(httpRequest, httpContext);
}
if (isCookieEnabled) {
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/HttpTokenAuthInterceptor.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/HttpTokenAuthInterceptor.java
index 27c9fb5..2660411 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/HttpTokenAuthInterceptor.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/HttpTokenAuthInterceptor.java
@@ -18,29 +18,31 @@
package org.apache.kyuubi.jdbc.hive;
import java.util.Map;
-
import org.apache.http.HttpRequest;
import org.apache.http.client.CookieStore;
import org.apache.http.protocol.HttpContext;
/**
- * The class is instantiated with the username and password, it is then
- * used to add header with these credentials to HTTP requests
- *
+ * The class is instantiated with the username and password, it is then used to add header with
+ * these credentials to HTTP requests
*/
public class HttpTokenAuthInterceptor extends HttpRequestInterceptorBase {
private String tokenStr;
- private static final String HIVE_DELEGATION_TOKEN_HEADER = "X-Hive-Delegation-Token";
-
- public HttpTokenAuthInterceptor(String tokenStr, CookieStore cookieStore, String cn,
- boolean isSSL, Map<String, String> additionalHeaders) {
+ private static final String HIVE_DELEGATION_TOKEN_HEADER = "X-Hive-Delegation-Token";
+
+ public HttpTokenAuthInterceptor(
+ String tokenStr,
+ CookieStore cookieStore,
+ String cn,
+ boolean isSSL,
+ Map<String, String> additionalHeaders) {
super(cookieStore, cn, isSSL, additionalHeaders);
this.tokenStr = tokenStr;
}
@Override
protected void addHttpAuthHeader(HttpRequest httpRequest, HttpContext httpContext)
- throws Exception {
+ throws Exception {
httpRequest.addHeader(HIVE_DELEGATION_TOKEN_HEADER, tokenStr);
}
}
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/JdbcColumn.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/JdbcColumn.java
index 0403363..e98444f 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/JdbcColumn.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/JdbcColumn.java
@@ -22,16 +22,12 @@ import java.sql.Date;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
-
import org.apache.hadoop.hive.common.type.HiveIntervalDayTime;
import org.apache.hadoop.hive.common.type.HiveIntervalYearMonth;
import org.apache.hadoop.hive.serde.serdeConstants;
import org.apache.hadoop.hive.serde2.thrift.Type;
-
-/**
- * Column metadata.
- */
+/** Column metadata. */
public class JdbcColumn {
private final String columnName;
private final String tableName;
@@ -40,8 +36,13 @@ public class JdbcColumn {
private final String comment;
private final int ordinalPos;
- JdbcColumn(String columnName, String tableName, String tableCatalog
- , String type, String comment, int ordinalPos) {
+ JdbcColumn(
+ String columnName,
+ String tableName,
+ String tableCatalog,
+ String type,
+ String comment,
+ int ordinalPos) {
this.columnName = columnName;
this.tableName = tableName;
this.tableCatalog = tableCatalog;
@@ -69,7 +70,7 @@ public class JdbcColumn {
static String columnClassName(Type hiveType, JdbcColumnAttributes columnAttributes)
throws SQLException {
int columnType = hiveTypeToSqlType(hiveType);
- switch(columnType) {
+ switch (columnType) {
case Types.NULL:
return "null";
case Types.BOOLEAN:
@@ -91,23 +92,24 @@ public class JdbcColumn {
return Float.class.getName();
case Types.DOUBLE:
return Double.class.getName();
- case Types.TIMESTAMP:
+ case Types.TIMESTAMP:
return Timestamp.class.getName();
case Types.DECIMAL:
return BigInteger.class.getName();
case Types.BINARY:
return byte[].class.getName();
case Types.OTHER:
- case Types.JAVA_OBJECT: {
- switch (hiveType) {
- case INTERVAL_YEAR_MONTH_TYPE:
- return HiveIntervalYearMonth.class.getName();
- case INTERVAL_DAY_TIME_TYPE:
- return HiveIntervalDayTime.class.getName();
- default:
- return String.class.getName();
+ case Types.JAVA_OBJECT:
+ {
+ switch (hiveType) {
+ case INTERVAL_YEAR_MONTH_TYPE:
+ return HiveIntervalYearMonth.class.getName();
+ case INTERVAL_DAY_TIME_TYPE:
+ return HiveIntervalDayTime.class.getName();
+ default:
+ return String.class.getName();
+ }
}
- }
case Types.ARRAY:
case Types.STRUCT:
return String.class.getName();
@@ -221,42 +223,44 @@ public class JdbcColumn {
throws SQLException {
// according to hiveTypeToSqlType possible options are:
int columnType = hiveTypeToSqlType(hiveType);
- switch(columnType) {
- case Types.NULL:
- return 4; // "NULL"
- case Types.BOOLEAN:
- return columnPrecision(hiveType, columnAttributes);
- case Types.CHAR:
- case Types.VARCHAR:
- return columnPrecision(hiveType, columnAttributes);
- case Types.BINARY:
- return Integer.MAX_VALUE; // hive has no max limit for binary
- case Types.TINYINT:
- case Types.SMALLINT:
- case Types.INTEGER:
- case Types.BIGINT:
- return columnPrecision(hiveType, columnAttributes) + 1; // allow +/-
- case Types.DATE:
- return 10;
- case Types.TIMESTAMP:
- return columnPrecision(hiveType, columnAttributes);
+ switch (columnType) {
+ case Types.NULL:
+ return 4; // "NULL"
+ case Types.BOOLEAN:
+ return columnPrecision(hiveType, columnAttributes);
+ case Types.CHAR:
+ case Types.VARCHAR:
+ return columnPrecision(hiveType, columnAttributes);
+ case Types.BINARY:
+ return Integer.MAX_VALUE; // hive has no max limit for binary
+ case Types.TINYINT:
+ case Types.SMALLINT:
+ case Types.INTEGER:
+ case Types.BIGINT:
+ return columnPrecision(hiveType, columnAttributes) + 1; // allow +/-
+ case Types.DATE:
+ return 10;
+ case Types.TIMESTAMP:
+ return columnPrecision(hiveType, columnAttributes);
- // see http://download.oracle.com/javase/6/docs/api/constant-values.html#java.lang.Float.MAX_EXPONENT
- case Types.FLOAT:
- return 24; // e.g. -(17#).e-###
- // see http://download.oracle.com/javase/6/docs/api/constant-values.html#java.lang.Double.MAX_EXPONENT
- case Types.DOUBLE:
- return 25; // e.g. -(17#).e-####
- case Types.DECIMAL:
- return columnPrecision(hiveType, columnAttributes) + 2; // '-' sign and '.'
- case Types.OTHER:
- case Types.JAVA_OBJECT:
- return columnPrecision(hiveType, columnAttributes);
- case Types.ARRAY:
- case Types.STRUCT:
- return Integer.MAX_VALUE;
- default:
- throw new SQLException("Invalid column type: " + columnType);
+ // see
+ // http://download.oracle.com/javase/6/docs/api/constant-values.html#java.lang.Float.MAX_EXPONENT
+ case Types.FLOAT:
+ return 24; // e.g. -(17#).e-###
+ // see
+ // http://download.oracle.com/javase/6/docs/api/constant-values.html#java.lang.Double.MAX_EXPONENT
+ case Types.DOUBLE:
+ return 25; // e.g. -(17#).e-####
+ case Types.DECIMAL:
+ return columnPrecision(hiveType, columnAttributes) + 2; // '-' sign and '.'
+ case Types.OTHER:
+ case Types.JAVA_OBJECT:
+ return columnPrecision(hiveType, columnAttributes);
+ case Types.ARRAY:
+ case Types.STRUCT:
+ return Integer.MAX_VALUE;
+ default:
+ throw new SQLException("Invalid column type: " + columnType);
}
}
@@ -264,89 +268,89 @@ public class JdbcColumn {
throws SQLException {
int columnType = hiveTypeToSqlType(hiveType);
// according to hiveTypeToSqlType possible options are:
- switch(columnType) {
- case Types.NULL:
- return 0;
- case Types.BOOLEAN:
- return 1;
- case Types.CHAR:
- case Types.VARCHAR:
- if (columnAttributes != null) {
+ switch (columnType) {
+ case Types.NULL:
+ return 0;
+ case Types.BOOLEAN:
+ return 1;
+ case Types.CHAR:
+ case Types.VARCHAR:
+ if (columnAttributes != null) {
+ return columnAttributes.precision;
+ }
+ return Integer.MAX_VALUE; // hive has no max limit for strings
+ case Types.BINARY:
+ return Integer.MAX_VALUE; // hive has no max limit for binary
+ case Types.TINYINT:
+ return 3;
+ case Types.SMALLINT:
+ return 5;
+ case Types.INTEGER:
+ return 10;
+ case Types.BIGINT:
+ return 19;
+ case Types.FLOAT:
+ return 7;
+ case Types.DOUBLE:
+ return 15;
+ case Types.DATE:
+ return 10;
+ case Types.TIMESTAMP:
+ return 29;
+ case Types.DECIMAL:
return columnAttributes.precision;
- }
- return Integer.MAX_VALUE; // hive has no max limit for strings
- case Types.BINARY:
- return Integer.MAX_VALUE; // hive has no max limit for binary
- case Types.TINYINT:
- return 3;
- case Types.SMALLINT:
- return 5;
- case Types.INTEGER:
- return 10;
- case Types.BIGINT:
- return 19;
- case Types.FLOAT:
- return 7;
- case Types.DOUBLE:
- return 15;
- case Types.DATE:
- return 10;
- case Types.TIMESTAMP:
- return 29;
- case Types.DECIMAL:
- return columnAttributes.precision;
- case Types.OTHER:
- case Types.JAVA_OBJECT: {
- switch (hiveType) {
- case INTERVAL_YEAR_MONTH_TYPE:
- // -yyyyyyy-mm : should be more than enough
- return 11;
- case INTERVAL_DAY_TIME_TYPE:
- // -ddddddddd hh:mm:ss.nnnnnnnnn
- return 29;
- default:
- return Integer.MAX_VALUE;
- }
- }
- case Types.ARRAY:
- case Types.STRUCT:
- return Integer.MAX_VALUE;
- default:
- throw new SQLException("Invalid column type: " + columnType);
+ case Types.OTHER:
+ case Types.JAVA_OBJECT:
+ {
+ switch (hiveType) {
+ case INTERVAL_YEAR_MONTH_TYPE:
+ // -yyyyyyy-mm : should be more than enough
+ return 11;
+ case INTERVAL_DAY_TIME_TYPE:
+ // -ddddddddd hh:mm:ss.nnnnnnnnn
+ return 29;
+ default:
+ return Integer.MAX_VALUE;
+ }
+ }
+ case Types.ARRAY:
+ case Types.STRUCT:
+ return Integer.MAX_VALUE;
+ default:
+ throw new SQLException("Invalid column type: " + columnType);
}
}
- static int columnScale(Type hiveType, JdbcColumnAttributes columnAttributes)
- throws SQLException {
+ static int columnScale(Type hiveType, JdbcColumnAttributes columnAttributes) throws SQLException {
int columnType = hiveTypeToSqlType(hiveType);
// according to hiveTypeToSqlType possible options are:
- switch(columnType) {
- case Types.NULL:
- case Types.BOOLEAN:
- case Types.CHAR:
- case Types.VARCHAR:
- case Types.TINYINT:
- case Types.SMALLINT:
- case Types.INTEGER:
- case Types.BIGINT:
- case Types.DATE:
- case Types.BINARY:
- return 0;
- case Types.FLOAT:
- return 7;
- case Types.DOUBLE:
- return 15;
- case Types.TIMESTAMP:
- return 9;
- case Types.DECIMAL:
- return columnAttributes.scale;
- case Types.OTHER:
- case Types.JAVA_OBJECT:
- case Types.ARRAY:
- case Types.STRUCT:
- return 0;
- default:
- throw new SQLException("Invalid column type: " + columnType);
+ switch (columnType) {
+ case Types.NULL:
+ case Types.BOOLEAN:
+ case Types.CHAR:
+ case Types.VARCHAR:
+ case Types.TINYINT:
+ case Types.SMALLINT:
+ case Types.INTEGER:
+ case Types.BIGINT:
+ case Types.DATE:
+ case Types.BINARY:
+ return 0;
+ case Types.FLOAT:
+ return 7;
+ case Types.DOUBLE:
+ return 15;
+ case Types.TIMESTAMP:
+ return 9;
+ case Types.DECIMAL:
+ return columnAttributes.scale;
+ case Types.OTHER:
+ case Types.JAVA_OBJECT:
+ case Types.ARRAY:
+ case Types.STRUCT:
+ return 0;
+ default:
+ throw new SQLException("Invalid column type: " + columnType);
}
}
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/JdbcColumnAttributes.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/JdbcColumnAttributes.java
index ca078ce..928df51 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/JdbcColumnAttributes.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/JdbcColumnAttributes.java
@@ -21,8 +21,7 @@ class JdbcColumnAttributes {
public int precision = 0;
public int scale = 0;
- public JdbcColumnAttributes() {
- }
+ public JdbcColumnAttributes() {}
public JdbcColumnAttributes(int precision, int scale) {
this.precision = precision;
@@ -33,5 +32,4 @@ class JdbcColumnAttributes {
public String toString() {
return "(" + precision + "," + scale + ")";
}
-
}
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/JdbcTable.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/JdbcTable.java
index 0bd7a02..a0127cf 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/JdbcTable.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/JdbcTable.java
@@ -19,10 +19,7 @@ package org.apache.kyuubi.jdbc.hive;
import java.sql.SQLException;
-
-/**
- * Table metadata.
- */
+/** Table metadata. */
public class JdbcTable {
private String tableCatalog;
private String tableName;
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/JdbcUriParseException.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/JdbcUriParseException.java
index cfd537d..17768d4 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/JdbcUriParseException.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/JdbcUriParseException.java
@@ -23,16 +23,12 @@ public class JdbcUriParseException extends SQLException {
private static final long serialVersionUID = 0;
- /**
- * @param cause (original exception)
- */
+ /** @param cause (original exception) */
public JdbcUriParseException(Throwable cause) {
super(cause);
}
- /**
- * @param msg (exception message)
- */
+ /** @param msg (exception message) */
public JdbcUriParseException(String msg) {
super(msg);
}
@@ -44,5 +40,4 @@ public class JdbcUriParseException extends SQLException {
public JdbcUriParseException(String msg, Throwable cause) {
super(msg, cause);
}
-
}
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java
index f6a5e28..a7dbd12 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiBaseResultSet.java
@@ -43,16 +43,12 @@ import java.sql.Timestamp;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
-
import org.apache.hadoop.hive.common.type.HiveIntervalDayTime;
import org.apache.hadoop.hive.common.type.HiveIntervalYearMonth;
import org.apache.hadoop.hive.serde2.thrift.Type;
import org.apache.hive.service.cli.TableSchema;
-/**
- * Data independent base class which implements the common part of
- * all Kyuubi result sets.
- */
+/** Data independent base class which implements the common part of all Kyuubi result sets. */
public abstract class KyuubiBaseResultSet implements ResultSet {
protected Statement statement = null;
@@ -92,7 +88,7 @@ public abstract class KyuubiBaseResultSet implements ResultSet {
for (String normalizedColumnName : normalizedColumnNames) {
++columnIndex;
String[] names = normalizedColumnName.split("\\.");
- String name = names[names.length -1];
+ String name = names[names.length - 1];
if (name.equalsIgnoreCase(columnName) || normalizedColumnName.equalsIgnoreCase(columnName)) {
findColumn = true;
break;
@@ -129,7 +125,7 @@ public abstract class KyuubiBaseResultSet implements ResultSet {
Object val = getObject(columnIndex);
if (val == null || val instanceof BigDecimal) {
- return (BigDecimal)val;
+ return (BigDecimal) val;
}
throw new SQLException("Illegal conversion");
@@ -153,19 +149,21 @@ public abstract class KyuubiBaseResultSet implements ResultSet {
if (obj == null) {
return null;
} else if (obj instanceof InputStream) {
- return (InputStream)obj;
+ return (InputStream) obj;
} else if (obj instanceof byte[]) {
- byte[] byteArray = (byte[])obj;
+ byte[] byteArray = (byte[]) obj;
InputStream is = new ByteArrayInputStream(byteArray);
return is;
} else if (obj instanceof String) {
- String str = (String)obj;
+ String str = (String) obj;
InputStream is = null;
try {
is = new ByteArrayInputStream(str.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
- throw new SQLException("Illegal conversion to binary stream from column " +
- columnIndex + " - Unsupported encoding exception");
+ throw new SQLException(
+ "Illegal conversion to binary stream from column "
+ + columnIndex
+ + " - Unsupported encoding exception");
}
return is;
}
@@ -258,15 +256,14 @@ public abstract class KyuubiBaseResultSet implements ResultSet {
}
try {
if (obj instanceof String) {
- return Date.valueOf((String)obj);
+ return Date.valueOf((String) obj);
}
} catch (Exception e) {
- throw new SQLException("Cannot convert column " + columnIndex
- + " to date: " + e.toString(), e);
+ throw new SQLException(
+ "Cannot convert column " + columnIndex + " to date: " + e.toString(), e);
}
// If we fell through to here this is not a valid type conversion
- throw new SQLException("Cannot convert column " + columnIndex
- + " to date: Illegal conversion");
+ throw new SQLException("Cannot convert column " + columnIndex + " to date: Illegal conversion");
}
public Date getDate(String columnName) throws SQLException {
@@ -289,12 +286,12 @@ public abstract class KyuubiBaseResultSet implements ResultSet {
} else if (obj == null) {
return 0;
} else if (String.class.isInstance(obj)) {
- return Double.parseDouble((String)obj);
+ return Double.parseDouble((String) obj);
}
throw new Exception("Illegal conversion");
} catch (Exception e) {
- throw new SQLException("Cannot convert column " + columnIndex
- + " to double: " + e.toString(), e);
+ throw new SQLException(
+ "Cannot convert column " + columnIndex + " to double: " + e.toString(), e);
}
}
@@ -318,12 +315,12 @@ public abstract class KyuubiBaseResultSet implements ResultSet {
} else if (obj == null) {
return 0;
} else if (String.class.isInstance(obj)) {
- return Float.parseFloat((String)obj);
+ return Float.parseFloat((String) obj);
}
throw new Exception("Illegal conversion");
} catch (Exception e) {
- throw new SQLException("Cannot convert column " + columnIndex
- + " to float: " + e.toString(), e);
+ throw new SQLException(
+ "Cannot convert column " + columnIndex + " to float: " + e.toString(), e);
}
}
@@ -343,13 +340,12 @@ public abstract class KyuubiBaseResultSet implements ResultSet {
} else if (obj == null) {
return 0;
} else if (String.class.isInstance(obj)) {
- return Integer.parseInt((String)obj);
+ return Integer.parseInt((String) obj);
}
throw new Exception("Illegal conversion");
} catch (Exception e) {
throw new SQLException(
- "Cannot convert column " + columnIndex + " to integer" + e.toString(),
- e);
+ "Cannot convert column " + columnIndex + " to integer" + e.toString(), e);
}
}
@@ -365,13 +361,12 @@ public abstract class KyuubiBaseResultSet implements ResultSet {
} else if (obj == null) {
return 0;
} else if (String.class.isInstance(obj)) {
- return Long.parseLong((String)obj);
+ return Long.parseLong((String) obj);
}
throw new Exception("Illegal conversion");
} catch (Exception e) {
throw new SQLException(
- "Cannot convert column " + columnIndex + " to long: " + e.toString(),
- e);
+ "Cannot convert column " + columnIndex + " to long: " + e.toString(), e);
}
}
@@ -442,7 +437,7 @@ public abstract class KyuubiBaseResultSet implements ResultSet {
case TIMESTAMP_TYPE:
return Timestamp.valueOf((String) value);
case DECIMAL_TYPE:
- return new BigDecimal((String)value);
+ return new BigDecimal((String) value);
case DATE_TYPE:
return Date.valueOf((String) value);
case INTERVAL_YEAR_MONTH_TYPE:
@@ -511,12 +506,12 @@ public abstract class KyuubiBaseResultSet implements ResultSet {
} else if (obj == null) {
return 0;
} else if (String.class.isInstance(obj)) {
- return Short.parseShort((String)obj);
+ return Short.parseShort((String) obj);
}
throw new Exception("Illegal conversion");
} catch (Exception e) {
- throw new SQLException("Cannot convert column " + columnIndex
- + " to short: " + e.toString(), e);
+ throw new SQLException(
+ "Cannot convert column " + columnIndex + " to short: " + e.toString(), e);
}
}
@@ -537,8 +532,8 @@ public abstract class KyuubiBaseResultSet implements ResultSet {
if (wasNull) {
return null;
}
- if (value instanceof byte[]){
- return new String((byte[])value);
+ if (value instanceof byte[]) {
+ return new String((byte[]) value);
}
return value.toString();
}
@@ -572,7 +567,7 @@ public abstract class KyuubiBaseResultSet implements ResultSet {
return (Timestamp) obj;
}
if (obj instanceof String) {
- return Timestamp.valueOf((String)obj);
+ return Timestamp.valueOf((String) obj);
}
throw new SQLException("Illegal conversion");
}
@@ -693,23 +688,20 @@ public abstract class KyuubiBaseResultSet implements ResultSet {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public void updateAsciiStream(int columnIndex, InputStream x, int length)
- throws SQLException {
+ public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public void updateAsciiStream(String columnName, InputStream x, int length)
- throws SQLException {
+ public void updateAsciiStream(String columnName, InputStream x, int length) throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public void updateAsciiStream(int columnIndex, InputStream x, long length)
- throws SQLException {
+ public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
public void updateAsciiStream(String columnLabel, InputStream x, long length)
- throws SQLException {
+ throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -729,23 +721,20 @@ public abstract class KyuubiBaseResultSet implements ResultSet {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public void updateBinaryStream(int columnIndex, InputStream x, int length)
- throws SQLException {
+ public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public void updateBinaryStream(String columnName, InputStream x, int length)
- throws SQLException {
+ public void updateBinaryStream(String columnName, InputStream x, int length) throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public void updateBinaryStream(int columnIndex, InputStream x, long length)
- throws SQLException {
+ public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
public void updateBinaryStream(String columnLabel, InputStream x, long length)
- throws SQLException {
+ throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -766,12 +755,12 @@ public abstract class KyuubiBaseResultSet implements ResultSet {
}
public void updateBlob(int columnIndex, InputStream inputStream, long length)
- throws SQLException {
+ throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public void updateBlob(String columnLabel, InputStream inputStream,
- long length) throws SQLException {
+ public void updateBlob(String columnLabel, InputStream inputStream, long length)
+ throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -807,23 +796,21 @@ public abstract class KyuubiBaseResultSet implements ResultSet {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public void updateCharacterStream(int columnIndex, Reader x, int length)
- throws SQLException {
+ public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
public void updateCharacterStream(String columnName, Reader reader, int length)
- throws SQLException {
+ throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public void updateCharacterStream(int columnIndex, Reader x, long length)
- throws SQLException {
+ public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public void updateCharacterStream(String columnLabel, Reader reader,
- long length) throws SQLException {
+ public void updateCharacterStream(String columnLabel, Reader reader, long length)
+ throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -903,8 +890,8 @@ public abstract class KyuubiBaseResultSet implements ResultSet {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public void updateNCharacterStream(String columnLabel, Reader reader,
- long length) throws SQLException {
+ public void updateNCharacterStream(String columnLabel, Reader reader, long length)
+ throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiCallableStatement.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiCallableStatement.java
index bb15baa..c5a31bf 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiCallableStatement.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiCallableStatement.java
@@ -41,16 +41,11 @@ import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Map;
-/**
- * KyuubiCallableStatement.
- *
- */
+/** KyuubiCallableStatement. */
public class KyuubiCallableStatement implements java.sql.CallableStatement {
private final Connection connection;
- /**
- *
- */
+ /** */
public KyuubiCallableStatement(Connection connection) {
this.connection = connection;
}
@@ -745,8 +740,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* @see java.sql.CallableStatement#registerOutParameter(int, int, int)
*/
- public void registerOutParameter(int parameterIndex, int sqlType, int scale)
- throws SQLException {
+ public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -784,8 +778,8 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.lang.String)
*/
- public void registerOutParameter(String parameterName, int sqlType,
- String typeName) throws SQLException {
+ public void registerOutParameter(String parameterName, int sqlType, String typeName)
+ throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -797,8 +791,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.io.InputStream)
*/
- public void setAsciiStream(String parameterName, InputStream x)
- throws SQLException {
+ public void setAsciiStream(String parameterName, InputStream x) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -810,8 +803,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.io.InputStream, int)
*/
- public void setAsciiStream(String parameterName, InputStream x, int length)
- throws SQLException {
+ public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -823,8 +815,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.io.InputStream, long)
*/
- public void setAsciiStream(String parameterName, InputStream x, long length)
- throws SQLException {
+ public void setAsciiStream(String parameterName, InputStream x, long length) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -836,8 +827,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.math.BigDecimal)
*/
- public void setBigDecimal(String parameterName, BigDecimal x)
- throws SQLException {
+ public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -849,8 +839,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.io.InputStream)
*/
- public void setBinaryStream(String parameterName, InputStream x)
- throws SQLException {
+ public void setBinaryStream(String parameterName, InputStream x) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -862,8 +851,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.io.InputStream, int)
*/
- public void setBinaryStream(String parameterName, InputStream x, int length)
- throws SQLException {
+ public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -899,8 +887,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.io.InputStream)
*/
- public void setBlob(String parameterName, InputStream inputStream)
- throws SQLException {
+ public void setBlob(String parameterName, InputStream inputStream) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -958,8 +945,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.io.Reader)
*/
- public void setCharacterStream(String parameterName, Reader reader)
- throws SQLException {
+ public void setCharacterStream(String parameterName, Reader reader) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -984,8 +970,8 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.io.Reader, long)
*/
- public void setCharacterStream(String parameterName, Reader reader,
- long length) throws SQLException {
+ public void setCharacterStream(String parameterName, Reader reader, long length)
+ throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1019,8 +1005,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* long)
*/
- public void setClob(String parameterName, Reader reader, long length)
- throws SQLException {
+ public void setClob(String parameterName, Reader reader, long length) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1043,8 +1028,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.util.Calendar)
*/
- public void setDate(String parameterName, Date x, Calendar cal)
- throws SQLException {
+ public void setDate(String parameterName, Date x, Calendar cal) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1100,8 +1084,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.io.Reader)
*/
- public void setNCharacterStream(String parameterName, Reader value)
- throws SQLException {
+ public void setNCharacterStream(String parameterName, Reader value) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1113,8 +1096,8 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.io.Reader, long)
*/
- public void setNCharacterStream(String parameterName, Reader value,
- long length) throws SQLException {
+ public void setNCharacterStream(String parameterName, Reader value, long length)
+ throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1148,8 +1131,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* long)
*/
- public void setNClob(String parameterName, Reader reader, long length)
- throws SQLException {
+ public void setNClob(String parameterName, Reader reader, long length) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1161,8 +1143,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.lang.String)
*/
- public void setNString(String parameterName, String value)
- throws SQLException {
+ public void setNString(String parameterName, String value) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1185,8 +1166,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.lang.String)
*/
- public void setNull(String parameterName, int sqlType, String typeName)
- throws SQLException {
+ public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1210,8 +1190,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.lang.Object, int)
*/
- public void setObject(String parameterName, Object x, int targetSqlType)
- throws SQLException {
+ public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1223,8 +1202,8 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.lang.Object, int, int)
*/
- public void setObject(String parameterName, Object x, int targetSqlType,
- int scale) throws SQLException {
+ public void setObject(String parameterName, Object x, int targetSqlType, int scale)
+ throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1247,8 +1226,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.sql.SQLXML)
*/
- public void setSQLXML(String parameterName, SQLXML xmlObject)
- throws SQLException {
+ public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1294,8 +1272,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.util.Calendar)
*/
- public void setTime(String parameterName, Time x, Calendar cal)
- throws SQLException {
+ public void setTime(String parameterName, Time x, Calendar cal) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1307,8 +1284,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.sql.Timestamp)
*/
- public void setTimestamp(String parameterName, Timestamp x)
- throws SQLException {
+ public void setTimestamp(String parameterName, Timestamp x) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1320,8 +1296,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.sql.Timestamp, java.util.Calendar)
*/
- public void setTimestamp(String parameterName, Timestamp x, Calendar cal)
- throws SQLException {
+ public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1453,8 +1428,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* int)
*/
- public void setAsciiStream(int parameterIndex, InputStream x, int length)
- throws SQLException {
+ public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1466,8 +1440,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* long)
*/
- public void setAsciiStream(int arg0, InputStream arg1, long arg2)
- throws SQLException {
+ public void setAsciiStream(int arg0, InputStream arg1, long arg2) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1478,8 +1451,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* @see java.sql.PreparedStatement#setBigDecimal(int, java.math.BigDecimal)
*/
- public void setBigDecimal(int parameterIndex, BigDecimal x)
- throws SQLException {
+ public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1490,8 +1462,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* @see java.sql.PreparedStatement#setBinaryStream(int, java.io.InputStream)
*/
- public void setBinaryStream(int parameterIndex, InputStream x)
- throws SQLException {
+ public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1503,8 +1474,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* int)
*/
- public void setBinaryStream(int parameterIndex, InputStream x, int length)
- throws SQLException {
+ public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1516,8 +1486,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* long)
*/
- public void setBinaryStream(int parameterIndex, InputStream x, long length)
- throws SQLException {
+ public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1539,8 +1508,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* @see java.sql.PreparedStatement#setBlob(int, java.io.InputStream)
*/
- public void setBlob(int parameterIndex, InputStream inputStream)
- throws SQLException {
+ public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1596,8 +1564,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* @see java.sql.PreparedStatement#setCharacterStream(int, java.io.Reader)
*/
- public void setCharacterStream(int parameterIndex, Reader reader)
- throws SQLException {
+ public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1656,8 +1623,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* @see java.sql.PreparedStatement#setClob(int, java.io.Reader, long)
*/
- public void setClob(int parameterIndex, Reader reader, long length)
- throws SQLException {
+ public void setClob(int parameterIndex, Reader reader, long length) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1680,8 +1646,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.util.Calendar)
*/
- public void setDate(int parameterIndex, Date x, Calendar cal)
- throws SQLException {
+ public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1736,8 +1701,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* @see java.sql.PreparedStatement#setNCharacterStream(int, java.io.Reader)
*/
- public void setNCharacterStream(int parameterIndex, Reader value)
- throws SQLException {
+ public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1783,8 +1747,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* @see java.sql.PreparedStatement#setNClob(int, java.io.Reader, long)
*/
- public void setNClob(int parameterIndex, Reader reader, long length)
- throws SQLException {
+ public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1817,8 +1780,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* @see java.sql.PreparedStatement#setNull(int, int, java.lang.String)
*/
- public void setNull(int paramIndex, int sqlType, String typeName)
- throws SQLException {
+ public void setNull(int paramIndex, int sqlType, String typeName) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1840,8 +1802,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* @see java.sql.PreparedStatement#setObject(int, java.lang.Object, int)
*/
- public void setObject(int parameterIndex, Object x, int targetSqlType)
- throws SQLException {
+ public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1852,8 +1813,8 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* @see java.sql.PreparedStatement#setObject(int, java.lang.Object, int, int)
*/
- public void setObject(int parameterIndex, Object x, int targetSqlType,
- int scale) throws SQLException {
+ public void setObject(int parameterIndex, Object x, int targetSqlType, int scale)
+ throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1886,8 +1847,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* @see java.sql.PreparedStatement#setSQLXML(int, java.sql.SQLXML)
*/
- public void setSQLXML(int parameterIndex, SQLXML xmlObject)
- throws SQLException {
+ public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1932,8 +1892,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.util.Calendar)
*/
- public void setTime(int parameterIndex, Time x, Calendar cal)
- throws SQLException {
+ public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1956,8 +1915,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* java.util.Calendar)
*/
- public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
- throws SQLException {
+ public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1980,8 +1938,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* int)
*/
- public void setUnicodeStream(int parameterIndex, InputStream x, int length)
- throws SQLException {
+ public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -2134,8 +2091,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* @see java.sql.Statement#executeUpdate(java.lang.String, int)
*/
- public int executeUpdate(String sql, int autoGeneratedKeys)
- throws SQLException {
+ public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -2157,8 +2113,7 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
* @see java.sql.Statement#executeUpdate(java.lang.String, java.lang.String[])
*/
- public int executeUpdate(String sql, String[] columnNames)
- throws SQLException {
+ public int executeUpdate(String sql, String[] columnNames) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -2458,5 +2413,4 @@ public class KyuubiCallableStatement implements java.sql.CallableStatement {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
-
}
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java
index 9acc959..873e651 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java
@@ -53,16 +53,15 @@ import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import javax.security.sasl.Sasl;
import javax.security.sasl.SaslException;
-
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.hive.common.auth.HiveAuthUtils;
-import org.apache.hive.service.cli.RowSet;
-import org.apache.hive.service.cli.RowSetFactory;
import org.apache.hive.service.auth.HiveAuthFactory;
import org.apache.hive.service.auth.KerberosSaslHelper;
import org.apache.hive.service.auth.PlainSaslHelper;
import org.apache.hive.service.auth.SaslQOP;
+import org.apache.hive.service.cli.RowSet;
+import org.apache.hive.service.cli.RowSetFactory;
import org.apache.hive.service.cli.thrift.*;
import org.apache.hive.service.rpc.thrift.*;
import org.apache.http.HttpRequestInterceptor;
@@ -82,6 +81,7 @@ import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
import org.apache.http.protocol.HttpContext;
import org.apache.http.ssl.SSLContexts;
+import org.apache.kyuubi.jdbc.hive.Utils.JdbcConnectionParams;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.transport.THttpClient;
@@ -90,12 +90,7 @@ import org.apache.thrift.transport.TTransportException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.kyuubi.jdbc.hive.Utils.JdbcConnectionParams;
-
-/**
- * KyuubiConnection.
- *
- */
+/** KyuubiConnection. */
public class KyuubiConnection implements java.sql.Connection {
public static final Logger LOG = LoggerFactory.getLogger(KyuubiConnection.class.getName());
private static boolean isBeeLineMode = false;
@@ -181,10 +176,10 @@ public class KyuubiConnection implements java.sql.Connection {
if (StringUtils.isNotBlank(strRetries)) {
maxRetries = Integer.parseInt(strRetries);
}
- } catch(NumberFormatException e) { // Ignore the exception
+ } catch (NumberFormatException e) { // Ignore the exception
}
- for (int numRetries = 0;;) {
+ for (int numRetries = 0; ; ) {
try {
// open the client transport
openTransport();
@@ -203,8 +198,9 @@ public class KyuubiConnection implements java.sql.Connection {
String warnMsg = "Could not open client transport with JDBC Uri: " + jdbcUriString + ": ";
if (isZkDynamicDiscoveryMode()) {
errMsg = "Could not open client transport for any of the Server URI's in ZooKeeper: ";
- // Try next available server in zookeeper, or retry all the servers again if retry is enabled
- while(!Utils.updateConnParamsFromZooKeeper(connParams) && ++numRetries < maxRetries) {
+ // Try next available server in zookeeper, or retry all the servers again if retry is
+ // enabled
+ while (!Utils.updateConnParamsFromZooKeeper(connParams) && ++numRetries < maxRetries) {
connParams.getRejectedHostZnodePaths().clear();
}
// Update with new values
@@ -230,40 +226,41 @@ public class KyuubiConnection implements java.sql.Connection {
}
/**
- * Check whether launch engine operation might be producing more logs to be fetched.
- * This method is a public API for usage outside of Kyuubi, although it is not part of the
- * interface java.sql.Connection.
- * @return true if launch engine operation might be producing more logs. It does not indicate
- * if last log lines have been fetched by getEngineLog.
+ * Check whether launch engine operation might be producing more logs to be fetched. This method
+ * is a public API for usage outside of Kyuubi, although it is not part of the interface
+ * java.sql.Connection.
+ *
+ * @return true if launch engine operation might be producing more logs. It does not indicate if
+ * last log lines have been fetched by getEngineLog.
*/
public boolean hasMoreEngineLogs() {
return launchEngineOpHandle != null && (!launchEngineOpCompleted || engineLogInflight);
}
/**
- * Get the launch engine operation logs of current connection.
- * This method is a public API for usage outside of Kyuubi, although it is not part of the
- * interface java.sql.Connection.
- * This method gets the incremental logs during launching engine, and uses fetchSize holden by
+ * Get the launch engine operation logs of current connection. This method is a public API for
+ * usage outside of Kyuubi, although it is not part of the interface java.sql.Connection. This
+ * method gets the incremental logs during launching engine, and uses fetchSize holden by
* KyuubiStatement object.
+ *
* @return a list of logs. It can be empty if there are no new logs to be retrieved at that time.
* @throws SQLException
* @throws ClosedConnectionException if connection has been closed
*/
public List<String> getEngineLog() throws SQLException, ClosedConnectionException {
if (isClosed()) {
- throw new ClosedConnectionException("Method getEngineLog() failed. The " +
- "connection has been closed.");
+ throw new ClosedConnectionException(
+ "Method getEngineLog() failed. The " + "connection has been closed.");
}
- TFetchResultsReq fetchResultsReq = new TFetchResultsReq(launchEngineOpHandle,
- TFetchOrientation.FETCH_NEXT, fetchSize);
+ TFetchResultsReq fetchResultsReq =
+ new TFetchResultsReq(launchEngineOpHandle, TFetchOrientation.FETCH_NEXT, fetchSize);
fetchResultsReq.setFetchType((short) 1);
List<String> logs = new ArrayList<>();
try {
TFetchResultsResp tFetchResultsResp = client.FetchResults(fetchResultsReq);
RowSet rowSet = RowSetFactory.create(tFetchResultsResp.getResults(), this.getProtocol());
- for (Object[] row: rowSet) {
+ for (Object[] row : rowSet) {
logs.add(String.valueOf(row[0]));
}
} catch (TException e) {
@@ -284,24 +281,25 @@ public class KyuubiConnection implements java.sql.Connection {
private void showLaunchEngineLog() {
if (launchEngineOpHandle != null) {
LOG.info("Starting to get launch engine log.");
- Thread logThread = new Thread("engine-launch-log") {
-
- @Override
- public void run() {
- try {
- while (hasMoreEngineLogs()) {
- List<String> logs = getEngineLog();
- for (String log: logs) {
- LOG.info(log);
+ Thread logThread =
+ new Thread("engine-launch-log") {
+
+ @Override
+ public void run() {
+ try {
+ while (hasMoreEngineLogs()) {
+ List<String> logs = getEngineLog();
+ for (String log : logs) {
+ LOG.info(log);
+ }
+ Thread.sleep(300);
+ }
+ } catch (Exception e) {
+ // do nothing
}
- Thread.sleep(300);
+ LOG.info("Finished to get launch engine log.");
}
- } catch (Exception e) {
- // do nothing
- }
- LOG.info("Finished to get launch engine log.");
- }
- };
+ };
logThread.start();
}
}
@@ -312,7 +310,7 @@ public class KyuubiConnection implements java.sql.Connection {
try {
List<String> sqlList = parseInitFile(initFile);
Statement st = createStatement();
- for(String sql : sqlList) {
+ for (String sql : sqlList) {
boolean hasResult = st.execute(sql);
if (hasResult) {
ResultSet rs = st.getResultSet();
@@ -321,7 +319,7 @@ public class KyuubiConnection implements java.sql.Connection {
}
}
}
- } catch(Exception e) {
+ } catch (Exception e) {
LOG.error("Failed to execute initial SQL");
throw new SQLException(e.getMessage());
}
@@ -350,7 +348,7 @@ public class KyuubiConnection implements java.sql.Connection {
}
}
initSqlList = getInitSql(sb.toString());
- } catch(IOException e) {
+ } catch (IOException e) {
LOG.error("Failed to read initial SQL file", e);
throw new IOException(e);
} finally {
@@ -376,16 +374,15 @@ public class KyuubiConnection implements java.sql.Connection {
return initSqlList;
}
-
private void openTransport() throws Exception {
- assumeSubject =
- JdbcConnectionParams.AUTH_KERBEROS_AUTH_TYPE_FROM_SUBJECT.equals(sessConfMap
- .get(JdbcConnectionParams.AUTH_KERBEROS_AUTH_TYPE));
- transport = isHttpTransportMode() ? createHttpTransport() : createBinaryTransport();
- if (!transport.isOpen()) {
- transport.open();
- logZkDiscoveryMessage("Connected to " + connParams.getHost() + ":" + connParams.getPort());
- }
+ assumeSubject =
+ JdbcConnectionParams.AUTH_KERBEROS_AUTH_TYPE_FROM_SUBJECT.equals(
+ sessConfMap.get(JdbcConnectionParams.AUTH_KERBEROS_AUTH_TYPE));
+ transport = isHttpTransportMode() ? createHttpTransport() : createBinaryTransport();
+ if (!transport.isOpen()) {
+ transport.open();
+ logZkDiscoveryMessage("Connected to " + connParams.getHost() + ":" + connParams.getPort());
+ }
}
public String getConnectedUrl() {
@@ -417,12 +414,14 @@ public class KyuubiConnection implements java.sql.Connection {
}
private CloseableHttpClient getHttpClient(Boolean useSsl) throws SQLException {
- boolean isCookieEnabled = sessConfMap.get(JdbcConnectionParams.COOKIE_AUTH) == null ||
- (!JdbcConnectionParams.COOKIE_AUTH_FALSE.equalsIgnoreCase(
- sessConfMap.get(JdbcConnectionParams.COOKIE_AUTH)));
- String cookieName = sessConfMap.get(JdbcConnectionParams.COOKIE_NAME) == null ?
- JdbcConnectionParams.DEFAULT_COOKIE_NAMES_HS2 :
- sessConfMap.get(JdbcConnectionParams.COOKIE_NAME);
+ boolean isCookieEnabled =
+ sessConfMap.get(JdbcConnectionParams.COOKIE_AUTH) == null
+ || (!JdbcConnectionParams.COOKIE_AUTH_FALSE.equalsIgnoreCase(
+ sessConfMap.get(JdbcConnectionParams.COOKIE_AUTH)));
+ String cookieName =
+ sessConfMap.get(JdbcConnectionParams.COOKIE_NAME) == null
+ ? JdbcConnectionParams.DEFAULT_COOKIE_NAMES_HS2
+ : sessConfMap.get(JdbcConnectionParams.COOKIE_NAME);
CookieStore cookieStore = isCookieEnabled ? new BasicCookieStore() : null;
HttpClientBuilder httpClientBuilder;
// Request interceptor for any request pre-processing logic
@@ -434,85 +433,100 @@ public class KyuubiConnection implements java.sql.Connection {
String key = entry.getKey();
if (key.startsWith(JdbcConnectionParams.HTTP_HEADER_PREFIX)) {
- additionalHttpHeaders.put(key.substring(JdbcConnectionParams.HTTP_HEADER_PREFIX.length()),
- entry.getValue());
+ additionalHttpHeaders.put(
+ key.substring(JdbcConnectionParams.HTTP_HEADER_PREFIX.length()), entry.getValue());
}
}
// Configure http client for kerberos/password based authentication
if (isKerberosAuthMode()) {
/**
- * Add an interceptor which sets the appropriate header in the request.
- * It does the kerberos authentication and get the final service ticket,
- * for sending to the server before every request.
- * In https mode, the entire information is encrypted
+ * Add an interceptor which sets the appropriate header in the request. It does the kerberos
+ * authentication and get the final service ticket, for sending to the server before every
+ * request. In https mode, the entire information is encrypted
*/
requestInterceptor =
- new HttpKerberosRequestInterceptor(sessConfMap.get(JdbcConnectionParams.AUTH_PRINCIPAL),
- host, getServerHttpUrl(useSsl), assumeSubject, cookieStore, cookieName, useSsl,
+ new HttpKerberosRequestInterceptor(
+ sessConfMap.get(JdbcConnectionParams.AUTH_PRINCIPAL),
+ host,
+ getServerHttpUrl(useSsl),
+ assumeSubject,
+ cookieStore,
+ cookieName,
+ useSsl,
additionalHttpHeaders);
} else {
// Check for delegation token, if present add it in the header
String tokenStr = getClientDelegationToken(sessConfMap);
if (tokenStr != null) {
requestInterceptor =
- new HttpTokenAuthInterceptor(tokenStr, cookieStore, cookieName, useSsl,
- additionalHttpHeaders);
+ new HttpTokenAuthInterceptor(
+ tokenStr, cookieStore, cookieName, useSsl, additionalHttpHeaders);
} else {
- /**
- * Add an interceptor to pass username/password in the header.
- * In https mode, the entire information is encrypted
- */
+ /**
+ * Add an interceptor to pass username/password in the header. In https mode, the entire
+ * information is encrypted
+ */
requestInterceptor =
- new HttpBasicAuthInterceptor(getUserName(), getPassword(), cookieStore, cookieName,
- useSsl, additionalHttpHeaders);
+ new HttpBasicAuthInterceptor(
+ getUserName(),
+ getPassword(),
+ cookieStore,
+ cookieName,
+ useSsl,
+ additionalHttpHeaders);
}
}
// Configure http client for cookie based authentication
if (isCookieEnabled) {
// Create a http client with a retry mechanism when the server returns a status code of 401.
httpClientBuilder =
- HttpClients.custom().setServiceUnavailableRetryStrategy(
- new ServiceUnavailableRetryStrategy() {
- @Override
- public boolean retryRequest(final HttpResponse response, final int executionCount,
- final HttpContext context) {
- int statusCode = response.getStatusLine().getStatusCode();
- boolean ret = statusCode == 401 && executionCount <= 1;
-
- // Set the context attribute to true which will be interpreted by the request
- // interceptor
- if (ret) {
- context.setAttribute(Utils.HIVE_SERVER2_RETRY_KEY,
- Utils.HIVE_SERVER2_RETRY_TRUE);
- }
- return ret;
- }
-
- @Override
- public long getRetryInterval() {
- // Immediate retry
- return 0;
- }
- });
+ HttpClients.custom()
+ .setServiceUnavailableRetryStrategy(
+ new ServiceUnavailableRetryStrategy() {
+ @Override
+ public boolean retryRequest(
+ final HttpResponse response,
+ final int executionCount,
+ final HttpContext context) {
+ int statusCode = response.getStatusLine().getStatusCode();
+ boolean ret = statusCode == 401 && executionCount <= 1;
+
+ // Set the context attribute to true which will be interpreted by the request
+ // interceptor
+ if (ret) {
+ context.setAttribute(
+ Utils.HIVE_SERVER2_RETRY_KEY, Utils.HIVE_SERVER2_RETRY_TRUE);
+ }
+ return ret;
+ }
+
+ @Override
+ public long getRetryInterval() {
+ // Immediate retry
+ return 0;
+ }
+ });
} else {
httpClientBuilder = HttpClientBuilder.create();
}
// In case the server's idletimeout is set to a lower value, it might close it's side of
// connection. However we retry one more time on NoHttpResponseException
- httpClientBuilder.setRetryHandler(new HttpRequestRetryHandler() {
- @Override
- public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
- if (executionCount > 1) {
- LOG.info("Retry attempts to connect to server exceeded.");
- return false;
- }
- if (exception instanceof org.apache.http.NoHttpResponseException) {
- LOG.info("Could not connect to the server. Retrying one more time.");
- return true;
- }
- return false;
- }
- });
+ httpClientBuilder.setRetryHandler(
+ new HttpRequestRetryHandler() {
+ @Override
+ public boolean retryRequest(
+ IOException exception, int executionCount, HttpContext context) {
+ if (executionCount > 1) {
+ LOG.info("Retry attempts to connect to server exceeded.");
+ return false;
+ }
+ if (exception instanceof org.apache.http.NoHttpResponseException) {
+ LOG.info("Could not connect to the server. Retrying one more time.");
+ return true;
+ }
+ return false;
+ }
+ });
// Add the request interceptor to the client builder
httpClientBuilder.addInterceptorFirst(requestInterceptor);
@@ -524,16 +538,15 @@ public class KyuubiConnection implements java.sql.Connection {
if (useSsl) {
String useTwoWaySSL = sessConfMap.get(JdbcConnectionParams.USE_TWO_WAY_SSL);
String sslTrustStorePath = sessConfMap.get(JdbcConnectionParams.SSL_TRUST_STORE);
- String sslTrustStorePassword = sessConfMap.get(
- JdbcConnectionParams.SSL_TRUST_STORE_PASSWORD);
+ String sslTrustStorePassword = sessConfMap.get(JdbcConnectionParams.SSL_TRUST_STORE_PASSWORD);
KeyStore sslTrustStore;
SSLConnectionSocketFactory socketFactory;
SSLContext sslContext;
/**
* The code within the try block throws: SSLInitializationException, KeyStoreException,
* IOException, NoSuchAlgorithmException, CertificateException, KeyManagementException &
- * UnrecoverableKeyException. We don't want the client to retry on any of these,
- * hence we catch all and throw a SQLException.
+ * UnrecoverableKeyException. We don't want the client to retry on any of these, hence we
+ * catch all and throw a SQLException.
*/
try {
if (useTwoWaySSL != null && useTwoWaySSL.equalsIgnoreCase(JdbcConnectionParams.TRUE)) {
@@ -552,7 +565,8 @@ public class KyuubiConnection implements java.sql.Connection {
new SSLConnectionSocketFactory(sslContext, new DefaultHostnameVerifier(null));
}
final Registry<ConnectionSocketFactory> registry =
- RegistryBuilder.<ConnectionSocketFactory> create().register("https", socketFactory)
+ RegistryBuilder.<ConnectionSocketFactory>create()
+ .register("https", socketFactory)
.build();
httpClientBuilder.setConnectionManager(new BasicHttpClientConnectionManager(registry));
} catch (Exception e) {
@@ -580,14 +594,14 @@ public class KyuubiConnection implements java.sql.Connection {
if (isSslConnection()) {
// get SSL socket
String sslTrustStore = sessConfMap.get(JdbcConnectionParams.SSL_TRUST_STORE);
- String sslTrustStorePassword = sessConfMap.get(
- JdbcConnectionParams.SSL_TRUST_STORE_PASSWORD);
+ String sslTrustStorePassword = sessConfMap.get(JdbcConnectionParams.SSL_TRUST_STORE_PASSWORD);
if (sslTrustStore == null || sslTrustStore.isEmpty()) {
transport = HiveAuthUtils.getSSLSocket(host, port, loginTimeout);
} else {
- transport = HiveAuthUtils.getSSLSocket(host, port, loginTimeout,
- sslTrustStore, sslTrustStorePassword);
+ transport =
+ HiveAuthUtils.getSSLSocket(
+ host, port, loginTimeout, sslTrustStore, sslTrustStorePassword);
}
} else {
// get non-SSL socket transport
@@ -597,23 +611,19 @@ public class KyuubiConnection implements java.sql.Connection {
}
/**
- * Create transport per the connection options
- * Supported transport options are:
- * - SASL based transports over
- * + Kerberos
- * + Delegation token
- * + SSL
- * + non-SSL
- * - Raw (non-SASL) socket
+ * Create transport per the connection options Supported transport options are: - SASL based
+ * transports over + Kerberos + Delegation token + SSL + non-SSL - Raw (non-SASL) socket
+ *
+ * <p>Kerberos and Delegation token supports SASL QOP configurations
*
- * Kerberos and Delegation token supports SASL QOP configurations
* @throws SQLException, TTransportException
*/
private TTransport createBinaryTransport() throws SQLException, TTransportException {
try {
TTransport socketTransport = createUnderlyingTransport();
// handle secure connection if specified
- if (!JdbcConnectionParams.AUTH_SIMPLE.equals(sessConfMap.get(JdbcConnectionParams.AUTH_TYPE))) {
+ if (!JdbcConnectionParams.AUTH_SIMPLE.equals(
+ sessConfMap.get(JdbcConnectionParams.AUTH_TYPE))) {
// If Kerberos
Map<String, String> saslProps = new HashMap<String, String>();
SaslQOP saslQOP = SaslQOP.AUTH;
@@ -621,8 +631,10 @@ public class KyuubiConnection implements java.sql.Connection {
try {
saslQOP = SaslQOP.fromString(sessConfMap.get(JdbcConnectionParams.AUTH_QOP));
} catch (IllegalArgumentException e) {
- throw new SQLException("Invalid " + JdbcConnectionParams.AUTH_QOP +
- " parameter. " + e.getMessage(), "42000", e);
+ throw new SQLException(
+ "Invalid " + JdbcConnectionParams.AUTH_QOP + " parameter. " + e.getMessage(),
+ "42000",
+ e);
}
saslProps.put(Sasl.QOP, saslQOP.toString());
} else {
@@ -631,15 +643,19 @@ public class KyuubiConnection implements java.sql.Connection {
}
saslProps.put(Sasl.SERVER_AUTH, "true");
if (sessConfMap.containsKey(JdbcConnectionParams.AUTH_PRINCIPAL)) {
- transport = KerberosSaslHelper.getKerberosTransport(
- sessConfMap.get(JdbcConnectionParams.AUTH_PRINCIPAL), host,
- socketTransport, saslProps, assumeSubject);
+ transport =
+ KerberosSaslHelper.getKerberosTransport(
+ sessConfMap.get(JdbcConnectionParams.AUTH_PRINCIPAL),
+ host,
+ socketTransport,
+ saslProps,
+ assumeSubject);
} else {
// If there's a delegation token available then use token based connection
String tokenStr = getClientDelegationToken(sessConfMap);
if (tokenStr != null) {
- transport = KerberosSaslHelper.getTokenTransport(tokenStr,
- host, socketTransport, saslProps);
+ transport =
+ KerberosSaslHelper.getTokenTransport(tokenStr, host, socketTransport, saslProps);
} else {
// we are using PLAIN Sasl connection with user/password
String userName = getUserName();
@@ -653,8 +669,10 @@ public class KyuubiConnection implements java.sql.Connection {
transport = socketTransport;
}
} catch (SaslException e) {
- throw new SQLException("Could not create secure connection to "
- + jdbcUriString + ": " + e.getMessage(), " 08S01", e);
+ throw new SQLException(
+ "Could not create secure connection to " + jdbcUriString + ": " + e.getMessage(),
+ " 08S01",
+ e);
}
return transport;
}
@@ -663,40 +681,43 @@ public class KyuubiConnection implements java.sql.Connection {
SSLConnectionSocketFactory socketFactory = null;
try {
- KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(
- JdbcConnectionParams.SUNX509_ALGORITHM_STRING,
- JdbcConnectionParams.SUNJSSE_ALGORITHM_STRING);
+ KeyManagerFactory keyManagerFactory =
+ KeyManagerFactory.getInstance(
+ JdbcConnectionParams.SUNX509_ALGORITHM_STRING,
+ JdbcConnectionParams.SUNJSSE_ALGORITHM_STRING);
String keyStorePath = sessConfMap.get(JdbcConnectionParams.SSL_KEY_STORE);
String keyStorePassword = sessConfMap.get(JdbcConnectionParams.SSL_KEY_STORE_PASSWORD);
KeyStore sslKeyStore = KeyStore.getInstance(JdbcConnectionParams.SSL_KEY_STORE_TYPE);
if (keyStorePath == null || keyStorePath.isEmpty()) {
- throw new IllegalArgumentException(JdbcConnectionParams.SSL_KEY_STORE
- + " Not configured for 2 way SSL connection, keyStorePath param is empty");
+ throw new IllegalArgumentException(
+ JdbcConnectionParams.SSL_KEY_STORE
+ + " Not configured for 2 way SSL connection, keyStorePath param is empty");
}
try (FileInputStream fis = new FileInputStream(keyStorePath)) {
sslKeyStore.load(fis, keyStorePassword.toCharArray());
}
keyManagerFactory.init(sslKeyStore, keyStorePassword.toCharArray());
- TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(
- JdbcConnectionParams.SUNX509_ALGORITHM_STRING);
+ TrustManagerFactory trustManagerFactory =
+ TrustManagerFactory.getInstance(JdbcConnectionParams.SUNX509_ALGORITHM_STRING);
String trustStorePath = sessConfMap.get(JdbcConnectionParams.SSL_TRUST_STORE);
- String trustStorePassword = sessConfMap.get(
- JdbcConnectionParams.SSL_TRUST_STORE_PASSWORD);
+ String trustStorePassword = sessConfMap.get(JdbcConnectionParams.SSL_TRUST_STORE_PASSWORD);
KeyStore sslTrustStore = KeyStore.getInstance(JdbcConnectionParams.SSL_TRUST_STORE_TYPE);
if (trustStorePath == null || trustStorePath.isEmpty()) {
- throw new IllegalArgumentException(JdbcConnectionParams.SSL_TRUST_STORE
- + " Not configured for 2 way SSL connection");
+ throw new IllegalArgumentException(
+ JdbcConnectionParams.SSL_TRUST_STORE + " Not configured for 2 way SSL connection");
}
try (FileInputStream fis = new FileInputStream(trustStorePath)) {
sslTrustStore.load(fis, trustStorePassword.toCharArray());
}
trustManagerFactory.init(sslTrustStore);
SSLContext context = SSLContext.getInstance("TLS");
- context.init(keyManagerFactory.getKeyManagers(),
- trustManagerFactory.getTrustManagers(), new SecureRandom());
+ context.init(
+ keyManagerFactory.getKeyManagers(),
+ trustManagerFactory.getTrustManagers(),
+ new SecureRandom());
socketFactory = new SSLConnectionSocketFactory(context);
} catch (Exception e) {
throw new SQLException("Error while initializing 2 way ssl socket factory ", e);
@@ -705,13 +726,14 @@ public class KyuubiConnection implements java.sql.Connection {
}
// Lookup the delegation token. First in the connection URL, then Configuration
- private String getClientDelegationToken(Map<String, String> jdbcConnConf)
- throws SQLException {
+ private String getClientDelegationToken(Map<String, String> jdbcConnConf) throws SQLException {
String tokenStr = null;
- if (JdbcConnectionParams.AUTH_TOKEN.equalsIgnoreCase(jdbcConnConf.get(JdbcConnectionParams.AUTH_TYPE))) {
+ if (JdbcConnectionParams.AUTH_TOKEN.equalsIgnoreCase(
+ jdbcConnConf.get(JdbcConnectionParams.AUTH_TYPE))) {
// check delegation token in job conf if any
try {
- tokenStr = org.apache.hadoop.hive.shims.Utils.getTokenStrForm(HiveAuthFactory.HS2_CLIENT_TOKEN);
+ tokenStr =
+ org.apache.hadoop.hive.shims.Utils.getTokenStrForm(HiveAuthFactory.HS2_CLIENT_TOKEN);
} catch (IOException e) {
throw new SQLException("Error reading token ", e);
}
@@ -734,14 +756,14 @@ public class KyuubiConnection implements java.sql.Connection {
// switch the database
openConf.put("use:database", connParams.getDbName());
// set the fetchSize
- openConf.put("set:hiveconf:hive.server2.thrift.resultset.default.fetch.size",
- Integer.toString(fetchSize));
+ openConf.put(
+ "set:hiveconf:hive.server2.thrift.resultset.default.fetch.size",
+ Integer.toString(fetchSize));
// set the session configuration
Map<String, String> sessVars = connParams.getSessionVars();
if (sessVars.containsKey(HiveAuthFactory.HS2_PROXY_USER)) {
- openConf.put(HiveAuthFactory.HS2_PROXY_USER,
- sessVars.get(HiveAuthFactory.HS2_PROXY_USER));
+ openConf.put(HiveAuthFactory.HS2_PROXY_USER, sessVars.get(HiveAuthFactory.HS2_PROXY_USER));
}
openReq.setConfiguration(openConf);
@@ -771,40 +793,38 @@ public class KyuubiConnection implements java.sql.Connection {
// Get launch engine operation handle
String launchEngineOpHandleGuid =
- openRespConf.get("kyuubi.session.launch.engine.handle.guid");
+ openRespConf.get("kyuubi.session.launch.engine.handle.guid");
String launchEngineOpHandleSecret =
- openRespConf.get("kyuubi.session.launch.engine.handle.secret");
+ openRespConf.get("kyuubi.session.launch.engine.handle.secret");
if (launchEngineOpHandleGuid != null && launchEngineOpHandleSecret != null) {
try {
byte[] guidBytes = Base64.decodeBase64(launchEngineOpHandleGuid);
byte[] secretBytes = Base64.decodeBase64(launchEngineOpHandleSecret);
- THandleIdentifier handleIdentifier = new THandleIdentifier(ByteBuffer.wrap(guidBytes),
- ByteBuffer.wrap(secretBytes));
+ THandleIdentifier handleIdentifier =
+ new THandleIdentifier(ByteBuffer.wrap(guidBytes), ByteBuffer.wrap(secretBytes));
launchEngineOpHandle =
- new TOperationHandle(handleIdentifier, TOperationType.UNKNOWN, false);
+ new TOperationHandle(handleIdentifier, TOperationType.UNKNOWN, false);
} catch (Exception e) {
LOG.error("Failed to decode launch engine operation handle from open session resp", e);
}
}
} catch (TException e) {
LOG.error("Error opening session", e);
- throw new SQLException("Could not establish connection to "
- + jdbcUriString + ": " + e.getMessage(), " 08S01", e);
+ throw new SQLException(
+ "Could not establish connection to " + jdbcUriString + ": " + e.getMessage(),
+ " 08S01",
+ e);
}
isClosed = false;
}
- /**
- * @return username from sessConfMap
- */
+ /** @return username from sessConfMap */
private String getUserName() {
return getSessionValue(JdbcConnectionParams.AUTH_USER, JdbcConnectionParams.ANONYMOUS_USER);
}
- /**
- * @return password from sessConfMap
- */
+ /** @return password from sessConfMap */
private String getPassword() {
return getSessionValue(JdbcConnectionParams.AUTH_PASSWD, JdbcConnectionParams.ANONYMOUS_PASSWD);
}
@@ -820,7 +840,7 @@ public class KyuubiConnection implements java.sql.Connection {
private boolean isHttpTransportMode() {
String transportMode = sessConfMap.get(JdbcConnectionParams.TRANSPORT_MODE);
- if(transportMode != null && (transportMode.equalsIgnoreCase("http"))) {
+ if (transportMode != null && (transportMode.equalsIgnoreCase("http"))) {
return true;
}
return false;
@@ -828,8 +848,8 @@ public class KyuubiConnection implements java.sql.Connection {
private boolean isZkDynamicDiscoveryMode() {
return (sessConfMap.get(JdbcConnectionParams.SERVICE_DISCOVERY_MODE) != null)
- && (JdbcConnectionParams.SERVICE_DISCOVERY_MODE_ZOOKEEPER.equalsIgnoreCase(sessConfMap
- .get(JdbcConnectionParams.SERVICE_DISCOVERY_MODE)));
+ && (JdbcConnectionParams.SERVICE_DISCOVERY_MODE_ZOOKEEPER.equalsIgnoreCase(
+ sessConfMap.get(JdbcConnectionParams.SERVICE_DISCOVERY_MODE)));
}
private void logZkDiscoveryMessage(String message) {
@@ -839,8 +859,8 @@ public class KyuubiConnection implements java.sql.Connection {
}
/**
- * Lookup varName in sessConfMap, if its null or empty return the default
- * value varDefault
+ * Lookup varName in sessConfMap, if its null or empty return the default value varDefault
+ *
* @param varName
* @param varDefault
* @return
@@ -875,34 +895,29 @@ public class KyuubiConnection implements java.sql.Connection {
Utils.verifySuccess(tokenResp.getStatus());
return tokenResp.getDelegationToken();
} catch (TException e) {
- throw new SQLException("Could not retrieve token: " +
- e.getMessage(), " 08S01", e);
+ throw new SQLException("Could not retrieve token: " + e.getMessage(), " 08S01", e);
}
}
public void cancelDelegationToken(String tokenStr) throws SQLException {
TCancelDelegationTokenReq cancelReq = new TCancelDelegationTokenReq(sessHandle, tokenStr);
try {
- TCancelDelegationTokenResp cancelResp =
- client.CancelDelegationToken(cancelReq);
+ TCancelDelegationTokenResp cancelResp = client.CancelDelegationToken(cancelReq);
Utils.verifySuccess(cancelResp.getStatus());
return;
} catch (TException e) {
- throw new SQLException("Could not cancel token: " +
- e.getMessage(), " 08S01", e);
+ throw new SQLException("Could not cancel token: " + e.getMessage(), " 08S01", e);
}
}
public void renewDelegationToken(String tokenStr) throws SQLException {
TRenewDelegationTokenReq cancelReq = new TRenewDelegationTokenReq(sessHandle, tokenStr);
try {
- TRenewDelegationTokenResp renewResp =
- client.RenewDelegationToken(cancelReq);
+ TRenewDelegationTokenResp renewResp = client.RenewDelegationToken(cancelReq);
Utils.verifySuccess(renewResp.getStatus());
return;
} catch (TException e) {
- throw new SQLException("Could not renew token: " +
- e.getMessage(), " 08S01", e);
+ throw new SQLException("Could not renew token: " + e.getMessage(), " 08S01", e);
}
}
@@ -1016,11 +1031,9 @@ public class KyuubiConnection implements java.sql.Connection {
/**
* Creates a Statement object for sending SQL statements to the database.
*
- * @throws SQLException
- * if a database access error occurs.
+ * @throws SQLException if a database access error occurs.
* @see java.sql.Connection#createStatement()
*/
-
@Override
public Statement createStatement() throws SQLException {
if (isClosed) {
@@ -1039,15 +1052,17 @@ public class KyuubiConnection implements java.sql.Connection {
public Statement createStatement(int resultSetType, int resultSetConcurrency)
throws SQLException {
if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) {
- throw new SQLException("Statement with resultset concurrency " +
- resultSetConcurrency + " is not supported", "HYC00"); // Optional feature not implemented
+ throw new SQLException(
+ "Statement with resultset concurrency " + resultSetConcurrency + " is not supported",
+ "HYC00"); // Optional feature not implemented
}
if (resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE) {
- throw new SQLException("Statement with resultset type " + resultSetType +
- " is not supported", "HYC00"); // Optional feature not implemented
+ throw new SQLException(
+ "Statement with resultset type " + resultSetType + " is not supported",
+ "HYC00"); // Optional feature not implemented
}
- return new KyuubiStatement(this, client, sessHandle,
- resultSetType == ResultSet.TYPE_SCROLL_INSENSITIVE, fetchSize);
+ return new KyuubiStatement(
+ this, client, sessHandle, resultSetType == ResultSet.TYPE_SCROLL_INSENSITIVE, fetchSize);
}
/*
@@ -1057,8 +1072,8 @@ public class KyuubiConnection implements java.sql.Connection {
*/
@Override
- public Statement createStatement(int resultSetType, int resultSetConcurrency,
- int resultSetHoldability) throws SQLException {
+ public Statement createStatement(
+ int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1070,8 +1085,7 @@ public class KyuubiConnection implements java.sql.Connection {
*/
@Override
- public Struct createStruct(String typeName, Object[] attributes)
- throws SQLException {
+ public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1158,7 +1172,7 @@ public class KyuubiConnection implements java.sql.Connection {
throw new SQLException("Connection is closed");
}
try (Statement stmt = createStatement();
- ResultSet res = stmt.executeQuery("SELECT current_database()")) {
+ ResultSet res = stmt.executeQuery("SELECT current_database()")) {
if (!res.next()) {
throw new SQLException("Failed to get schema information");
}
@@ -1235,8 +1249,8 @@ public class KyuubiConnection implements java.sql.Connection {
}
boolean rc = false;
try {
- String productName = new KyuubiDatabaseMetaData(this, client, sessHandle)
- .getDatabaseProductName();
+ String productName =
+ new KyuubiDatabaseMetaData(this, client, sessHandle).getDatabaseProductName();
rc = true;
} catch (SQLException e) {
// IGNORE
@@ -1275,8 +1289,8 @@ public class KyuubiConnection implements java.sql.Connection {
*/
@Override
- public CallableStatement prepareCall(String sql, int resultSetType,
- int resultSetConcurrency) throws SQLException {
+ public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency)
+ throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1288,8 +1302,9 @@ public class KyuubiConnection implements java.sql.Connection {
*/
@Override
- public CallableStatement prepareCall(String sql, int resultSetType,
- int resultSetConcurrency, int resultSetHoldability) throws SQLException {
+ public CallableStatement prepareCall(
+ String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1312,8 +1327,7 @@ public class KyuubiConnection implements java.sql.Connection {
*/
@Override
- public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
- throws SQLException {
+ public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
return new KyuubiPreparedStatement(this, client, sessHandle, sql);
}
@@ -1324,8 +1338,7 @@ public class KyuubiConnection implements java.sql.Connection {
*/
@Override
- public PreparedStatement prepareStatement(String sql, int[] columnIndexes)
- throws SQLException {
+ public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1338,8 +1351,7 @@ public class KyuubiConnection implements java.sql.Connection {
*/
@Override
- public PreparedStatement prepareStatement(String sql, String[] columnNames)
- throws SQLException {
+ public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1351,8 +1363,8 @@ public class KyuubiConnection implements java.sql.Connection {
*/
@Override
- public PreparedStatement prepareStatement(String sql, int resultSetType,
- int resultSetConcurrency) throws SQLException {
+ public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
+ throws SQLException {
return new KyuubiPreparedStatement(this, client, sessHandle, sql);
}
@@ -1363,8 +1375,9 @@ public class KyuubiConnection implements java.sql.Connection {
*/
@Override
- public PreparedStatement prepareStatement(String sql, int resultSetType,
- int resultSetConcurrency, int resultSetHoldability) throws SQLException {
+ public PreparedStatement prepareStatement(
+ String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1414,7 +1427,7 @@ public class KyuubiConnection implements java.sql.Connection {
@Override
public void setAutoCommit(boolean autoCommit) throws SQLException {
// Per JDBC spec, if the connection is closed a SQLException should be thrown.
- if(isClosed) {
+ if (isClosed) {
throw new SQLException("Connection is closed");
}
// The auto-commit mode is always enabled for this connection. Per JDBC spec,
@@ -1450,8 +1463,7 @@ public class KyuubiConnection implements java.sql.Connection {
*/
@Override
- public void setClientInfo(Properties properties)
- throws SQLClientInfoException {
+ public void setClientInfo(Properties properties) throws SQLClientInfoException {
// TODO Auto-generated method stub
throw new SQLClientInfoException("Method not supported", null);
}
@@ -1463,8 +1475,7 @@ public class KyuubiConnection implements java.sql.Connection {
*/
@Override
- public void setClientInfo(String name, String value)
- throws SQLClientInfoException {
+ public void setClientInfo(String name, String value) throws SQLClientInfoException {
// TODO Auto-generated method stub
throw new SQLClientInfoException("Method not supported", null);
}
@@ -1499,9 +1510,10 @@ public class KyuubiConnection implements java.sql.Connection {
throw new SQLException("Connection is closed");
}
// Per JDBC spec, the request defines a hint to the driver to enable database optimizations.
- // The read-only mode for this connection is disabled and cannot be enabled (isReadOnly always returns false).
+ // The read-only mode for this connection is disabled and cannot be enabled (isReadOnly always
+ // returns false).
// The most correct behavior is to throw only if the request tries to enable the read-only mode.
- if(readOnly) {
+ if (readOnly) {
throw new SQLException("Enabling read-only mode not supported");
}
}
@@ -1594,12 +1606,12 @@ public class KyuubiConnection implements java.sql.Connection {
return protocol;
}
- public static TCLIService.Iface newSynchronizedClient(
- TCLIService.Iface client) {
- return (TCLIService.Iface) Proxy.newProxyInstance(
- KyuubiConnection.class.getClassLoader(),
- new Class [] { TCLIService.Iface.class },
- new SynchronizedHandler(client));
+ public static TCLIService.Iface newSynchronizedClient(TCLIService.Iface client) {
+ return (TCLIService.Iface)
+ Proxy.newProxyInstance(
+ KyuubiConnection.class.getClassLoader(),
+ new Class[] {TCLIService.Iface.class},
+ new SynchronizedHandler(client));
}
private static class SynchronizedHandler implements InvocationHandler {
@@ -1611,19 +1623,18 @@ public class KyuubiConnection implements java.sql.Connection {
}
@Override
- public Object invoke(Object proxy, Method method, Object [] args)
- throws Throwable {
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
lock.lock();
return method.invoke(client, args);
} catch (InvocationTargetException e) {
// all IFace APIs throw TException
if (e.getTargetException() instanceof TException) {
- throw (TException)e.getTargetException();
+ throw (TException) e.getTargetException();
} else {
// should not happen
- throw new TException("Error in calling method " + method.getName(),
- e.getTargetException());
+ throw new TException(
+ "Error in calling method " + method.getName(), e.getTargetException());
}
} catch (Exception e) {
throw new TException("Error in calling method " + method.getName(), e);
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiDataSource.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiDataSource.java
index acecd74..fa6d84a 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiDataSource.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiDataSource.java
@@ -22,18 +22,12 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;
-
import javax.sql.DataSource;
-/**
- * KyuubiDataSource.
- *
- */
+/** KyuubiDataSource. */
public class KyuubiDataSource implements DataSource {
- /**
- *
- */
+ /** */
public KyuubiDataSource() {
// TODO Auto-generated constructor stub
}
@@ -56,12 +50,11 @@ public class KyuubiDataSource implements DataSource {
*/
@Override
- public Connection getConnection(String username, String password)
- throws SQLException {
+ public Connection getConnection(String username, String password) throws SQLException {
try {
return new KyuubiConnection("", null);
} catch (Exception ex) {
- throw new SQLException("Error in getting HiveConnection",ex);
+ throw new SQLException("Error in getting HiveConnection", ex);
}
}
@@ -141,5 +134,4 @@ public class KyuubiDataSource implements DataSource {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
-
}
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiDatabaseMetaData.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiDatabaseMetaData.java
index 9c30ad7..9ef9eef 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiDatabaseMetaData.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiDatabaseMetaData.java
@@ -26,19 +26,14 @@ import java.sql.SQLFeatureNotSupportedException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.jar.Attributes;
-
import org.apache.hadoop.hive.metastore.TableType;
import org.apache.hive.service.cli.GetInfoType;
import org.apache.hive.service.cli.HiveSQLException;
import org.apache.hive.service.rpc.thrift.*;
-import org.apache.thrift.TException;
-
import org.apache.kyuubi.jdbc.KyuubiHiveDriver;
+import org.apache.thrift.TException;
-/**
- * KyuubiDatabaseMetaData.
- *
- */
+/** KyuubiDatabaseMetaData. */
public class KyuubiDatabaseMetaData implements DatabaseMetaData {
private final KyuubiConnection connection;
@@ -54,11 +49,9 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
// Cached values, to save on round trips to database.
private String dbVersion = null;
- /**
- *
- */
- public KyuubiDatabaseMetaData(KyuubiConnection connection, TCLIService.Iface client,
- TSessionHandle sessHandle) {
+ /** */
+ public KyuubiDatabaseMetaData(
+ KyuubiConnection connection, TCLIService.Iface client, TSessionHandle sessHandle) {
this.connection = connection;
this.client = client;
this.sessHandle = sessHandle;
@@ -92,13 +85,15 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public ResultSet getAttributes(String catalog, String schemaPattern,
- String typeNamePattern, String attributeNamePattern) throws SQLException {
+ public ResultSet getAttributes(
+ String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern)
+ throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public ResultSet getBestRowIdentifier(String catalog, String schema,
- String table, int scope, boolean nullable) throws SQLException {
+ public ResultSet getBestRowIdentifier(
+ String catalog, String schema, String table, int scope, boolean nullable)
+ throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -121,23 +116,24 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
Utils.verifySuccess(catalogResp.getStatus());
return new KyuubiQueryResultSet.Builder(connection)
- .setClient(client)
- .setSessionHandle(sessHandle)
- .setStmtHandle(catalogResp.getOperationHandle())
- .build();
+ .setClient(client)
+ .setSessionHandle(sessHandle)
+ .setStmtHandle(catalogResp.getOperationHandle())
+ .build();
}
public ResultSet getClientInfoProperties() throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public ResultSet getColumnPrivileges(String catalog, String schema,
- String table, String columnNamePattern) throws SQLException {
+ public ResultSet getColumnPrivileges(
+ String catalog, String schema, String table, String columnNamePattern) throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public ResultSet getPseudoColumns(String catalog, String schemaPattern,
- String tableNamePattern, String columnNamePattern) throws SQLException {
+ public ResultSet getPseudoColumns(
+ String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern)
+ throws SQLException {
// JDK 1.7
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -148,16 +144,14 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
}
/**
- * Convert a pattern containing JDBC catalog search wildcards into
- * Java regex patterns.
+ * Convert a pattern containing JDBC catalog search wildcards into Java regex patterns.
*
- * @param pattern input which may contain '%' or '_' wildcard characters, or
- * these characters escaped using {@link #getSearchStringEscape()}.
- * @return replace %/_ with regex search characters, also handle escaped
- * characters.
+ * @param pattern input which may contain '%' or '_' wildcard characters, or these characters
+ * escaped using {@link #getSearchStringEscape()}.
+ * @return replace %/_ with regex search characters, also handle escaped characters.
*/
private String convertPattern(final String pattern) {
- if (pattern==null) {
+ if (pattern == null) {
return ".*";
} else {
StringBuilder result = new StringBuilder(pattern.length());
@@ -188,8 +182,9 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
}
}
- public ResultSet getColumns(String catalog, String schemaPattern,
- String tableNamePattern, String columnNamePattern) throws SQLException {
+ public ResultSet getColumns(
+ String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern)
+ throws SQLException {
TGetColumnsResp colResp;
TGetColumnsReq colReq = new TGetColumnsReq();
colReq.setSessionHandle(sessHandle);
@@ -205,21 +200,21 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
Utils.verifySuccess(colResp.getStatus());
// build the resultset from response
return new KyuubiQueryResultSet.Builder(connection)
- .setClient(client)
- .setSessionHandle(sessHandle)
- .setStmtHandle(colResp.getOperationHandle())
- .build();
+ .setClient(client)
+ .setSessionHandle(sessHandle)
+ .setStmtHandle(colResp.getOperationHandle())
+ .build();
}
/**
- * We sort the output of getColumns to guarantee jdbc compliance.
- * First check by table name then by ordinal position
+ * We sort the output of getColumns to guarantee jdbc compliance. First check by table name then
+ * by ordinal position
*/
private class GetColumnsComparator implements Comparator<JdbcColumn> {
public int compare(JdbcColumn o1, JdbcColumn o2) {
int compareName = o1.getTableName().compareTo(o2.getTableName());
- if (compareName==0) {
+ if (compareName == 0) {
if (o1.getOrdinalPos() > o2.getOrdinalPos()) {
return 1;
} else if (o1.getOrdinalPos() < o2.getOrdinalPos()) {
@@ -236,30 +231,35 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
return this.connection;
}
- public ResultSet getCrossReference(String primaryCatalog,
- String primarySchema, String primaryTable, String foreignCatalog,
- String foreignSchema, String foreignTable) throws SQLException {
- TGetCrossReferenceResp getFKResp;
- TGetCrossReferenceReq getFKReq = new TGetCrossReferenceReq(sessHandle);
- getFKReq.setParentTableName(primaryTable);
- getFKReq.setParentSchemaName(primarySchema);
- getFKReq.setParentCatalogName(primaryCatalog);
- getFKReq.setForeignTableName(foreignTable);
- getFKReq.setForeignSchemaName(foreignSchema);
- getFKReq.setForeignCatalogName(foreignCatalog);
-
- try {
- getFKResp = client.GetCrossReference(getFKReq);
- } catch (TException e) {
- throw new SQLException(e.getMessage(), "08S01", e);
- }
- Utils.verifySuccess(getFKResp.getStatus());
-
- return new KyuubiQueryResultSet.Builder(connection)
- .setClient(client)
- .setSessionHandle(sessHandle)
- .setStmtHandle(getFKResp.getOperationHandle())
- .build();
+ public ResultSet getCrossReference(
+ String primaryCatalog,
+ String primarySchema,
+ String primaryTable,
+ String foreignCatalog,
+ String foreignSchema,
+ String foreignTable)
+ throws SQLException {
+ TGetCrossReferenceResp getFKResp;
+ TGetCrossReferenceReq getFKReq = new TGetCrossReferenceReq(sessHandle);
+ getFKReq.setParentTableName(primaryTable);
+ getFKReq.setParentSchemaName(primarySchema);
+ getFKReq.setParentCatalogName(primaryCatalog);
+ getFKReq.setForeignTableName(foreignTable);
+ getFKReq.setForeignSchemaName(foreignSchema);
+ getFKReq.setForeignCatalogName(foreignCatalog);
+
+ try {
+ getFKResp = client.GetCrossReference(getFKReq);
+ } catch (TException e) {
+ throw new SQLException(e.getMessage(), "08S01", e);
+ }
+ Utils.verifySuccess(getFKResp.getStatus());
+
+ return new KyuubiQueryResultSet.Builder(connection)
+ .setClient(client)
+ .setSessionHandle(sessHandle)
+ .setStmtHandle(getFKResp.getOperationHandle())
+ .build();
}
public int getDatabaseMajorVersion() throws SQLException {
@@ -276,7 +276,7 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
}
public String getDatabaseProductVersion() throws SQLException {
- if (dbVersion != null) { //lazy-caching of the version.
+ if (dbVersion != null) { // lazy-caching of the version.
return dbVersion;
}
@@ -315,13 +315,13 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
return "";
}
- public ResultSet getFunctionColumns(String arg0, String arg1, String arg2,
- String arg3) throws SQLException {
+ public ResultSet getFunctionColumns(String arg0, String arg1, String arg2, String arg3)
+ throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public ResultSet getFunctions(String catalogName, String schemaPattern, String functionNamePattern)
- throws SQLException {
+ public ResultSet getFunctions(
+ String catalogName, String schemaPattern, String functionNamePattern) throws SQLException {
TGetFunctionsResp funcResp;
TGetFunctionsReq getFunctionsReq = new TGetFunctionsReq();
getFunctionsReq.setSessionHandle(sessHandle);
@@ -337,10 +337,10 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
Utils.verifySuccess(funcResp.getStatus());
return new KyuubiQueryResultSet.Builder(connection)
- .setClient(client)
- .setSessionHandle(sessHandle)
- .setStmtHandle(funcResp.getOperationHandle())
- .build();
+ .setClient(client)
+ .setSessionHandle(sessHandle)
+ .setStmtHandle(funcResp.getOperationHandle())
+ .build();
}
public String getIdentifierQuoteString() throws SQLException {
@@ -350,53 +350,67 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
public ResultSet getImportedKeys(String catalog, String schema, String table)
throws SQLException {
return new KyuubiQueryResultSet.Builder(connection)
- .setClient(client)
- .setEmptyResultSet(true)
- .setSchema(
- Arrays.asList(
- "PKTABLE_CAT",
- "PKTABLE_SCHEM",
- "PKTABLE_NAME",
- "PKCOLUMN_NAME",
- "FKTABLE_CAT",
- "FKTABLE_SCHEM",
- "FKTABLE_NAME",
- "FKCOLUMN_NAME",
- "KEY_SEQ",
- "UPDATE_RULE",
- "DELETE_RULE",
- "FK_NAME",
- "PK_NAME",
- "DEFERRABILITY"),
- Arrays.asList(
- "STRING",
- "STRING",
- "STRING",
- "STRING",
- "STRING",
- "STRING",
- "STRING",
- "STRING",
- "SMALLINT",
- "SMALLINT",
- "SMALLINT",
- "STRING",
- "STRING",
- "STRING"))
- .build();
- }
-
- public ResultSet getIndexInfo(String catalog, String schema, String table,
- boolean unique, boolean approximate) throws SQLException {
+ .setClient(client)
+ .setEmptyResultSet(true)
+ .setSchema(
+ Arrays.asList(
+ "PKTABLE_CAT",
+ "PKTABLE_SCHEM",
+ "PKTABLE_NAME",
+ "PKCOLUMN_NAME",
+ "FKTABLE_CAT",
+ "FKTABLE_SCHEM",
+ "FKTABLE_NAME",
+ "FKCOLUMN_NAME",
+ "KEY_SEQ",
+ "UPDATE_RULE",
+ "DELETE_RULE",
+ "FK_NAME",
+ "PK_NAME",
+ "DEFERRABILITY"),
+ Arrays.asList(
+ "STRING",
+ "STRING",
+ "STRING",
+ "STRING",
+ "STRING",
+ "STRING",
+ "STRING",
+ "STRING",
+ "SMALLINT",
+ "SMALLINT",
+ "SMALLINT",
+ "STRING",
+ "STRING",
+ "STRING"))
+ .build();
+ }
+
+ public ResultSet getIndexInfo(
+ String catalog, String schema, String table, boolean unique, boolean approximate)
+ throws SQLException {
return new KyuubiQueryResultSet.Builder(connection)
.setClient(client)
.setEmptyResultSet(true)
.setSchema(
- Arrays.asList("TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "NON_UNIQUE",
- "INDEX_QUALIFIER", "INDEX_NAME", "TYPE", "ORDINAL_POSITION", "COLUMN_NAME",
- "ASC_OR_DESC", "CARDINALITY", "PAGES", "FILTER_CONDITION"),
- Arrays.asList("STRING", "STRING", "STRING", "BOOLEAN", "STRING", "STRING", "SHORT",
- "SHORT", "STRING", "STRING", "INT", "INT", "STRING")).build();
+ Arrays.asList(
+ "TABLE_CAT",
+ "TABLE_SCHEM",
+ "TABLE_NAME",
+ "NON_UNIQUE",
+ "INDEX_QUALIFIER",
+ "INDEX_NAME",
+ "TYPE",
+ "ORDINAL_POSITION",
+ "COLUMN_NAME",
+ "ASC_OR_DESC",
+ "CARDINALITY",
+ "PAGES",
+ "FILTER_CONDITION"),
+ Arrays.asList(
+ "STRING", "STRING", "STRING", "BOOLEAN", "STRING", "STRING", "SHORT", "SHORT",
+ "STRING", "STRING", "INT", "INT", "STRING"))
+ .build();
}
public int getJDBCMajorVersion() throws SQLException {
@@ -419,10 +433,7 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /**
- * Returns the value of maxColumnNameLength.
- *
- */
+ /** Returns the value of maxColumnNameLength. */
public int getMaxColumnNameLength() throws SQLException {
return maxColumnNameLength;
}
@@ -495,8 +506,7 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
return "";
}
- public ResultSet getPrimaryKeys(String catalog, String schema, String table)
- throws SQLException {
+ public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException {
TGetPrimaryKeysResp getPKResp;
TGetPrimaryKeysReq getPKReq = new TGetPrimaryKeysReq(sessHandle);
getPKReq.setTableName(table);
@@ -510,45 +520,99 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
Utils.verifySuccess(getPKResp.getStatus());
return new KyuubiQueryResultSet.Builder(connection)
- .setClient(client)
- .setSessionHandle(sessHandle)
- .setStmtHandle(getPKResp.getOperationHandle())
- .build();
+ .setClient(client)
+ .setSessionHandle(sessHandle)
+ .setStmtHandle(getPKResp.getOperationHandle())
+ .build();
}
- public ResultSet getProcedureColumns(String catalog, String schemaPattern,
- String procedureNamePattern, String columnNamePattern)
+ public ResultSet getProcedureColumns(
+ String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern)
throws SQLException {
// Hive doesn't support primary keys
// using local schema with empty resultset
- return new KyuubiQueryResultSet.Builder(connection).setClient(client).setEmptyResultSet(true).
- setSchema(
- Arrays.asList("PROCEDURE_CAT", "PROCEDURE_SCHEM", "PROCEDURE_NAME", "COLUMN_NAME", "COLUMN_TYPE",
- "DATA_TYPE", "TYPE_NAME", "PRECISION", "LENGTH", "SCALE", "RADIX", "NULLABLE", "REMARKS",
- "COLUMN_DEF", "SQL_DATA_TYPE", "SQL_DATETIME_SUB", "CHAR_OCTET_LENGTH", "ORDINAL_POSITION",
- "IS_NULLABLE", "SPECIFIC_NAME"),
- Arrays.asList("STRING", "STRING", "STRING", "STRING", "SMALLINT", "INT",
- "STRING", "INT", "INT", "SMALLINT", "SMALLINT", "SMALLINT", "STRING", "STRING",
- "INT", "INT", "INT", "INT",
- "STRING", "STRING"))
- .build();
+ return new KyuubiQueryResultSet.Builder(connection)
+ .setClient(client)
+ .setEmptyResultSet(true)
+ .setSchema(
+ Arrays.asList(
+ "PROCEDURE_CAT",
+ "PROCEDURE_SCHEM",
+ "PROCEDURE_NAME",
+ "COLUMN_NAME",
+ "COLUMN_TYPE",
+ "DATA_TYPE",
+ "TYPE_NAME",
+ "PRECISION",
+ "LENGTH",
+ "SCALE",
+ "RADIX",
+ "NULLABLE",
+ "REMARKS",
+ "COLUMN_DEF",
+ "SQL_DATA_TYPE",
+ "SQL_DATETIME_SUB",
+ "CHAR_OCTET_LENGTH",
+ "ORDINAL_POSITION",
+ "IS_NULLABLE",
+ "SPECIFIC_NAME"),
+ Arrays.asList(
+ "STRING",
+ "STRING",
+ "STRING",
+ "STRING",
+ "SMALLINT",
+ "INT",
+ "STRING",
+ "INT",
+ "INT",
+ "SMALLINT",
+ "SMALLINT",
+ "SMALLINT",
+ "STRING",
+ "STRING",
+ "INT",
+ "INT",
+ "INT",
+ "INT",
+ "STRING",
+ "STRING"))
+ .build();
}
public String getProcedureTerm() throws SQLException {
return new String("UDF");
}
- public ResultSet getProcedures(String catalog, String schemaPattern,
- String procedureNamePattern) throws SQLException {
+ public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern)
+ throws SQLException {
// Hive doesn't support primary keys
// using local schema with empty resultset
- return new KyuubiQueryResultSet.Builder(connection).setClient(client).setEmptyResultSet(true).
- setSchema(
- Arrays.asList("PROCEDURE_CAT", "PROCEDURE_SCHEM", "PROCEDURE_NAME", "RESERVERD", "RESERVERD",
- "RESERVERD", "REMARKS", "PROCEDURE_TYPE", "SPECIFIC_NAME"),
- Arrays.asList("STRING", "STRING", "STRING", "STRING", "STRING",
- "STRING", "STRING", "SMALLINT", "STRING"))
- .build();
+ return new KyuubiQueryResultSet.Builder(connection)
+ .setClient(client)
+ .setEmptyResultSet(true)
+ .setSchema(
+ Arrays.asList(
+ "PROCEDURE_CAT",
+ "PROCEDURE_SCHEM",
+ "PROCEDURE_NAME",
+ "RESERVERD",
+ "RESERVERD",
+ "RESERVERD",
+ "REMARKS",
+ "PROCEDURE_TYPE",
+ "SPECIFIC_NAME"),
+ Arrays.asList(
+ "STRING",
+ "STRING",
+ "STRING",
+ "STRING",
+ "STRING",
+ "STRING",
+ "STRING",
+ "SMALLINT",
+ "STRING"))
+ .build();
}
public int getResultSetHoldability() throws SQLException {
@@ -575,8 +639,7 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
return getSchemas(null, null);
}
- public ResultSet getSchemas(String catalog, String schemaPattern)
- throws SQLException {
+ public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException {
TGetSchemasResp schemaResp;
TGetSchemasReq schemaReq = new TGetSchemasReq();
@@ -597,10 +660,10 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
Utils.verifySuccess(schemaResp.getStatus());
return new KyuubiQueryResultSet.Builder(connection)
- .setClient(client)
- .setSessionHandle(sessHandle)
- .setStmtHandle(schemaResp.getOperationHandle())
- .build();
+ .setClient(client)
+ .setSessionHandle(sessHandle)
+ .setStmtHandle(schemaResp.getOperationHandle())
+ .build();
}
public String getSearchStringEscape() throws SQLException {
@@ -611,13 +674,13 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
return "";
}
- public ResultSet getSuperTables(String catalog, String schemaPattern,
- String tableNamePattern) throws SQLException {
+ public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern)
+ throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public ResultSet getSuperTypes(String catalog, String schemaPattern,
- String typeNamePattern) throws SQLException {
+ public ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern)
+ throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -625,8 +688,8 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
return "";
}
- public ResultSet getTablePrivileges(String catalog, String schemaPattern,
- String tableNamePattern) throws SQLException {
+ public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern)
+ throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -641,15 +704,16 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
Utils.verifySuccess(tableTypeResp.getStatus());
return new KyuubiQueryResultSet.Builder(connection)
- .setClient(client)
- .setSessionHandle(sessHandle)
- .setStmtHandle(tableTypeResp.getOperationHandle())
- .build();
+ .setClient(client)
+ .setSessionHandle(sessHandle)
+ .setStmtHandle(tableTypeResp.getOperationHandle())
+ .build();
}
@Override
- public ResultSet getTables(String catalog, String schemaPattern,
- String tableNamePattern, String[] types) throws SQLException {
+ public ResultSet getTables(
+ String catalog, String schemaPattern, String tableNamePattern, String[] types)
+ throws SQLException {
TGetTablesReq getTableReq = new TGetTablesReq(sessHandle);
getTableReq.setCatalogName(catalog);
@@ -669,21 +733,21 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
throw new HiveSQLException(tStatus);
}
return new KyuubiQueryResultSet.Builder(connection)
- .setClient(client)
- .setSessionHandle(sessHandle)
- .setStmtHandle(getTableResp.getOperationHandle())
- .build();
+ .setClient(client)
+ .setSessionHandle(sessHandle)
+ .setStmtHandle(getTableResp.getOperationHandle())
+ .build();
}
/**
- * We sort the output of getTables to guarantee jdbc compliance.
- * First check by table type then by table name
+ * We sort the output of getTables to guarantee jdbc compliance. First check by table type then by
+ * table name
*/
private class GetTablesComparator implements Comparator<JdbcTable> {
public int compare(JdbcTable o1, JdbcTable o2) {
int compareType = o1.getType().compareTo(o2.getType());
- if (compareType==0) {
+ if (compareType == 0) {
return o1.getTableName().compareTo(o2.getTableName());
} else {
return compareType;
@@ -693,11 +757,12 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
/**
* Translate hive table types into jdbc table types.
+ *
* @param hivetabletype
* @return the type of the table
*/
public static String toJdbcTableType(String hivetabletype) {
- if (hivetabletype==null) {
+ if (hivetabletype == null) {
return null;
} else if (hivetabletype.equals(TableType.MANAGED_TABLE.toString())) {
return "TABLE";
@@ -727,20 +792,27 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
}
Utils.verifySuccess(getTypeInfoResp.getStatus());
return new KyuubiQueryResultSet.Builder(connection)
- .setClient(client)
- .setSessionHandle(sessHandle)
- .setStmtHandle(getTypeInfoResp.getOperationHandle())
- .build();
+ .setClient(client)
+ .setSessionHandle(sessHandle)
+ .setStmtHandle(getTypeInfoResp.getOperationHandle())
+ .build();
}
- public ResultSet getUDTs(String catalog, String schemaPattern,
- String typeNamePattern, int[] types) throws SQLException {
+ public ResultSet getUDTs(
+ String catalog, String schemaPattern, String typeNamePattern, int[] types)
+ throws SQLException {
return new KyuubiMetaDataResultSet(
- Arrays.asList("TYPE_CAT", "TYPE_SCHEM", "TYPE_NAME", "CLASS_NAME", "DATA_TYPE"
- , "REMARKS", "BASE_TYPE")
- , Arrays.asList("STRING", "STRING", "STRING", "STRING", "INT", "STRING", "INT")
- , null) {
+ Arrays.asList(
+ "TYPE_CAT",
+ "TYPE_SCHEM",
+ "TYPE_NAME",
+ "CLASS_NAME",
+ "DATA_TYPE",
+ "REMARKS",
+ "BASE_TYPE"),
+ Arrays.asList("STRING", "STRING", "STRING", "STRING", "INT", "STRING", "INT"),
+ null) {
public boolean next() throws SQLException {
return false;
@@ -754,7 +826,7 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
// JDK 1.7
throw new SQLFeatureNotSupportedException("Method not supported");
- }
+ }
};
}
@@ -919,8 +991,7 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public boolean supportsDataDefinitionAndDataManipulationTransactions()
- throws SQLException {
+ public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -1036,13 +1107,11 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
return false;
}
- public boolean supportsResultSetConcurrency(int type, int concurrency)
- throws SQLException {
+ public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public boolean supportsResultSetHoldability(int holdability)
- throws SQLException {
+ public boolean supportsResultSetHoldability(int holdability) throws SQLException {
return false;
}
@@ -1110,8 +1179,7 @@ public class KyuubiDatabaseMetaData implements DatabaseMetaData {
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public boolean supportsTransactionIsolationLevel(int level)
- throws SQLException {
+ public boolean supportsTransactionIsolationLevel(int level) throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiMetaDataResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiMetaDataResultSet.java
index f27cd78..0ffd4b4 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiMetaDataResultSet.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiMetaDataResultSet.java
@@ -25,33 +25,31 @@ public abstract class KyuubiMetaDataResultSet<M> extends KyuubiBaseResultSet {
protected final List<M> data;
@SuppressWarnings("unchecked")
- public KyuubiMetaDataResultSet(final List<String> columnNames
- , final List<String> columnTypes
- , final List<M> data) throws SQLException {
- if (data!=null) {
+ public KyuubiMetaDataResultSet(
+ final List<String> columnNames, final List<String> columnTypes, final List<M> data)
+ throws SQLException {
+ if (data != null) {
this.data = new ArrayList<M>(data);
} else {
- this.data = new ArrayList<M>();
+ this.data = new ArrayList<M>();
}
- if (columnNames!=null) {
+ if (columnNames != null) {
this.columnNames = new ArrayList<String>(columnNames);
this.normalizedColumnNames = new ArrayList<String>();
for (String colName : columnNames) {
this.normalizedColumnNames.add(colName.toLowerCase());
}
} else {
- this.columnNames = new ArrayList<String>();
+ this.columnNames = new ArrayList<String>();
this.normalizedColumnNames = new ArrayList<String>();
}
- if (columnTypes!=null) {
+ if (columnTypes != null) {
this.columnTypes = new ArrayList<String>(columnTypes);
} else {
- this.columnTypes = new ArrayList<String>();
+ this.columnTypes = new ArrayList<String>();
}
}
@Override
- public void close() throws SQLException {
- }
-
+ public void close() throws SQLException {}
}
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiPreparedStatement.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiPreparedStatement.java
index 2ba9738..706bef9 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiPreparedStatement.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiPreparedStatement.java
@@ -44,24 +44,21 @@ import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
-
import org.apache.hive.service.rpc.thrift.TCLIService;
import org.apache.hive.service.rpc.thrift.TSessionHandle;
-/**
- * KyuubiPreparedStatement.
- *
- */
+/** KyuubiPreparedStatement. */
public class KyuubiPreparedStatement extends KyuubiStatement implements PreparedStatement {
private final String sql;
- /**
- * save the SQL parameters {paramLoc:paramValue}
- */
- private final HashMap<Integer, String> parameters=new HashMap<Integer, String>();
+ /** save the SQL parameters {paramLoc:paramValue} */
+ private final HashMap<Integer, String> parameters = new HashMap<Integer, String>();
- public KyuubiPreparedStatement(KyuubiConnection connection, TCLIService.Iface client,
- TSessionHandle sessHandle, String sql) {
+ public KyuubiPreparedStatement(
+ KyuubiConnection connection,
+ TCLIService.Iface client,
+ TSessionHandle sessHandle,
+ String sql) {
super(connection, client, sessHandle);
this.sql = sql;
}
@@ -88,25 +85,22 @@ public class KyuubiPreparedStatement extends KyuubiStatement implements Prepared
}
/**
- * Invokes executeQuery(sql) using the sql provided to the constructor.
+ * Invokes executeQuery(sql) using the sql provided to the constructor.
*
- * @return boolean Returns true if a resultSet is created, false if not.
- * Note: If the result set is empty a true is returned.
- *
- * @throws SQLException
+ * @return boolean Returns true if a resultSet is created, false if not. Note: If the result set
+ * is empty a true is returned.
+ * @throws SQLException
*/
-
public boolean execute() throws SQLException {
return super.execute(updateSql(sql, parameters));
}
/**
- * Invokes executeQuery(sql) using the sql provided to the constructor.
+ * Invokes executeQuery(sql) using the sql provided to the constructor.
*
- * @return ResultSet
- * @throws SQLException
+ * @return ResultSet
+ * @throws SQLException
*/
-
public ResultSet executeQuery() throws SQLException {
return super.executeQuery(updateSql(sql, parameters));
}
@@ -128,64 +122,63 @@ public class KyuubiPreparedStatement extends KyuubiStatement implements Prepared
* @param sql
* @param parameters
* @return updated SQL string
- * @throws SQLException
+ * @throws SQLException
*/
- private String updateSql(final String sql, HashMap<Integer, String> parameters) throws SQLException {
- List<String> parts=splitSqlStatement(sql);
-
+ private String updateSql(final String sql, HashMap<Integer, String> parameters)
+ throws SQLException {
+ List<String> parts = splitSqlStatement(sql);
+
StringBuilder newSql = new StringBuilder(parts.get(0));
- for(int i=1;i<parts.size();i++){
- if(!parameters.containsKey(i)){
- throw new SQLException("Parameter #"+i+" is unset");
+ for (int i = 1; i < parts.size(); i++) {
+ if (!parameters.containsKey(i)) {
+ throw new SQLException("Parameter #" + i + " is unset");
}
newSql.append(parameters.get(i));
newSql.append(parts.get(i));
}
return newSql.toString();
-
}
-
+
/**
* Splits the parametered sql statement at parameter boundaries.
- *
- * taking into account ' and \ escaping.
- *
- * output for: 'select 1 from ? where a = ?'
- * ['select 1 from ',' where a = ','']
- *
+ *
+ * <p>taking into account ' and \ escaping.
+ *
+ * <p>output for: 'select 1 from ? where a = ?' ['select 1 from ',' where a = ','']
+ *
* @param sql
* @return
*/
private List<String> splitSqlStatement(String sql) {
- List<String> parts=new ArrayList<>();
- int apCount=0;
- int off=0;
- boolean skip=false;
+ List<String> parts = new ArrayList<>();
+ int apCount = 0;
+ int off = 0;
+ boolean skip = false;
for (int i = 0; i < sql.length(); i++) {
char c = sql.charAt(i);
- if(skip){
- skip=false;
+ if (skip) {
+ skip = false;
continue;
}
switch (c) {
- case '\'':
- apCount++;
- break;
- case '\\':
- skip = true;
- break;
- case '?':
- if ((apCount & 1) == 0) {
- parts.add(sql.substring(off,i));
- off=i+1;
- }
- break;
- default:
- break;
+ case '\'':
+ apCount++;
+ break;
+ case '\\':
+ skip = true;
+ break;
+ case '?':
+ if ((apCount & 1) == 0) {
+ parts.add(sql.substring(off, i));
+ off = i + 1;
+ }
+ break;
+ default:
+ break;
}
}
- parts.add(sql.substring(off,sql.length()));
+ parts.add(sql.substring(off, sql.length()));
return parts;
}
@@ -331,7 +324,7 @@ public class KyuubiPreparedStatement extends KyuubiStatement implements Prepared
*/
public void setBlob(int parameterIndex, InputStream inputStream, long length)
- throws SQLException {
+ throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -343,7 +336,7 @@ public class KyuubiPreparedStatement extends KyuubiStatement implements Prepared
*/
public void setBoolean(int parameterIndex, boolean x) throws SQLException {
- this.parameters.put(parameterIndex, ""+x);
+ this.parameters.put(parameterIndex, "" + x);
}
/*
@@ -353,7 +346,7 @@ public class KyuubiPreparedStatement extends KyuubiStatement implements Prepared
*/
public void setByte(int parameterIndex, byte x) throws SQLException {
- this.parameters.put(parameterIndex, ""+x);
+ this.parameters.put(parameterIndex, "" + x);
}
/*
@@ -466,7 +459,7 @@ public class KyuubiPreparedStatement extends KyuubiStatement implements Prepared
*/
public void setDouble(int parameterIndex, double x) throws SQLException {
- this.parameters.put(parameterIndex,""+x);
+ this.parameters.put(parameterIndex, "" + x);
}
/*
@@ -476,7 +469,7 @@ public class KyuubiPreparedStatement extends KyuubiStatement implements Prepared
*/
public void setFloat(int parameterIndex, float x) throws SQLException {
- this.parameters.put(parameterIndex,""+x);
+ this.parameters.put(parameterIndex, "" + x);
}
/*
@@ -486,7 +479,7 @@ public class KyuubiPreparedStatement extends KyuubiStatement implements Prepared
*/
public void setInt(int parameterIndex, int x) throws SQLException {
- this.parameters.put(parameterIndex,""+x);
+ this.parameters.put(parameterIndex, "" + x);
}
/*
@@ -496,7 +489,7 @@ public class KyuubiPreparedStatement extends KyuubiStatement implements Prepared
*/
public void setLong(int parameterIndex, long x) throws SQLException {
- this.parameters.put(parameterIndex,""+x);
+ this.parameters.put(parameterIndex, "" + x);
}
/*
@@ -621,10 +614,9 @@ public class KyuubiPreparedStatement extends KyuubiStatement implements Prepared
} else {
// Can't infer a type.
throw new SQLException(
- MessageFormat
- .format(
- "Can''t infer the SQL type to use for an instance of {0}. Use setObject() with an explicit Types value to specify the type to use.",
- x.getClass().getName()));
+ MessageFormat.format(
+ "Can't infer the SQL type to use for an instance of {0}. Use setObject() with an explicit Types value to specify the type to use.",
+ x.getClass().getName()));
}
}
@@ -634,8 +626,7 @@ public class KyuubiPreparedStatement extends KyuubiStatement implements Prepared
* @see java.sql.PreparedStatement#setObject(int, java.lang.Object, int)
*/
- public void setObject(int parameterIndex, Object x, int targetSqlType)
- throws SQLException {
+ public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -692,7 +683,7 @@ public class KyuubiPreparedStatement extends KyuubiStatement implements Prepared
*/
public void setShort(int parameterIndex, short x) throws SQLException {
- this.parameters.put(parameterIndex,""+x);
+ this.parameters.put(parameterIndex, "" + x);
}
private String replaceBackSlashSingleQuote(String x) {
@@ -700,8 +691,8 @@ public class KyuubiPreparedStatement extends KyuubiStatement implements Prepared
StringBuffer newX = new StringBuffer();
for (int i = 0; i < x.length(); i++) {
char c = x.charAt(i);
- if (c == '\\' && i < x.length()-1) {
- char c1 = x.charAt(i+1);
+ if (c == '\\' && i < x.length() - 1) {
+ char c1 = x.charAt(i + 1);
if (c1 == '\'') {
newX.append(c1);
} else {
@@ -724,8 +715,8 @@ public class KyuubiPreparedStatement extends KyuubiStatement implements Prepared
public void setString(int parameterIndex, String x) throws SQLException {
x = replaceBackSlashSingleQuote(x);
- x=x.replace("'", "\\'");
- this.parameters.put(parameterIndex, "'"+x+"'");
+ x = x.replace("'", "\\'");
+ this.parameters.put(parameterIndex, "'" + x + "'");
}
/*
@@ -768,8 +759,7 @@ public class KyuubiPreparedStatement extends KyuubiStatement implements Prepared
* java.util.Calendar)
*/
- public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
- throws SQLException {
+ public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -792,8 +782,7 @@ public class KyuubiPreparedStatement extends KyuubiStatement implements Prepared
* int)
*/
- public void setUnicodeStream(int parameterIndex, InputStream x, int length)
- throws SQLException {
+ public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
// TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiQueryResultSet.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiQueryResultSet.java
index d57aff7..ef9db0c 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiQueryResultSet.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiQueryResultSet.java
@@ -29,7 +29,6 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
-
import org.apache.hadoop.hive.common.type.HiveDecimal;
import org.apache.hive.service.cli.RowSet;
import org.apache.hive.service.cli.RowSetFactory;
@@ -55,10 +54,7 @@ import org.apache.hive.service.rpc.thrift.TTypeQualifiers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- * KyuubiQueryResultSet.
- *
- */
+/** KyuubiQueryResultSet. */
public class KyuubiQueryResultSet extends KyuubiBaseResultSet {
public static final Logger LOG = LoggerFactory.getLogger(KyuubiQueryResultSet.class);
@@ -85,14 +81,15 @@ public class KyuubiQueryResultSet extends KyuubiBaseResultSet {
private final Statement statement;
private TCLIService.Iface client = null;
private TOperationHandle stmtHandle = null;
- private TSessionHandle sessHandle = null;
+ private TSessionHandle sessHandle = null;
/**
* Sets the limit for the maximum number of rows that any ResultSet object produced by this
- * Statement can contain to the given number. If the limit is exceeded, the excess rows
- * are silently dropped. The value must be >= 0, and 0 means there is not limit.
+ * Statement can contain to the given number. If the limit is exceeded, the excess rows are
+ * silently dropped. The value must be >= 0, and 0 means there is not limit.
*/
private int maxRows = 0;
+
private boolean retrieveSchema = true;
private List<String> colNames;
private List<String> colTypes;
@@ -134,16 +131,15 @@ public class KyuubiQueryResultSet extends KyuubiBaseResultSet {
public Builder setSchema(List<String> colNames, List<String> colTypes) {
// no column attributes provided - create list of null attributes.
- List<JdbcColumnAttributes> colAttributes =
- new ArrayList<JdbcColumnAttributes>();
+ List<JdbcColumnAttributes> colAttributes = new ArrayList<JdbcColumnAttributes>();
for (int idx = 0; idx < colTypes.size(); ++idx) {
colAttributes.add(null);
}
return setSchema(colNames, colTypes, colAttributes);
}
- public Builder setSchema(List<String> colNames, List<String> colTypes,
- List<JdbcColumnAttributes> colAttributes) {
+ public Builder setSchema(
+ List<String> colNames, List<String> colTypes, List<JdbcColumnAttributes> colAttributes) {
this.colNames = new ArrayList<String>();
this.colNames.addAll(colNames);
this.colTypes = new ArrayList<String>();
@@ -179,7 +175,7 @@ public class KyuubiQueryResultSet extends KyuubiBaseResultSet {
}
public TProtocolVersion getProtocolVersion() throws SQLException {
- return ((KyuubiConnection)connection).getProtocol();
+ return ((KyuubiConnection) connection).getProtocol();
}
}
@@ -210,11 +206,11 @@ public class KyuubiQueryResultSet extends KyuubiBaseResultSet {
/**
* Generate ColumnAttributes object from a TTypeQualifiers
+ *
* @param primitiveTypeEntry primitive type
* @return generated ColumnAttributes, or null
*/
- private static JdbcColumnAttributes getColumnAttributes(
- TPrimitiveTypeEntry primitiveTypeEntry) {
+ private static JdbcColumnAttributes getColumnAttributes(TPrimitiveTypeEntry primitiveTypeEntry) {
JdbcColumnAttributes ret = null;
if (primitiveTypeEntry.isSetTypeQualifiers()) {
TTypeQualifiers tq = primitiveTypeEntry.getTypeQualifiers();
@@ -231,8 +227,10 @@ public class KyuubiQueryResultSet extends KyuubiBaseResultSet {
case DECIMAL_TYPE:
TTypeQualifierValue prec = tq.getQualifiers().get(TCLIServiceConstants.PRECISION);
TTypeQualifierValue scale = tq.getQualifiers().get(TCLIServiceConstants.SCALE);
- ret = new JdbcColumnAttributes(prec == null ? HiveDecimal.USER_DEFAULT_PRECISION : prec.getI32Value(),
- scale == null ? HiveDecimal.USER_DEFAULT_SCALE : scale.getI32Value());
+ ret =
+ new JdbcColumnAttributes(
+ prec == null ? HiveDecimal.USER_DEFAULT_PRECISION : prec.getI32Value(),
+ scale == null ? HiveDecimal.USER_DEFAULT_SCALE : scale.getI32Value());
break;
default:
break;
@@ -241,14 +239,12 @@ public class KyuubiQueryResultSet extends KyuubiBaseResultSet {
return ret;
}
- /**
- * Retrieve schema from the server
- */
+ /** Retrieve schema from the server */
private void retrieveSchema() throws SQLException {
try {
TGetResultSetMetadataReq metadataReq = new TGetResultSetMetadataReq(stmtHandle);
// TODO need session handle
- TGetResultSetMetadataResp metadataResp;
+ TGetResultSetMetadataResp metadataResp;
metadataResp = client.GetResultSetMetadata(metadataReq);
Utils.verifySuccess(metadataResp.getStatus());
@@ -287,11 +283,12 @@ public class KyuubiQueryResultSet extends KyuubiBaseResultSet {
/**
* Set the specified schema to the resultset
+ *
* @param colNames
* @param colTypes
*/
- private void setSchema(List<String> colNames, List<String> colTypes,
- List<JdbcColumnAttributes> colAttributes) {
+ private void setSchema(
+ List<String> colNames, List<String> colTypes, List<JdbcColumnAttributes> colAttributes) {
columnNames.addAll(colNames);
columnTypes.addAll(colTypes);
columnAttributes.addAll(colAttributes);
@@ -336,8 +333,7 @@ public class KyuubiQueryResultSet extends KyuubiBaseResultSet {
* Moves the cursor down one row from its current position.
*
* @see java.sql.ResultSet#next()
- * @throws SQLException
- * if a database access error occurs.
+ * @throws SQLException if a database access error occurs.
*/
public boolean next() throws SQLException {
if (isClosed) {
@@ -348,9 +344,9 @@ public class KyuubiQueryResultSet extends KyuubiBaseResultSet {
}
/**
- * Poll on the operation status, till the operation is complete.
- * We need to wait only for HiveStatement to complete.
- * HiveDatabaseMetaData which also uses this ResultSet returns only after the RPC is complete.
+ * Poll on the operation status, till the operation is complete. We need to wait only for
+ * HiveStatement to complete. HiveDatabaseMetaData which also uses this ResultSet returns only
+ * after the RPC is complete.
*/
if ((statement != null) && (statement instanceof KyuubiStatement)) {
((KyuubiStatement) statement).waitForOperationToComplete();
@@ -366,8 +362,7 @@ public class KyuubiQueryResultSet extends KyuubiBaseResultSet {
fetchFirst = false;
}
if (fetchedRows == null || !fetchedRowsItr.hasNext()) {
- TFetchResultsReq fetchReq = new TFetchResultsReq(stmtHandle,
- orientation, fetchSize);
+ TFetchResultsReq fetchReq = new TFetchResultsReq(stmtHandle, orientation, fetchSize);
TFetchResultsResp fetchResp;
fetchResp = client.FetchResults(fetchReq);
Utils.verifySuccessWithInfo(fetchResp.getStatus());
@@ -430,13 +425,13 @@ public class KyuubiQueryResultSet extends KyuubiBaseResultSet {
return fetchSize;
}
- public <T> T getObject(String columnLabel, Class<T> type) throws SQLException {
- //JDK 1.7
+ public <T> T getObject(String columnLabel, Class<T> type) throws SQLException {
+ // JDK 1.7
throw new SQLFeatureNotSupportedException("Method not supported");
}
- public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
- //JDK 1.7
+ public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
+ // JDK 1.7
throw new SQLFeatureNotSupportedException("Method not supported");
}
@@ -444,8 +439,7 @@ public class KyuubiQueryResultSet extends KyuubiBaseResultSet {
* Moves the cursor before the first row of the resultset.
*
* @see java.sql.ResultSet#next()
- * @throws SQLException
- * if a database access error occurs.
+ * @throws SQLException if a database access error occurs.
*/
@Override
public void beforeFirst() throws SQLException {
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiResultSetMetaData.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiResultSetMetaData.java
index a26fe90..754ade5 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiResultSetMetaData.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiResultSetMetaData.java
@@ -21,21 +21,18 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.List;
-
import org.apache.hadoop.hive.serde2.thrift.Type;
-/**
- * KyuubiResultSetMetaData.
- *
- */
+/** KyuubiResultSetMetaData. */
public class KyuubiResultSetMetaData implements java.sql.ResultSetMetaData {
private final List<String> columnNames;
private final List<String> columnTypes;
private final List<JdbcColumnAttributes> columnAttributes;
- public KyuubiResultSetMetaData(List<String> columnNames,
- List<String> columnTypes,
- List<JdbcColumnAttributes> columnAttributes) {
+ public KyuubiResultSetMetaData(
+ List<String> columnNames,
+ List<String> columnTypes,
+ List<JdbcColumnAttributes> columnAttributes) {
this.columnNames = columnNames;
this.columnTypes = columnTypes;
this.columnAttributes = columnAttributes;
@@ -50,8 +47,8 @@ public class KyuubiResultSetMetaData implements java.sql.ResultSetMetaData {
}
public String getColumnClassName(int column) throws SQLException {
- return JdbcColumn.columnClassName(getHiveType(column),
- columnAttributes.get(toZeroIndex(column)));
+ return JdbcColumn.columnClassName(
+ getHiveType(column), columnAttributes.get(toZeroIndex(column)));
}
public int getColumnCount() throws SQLException {
@@ -59,8 +56,8 @@ public class KyuubiResultSetMetaData implements java.sql.ResultSetMetaData {
}
public int getColumnDisplaySize(int column) throws SQLException {
- return JdbcColumn.columnDisplaySize(getHiveType(column),
- columnAttributes.get(toZeroIndex(column)));
+ return JdbcColumn.columnDisplaySize(
+ getHiveType(column), columnAttributes.get(toZeroIndex(column)));
}
public String getColumnLabel(int column) throws SQLException {
@@ -84,13 +81,12 @@ public class KyuubiResultSetMetaData implements java.sql.ResultSetMetaData {
}
public int getPrecision(int column) throws SQLException {
- return JdbcColumn.columnPrecision(getHiveType(column),
- columnAttributes.get(toZeroIndex(column)));
+ return JdbcColumn.columnPrecision(
+ getHiveType(column), columnAttributes.get(toZeroIndex(column)));
}
public int getScale(int column) throws SQLException {
- return JdbcColumn.columnScale(getHiveType(column),
- columnAttributes.get(toZeroIndex(column)));
+ return JdbcColumn.columnScale(getHiveType(column), columnAttributes.get(toZeroIndex(column)));
}
public String getSchemaName(int column) throws SQLException {
@@ -111,7 +107,7 @@ public class KyuubiResultSetMetaData implements java.sql.ResultSetMetaData {
// TODO: this would be better handled in an enum
String type = columnTypes.get(toZeroIndex(column));
- if("string".equalsIgnoreCase(type)) {
+ if ("string".equalsIgnoreCase(type)) {
return true;
} else {
return false;
@@ -158,8 +154,7 @@ public class KyuubiResultSetMetaData implements java.sql.ResultSetMetaData {
protected int toZeroIndex(int column) throws SQLException {
if (columnTypes == null) {
- throw new SQLException(
- "Could not determine column type name for ResultSet");
+ throw new SQLException("Could not determine column type name for ResultSet");
}
if (column < 1 || column > columnTypes.size()) {
throw new SQLException("Invalid column value: " + column);
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiStatement.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiStatement.java
index a0ab36c..64cec19 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiStatement.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiStatement.java
@@ -17,8 +17,17 @@
package org.apache.kyuubi.jdbc.hive;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.SQLTimeoutException;
+import java.sql.SQLWarning;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.apache.commons.codec.binary.Base64;
-import org.apache.kyuubi.jdbc.hive.logs.InPlaceUpdateStream;
import org.apache.hive.service.cli.RowSet;
import org.apache.hive.service.cli.RowSetFactory;
import org.apache.hive.service.rpc.thrift.TCLIService;
@@ -35,25 +44,12 @@ import org.apache.hive.service.rpc.thrift.TGetOperationStatusReq;
import org.apache.hive.service.rpc.thrift.TGetOperationStatusResp;
import org.apache.hive.service.rpc.thrift.TOperationHandle;
import org.apache.hive.service.rpc.thrift.TSessionHandle;
+import org.apache.kyuubi.jdbc.hive.logs.InPlaceUpdateStream;
import org.apache.thrift.TException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.SQLFeatureNotSupportedException;
-import java.sql.SQLTimeoutException;
-import java.sql.SQLWarning;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * KyuubiStatement.
- *
- */
+/** KyuubiStatement. */
public class KyuubiStatement implements java.sql.Statement {
public static final Logger LOG = LoggerFactory.getLogger(KyuubiStatement.class.getName());
public static final int DEFAULT_FETCH_SIZE = 1000;
@@ -61,13 +57,12 @@ public class KyuubiStatement implements java.sql.Statement {
private TCLIService.Iface client;
private TOperationHandle stmtHandle = null;
private final TSessionHandle sessHandle;
- Map<String,String> sessConf = new HashMap<String,String>();
+ Map<String, String> sessConf = new HashMap<String, String>();
private int fetchSize = DEFAULT_FETCH_SIZE;
private boolean isScrollableResultset = false;
private boolean isOperationComplete = false;
/**
- * We need to keep a reference to the result set to support the following:
- * <code>
+ * We need to keep a reference to the result set to support the following: <code>
* statement.execute(String sql);
* statement.getResultSet();
* </code>.
@@ -76,34 +71,24 @@ public class KyuubiStatement implements java.sql.Statement {
/**
* Sets the limit for the maximum number of rows that any ResultSet object produced by this
- * Statement can contain to the given number. If the limit is exceeded, the excess rows
- * are silently dropped. The value must be >= 0, and 0 means there is not limit.
+ * Statement can contain to the given number. If the limit is exceeded, the excess rows are
+ * silently dropped. The value must be >= 0, and 0 means there is not limit.
*/
private int maxRows = 0;
- /**
- * Add SQLWarnings to the warningChain if needed.
- */
+ /** Add SQLWarnings to the warningChain if needed. */
private SQLWarning warningChain = null;
- /**
- * Keep state so we can fail certain calls made after close().
- */
+ /** Keep state so we can fail certain calls made after close(). */
private boolean isClosed = false;
- /**
- * Keep state so we can fail certain calls made after cancel().
- */
+ /** Keep state so we can fail certain calls made after cancel(). */
private boolean isCancelled = false;
- /**
- * Keep this state so we can know whether the query in this statement is closed.
- */
+ /** Keep this state so we can know whether the query in this statement is closed. */
private boolean isQueryClosed = false;
- /**
- * Keep this state so we can know whether the query logs are being generated in HS2.
- */
+ /** Keep this state so we can know whether the query logs are being generated in HS2. */
private boolean isLogBeingGenerated = true;
/**
@@ -116,23 +101,33 @@ public class KyuubiStatement implements java.sql.Statement {
private InPlaceUpdateStream inPlaceUpdateStream = InPlaceUpdateStream.NO_OP;
- public KyuubiStatement(KyuubiConnection connection, TCLIService.Iface client,
- TSessionHandle sessHandle) {
+ public KyuubiStatement(
+ KyuubiConnection connection, TCLIService.Iface client, TSessionHandle sessHandle) {
this(connection, client, sessHandle, false, DEFAULT_FETCH_SIZE);
}
- public KyuubiStatement(KyuubiConnection connection, TCLIService.Iface client,
- TSessionHandle sessHandle, int fetchSize) {
+ public KyuubiStatement(
+ KyuubiConnection connection,
+ TCLIService.Iface client,
+ TSessionHandle sessHandle,
+ int fetchSize) {
this(connection, client, sessHandle, false, fetchSize);
}
- public KyuubiStatement(KyuubiConnection connection, TCLIService.Iface client,
- TSessionHandle sessHandle, boolean isScrollableResultset) {
+ public KyuubiStatement(
+ KyuubiConnection connection,
+ TCLIService.Iface client,
+ TSessionHandle sessHandle,
+ boolean isScrollableResultset) {
this(connection, client, sessHandle, isScrollableResultset, DEFAULT_FETCH_SIZE);
}
- public KyuubiStatement(KyuubiConnection connection, TCLIService.Iface client,
- TSessionHandle sessHandle, boolean isScrollableResultset, int fetchSize) {
+ public KyuubiStatement(
+ KyuubiConnection connection,
+ TCLIService.Iface client,
+ TSessionHandle sessHandle,
+ boolean isScrollableResultset,
+ int fetchSize) {
this.connection = connection;
this.client = client;
this.sessHandle = sessHandle;
@@ -256,10 +251,15 @@ public class KyuubiStatement implements java.sql.Statement {
if (!status.isHasResultSet() && !stmtHandle.isHasResultSet()) {
return false;
}
- resultSet = new KyuubiQueryResultSet.Builder(this).setClient(client).setSessionHandle(sessHandle)
- .setStmtHandle(stmtHandle).setMaxRows(maxRows).setFetchSize(fetchSize)
- .setScrollable(isScrollableResultset)
- .build();
+ resultSet =
+ new KyuubiQueryResultSet.Builder(this)
+ .setClient(client)
+ .setSessionHandle(sessHandle)
+ .setStmtHandle(stmtHandle)
+ .setMaxRows(maxRows)
+ .setFetchSize(fetchSize)
+ .setScrollable(isScrollableResultset)
+ .build();
return true;
}
@@ -269,13 +269,12 @@ public class KyuubiStatement implements java.sql.Statement {
* query type. Users should call ResultSet.next or Statement#getUpdateCount (depending on whether
* query returns results) to ensure that query completes successfully. Calling another execute*
* method, or close before query completion would result in the async query getting killed if it
- * is not already finished.
- * Note: This method is an API for limited usage outside of Hive by applications like Apache Ambari,
- * although it is not part of the interface java.sql.Statement.
+ * is not already finished. Note: This method is an API for limited usage outside of Hive by
+ * applications like Apache Ambari, although it is not part of the interface java.sql.Statement.
*
* @param sql
* @return true if the first result is a ResultSet object; false if it is an update count or there
- * are no results
+ * are no results
* @throws SQLException
*/
public boolean executeAsync(String sql) throws SQLException {
@@ -285,9 +284,14 @@ public class KyuubiStatement implements java.sql.Statement {
return false;
}
resultSet =
- new KyuubiQueryResultSet.Builder(this).setClient(client).setSessionHandle(sessHandle)
- .setStmtHandle(stmtHandle).setMaxRows(maxRows).setFetchSize(fetchSize)
- .setScrollable(isScrollableResultset).build();
+ new KyuubiQueryResultSet.Builder(this)
+ .setClient(client)
+ .setSessionHandle(sessHandle)
+ .setStmtHandle(stmtHandle)
+ .setMaxRows(maxRows)
+ .setFetchSize(fetchSize)
+ .setScrollable(isScrollableResultset)
+ .build();
return true;
}
@@ -299,10 +303,9 @@ public class KyuubiStatement implements java.sql.Statement {
TExecuteStatementReq execReq = new TExecuteStatementReq(sessHandle, sql);
/**
- * Run asynchronously whenever possible
- * Currently only a SQLOperation can be run asynchronously,
- * in a background operation thread
- * Compilation can run asynchronously or synchronously and execution run asynchronously
+ * Run asynchronously whenever possible Currently only a SQLOperation can be run asynchronously,
+ * in a background operation thread Compilation can run asynchronously or synchronously and
+ * execution run asynchronously
*/
execReq.setRunAsync(true);
execReq.setConfOverlay(sessConf);
@@ -325,6 +328,7 @@ public class KyuubiStatement implements java.sql.Statement {
/**
* Poll the result set status by checking if isSetHasResultSet is set
+ *
* @return
* @throws SQLException
*/
@@ -332,7 +336,7 @@ public class KyuubiStatement implements java.sql.Statement {
TGetOperationStatusReq statusReq = new TGetOperationStatusReq(stmtHandle);
TGetOperationStatusResp statusResp = null;
- while(statusResp == null || !statusResp.isSetHasResultSet()) {
+ while (statusResp == null || !statusResp.isSetHasResultSet()) {
try {
statusResp = client.GetOperationStatus(statusReq);
} catch (TException e) {
@@ -349,9 +353,7 @@ public class KyuubiStatement implements java.sql.Statement {
boolean shouldGetProgressUpdate = inPlaceUpdateStream != InPlaceUpdateStream.NO_OP;
statusReq.setGetProgressUpdate(shouldGetProgressUpdate);
if (!shouldGetProgressUpdate) {
- /**
- * progress bar is completed if there is nothing we want to request in the first place.
- */
+ /** progress bar is completed if there is nothing we want to request in the first place. */
inPlaceUpdateStream.getEventNotifier().progressBarCompleted();
}
TGetOperationStatusResp statusResp = null;
@@ -368,26 +370,28 @@ public class KyuubiStatement implements java.sql.Statement {
Utils.verifySuccessWithInfo(statusResp.getStatus());
if (statusResp.isSetOperationState()) {
switch (statusResp.getOperationState()) {
- case CLOSED_STATE:
- case FINISHED_STATE:
- isOperationComplete = true;
- isLogBeingGenerated = false;
- break;
- case CANCELED_STATE:
- // 01000 -> warning
- throw new SQLException("Query was cancelled", "01000");
- case TIMEDOUT_STATE:
- throw new SQLTimeoutException("Query timed out after " + queryTimeout + " seconds");
- case ERROR_STATE:
- // Get the error details from the underlying exception
- throw new SQLException(statusResp.getErrorMessage(), statusResp.getSqlState(),
- statusResp.getErrorCode());
- case UKNOWN_STATE:
- throw new SQLException("Unknown query", "HY000");
- case INITIALIZED_STATE:
- case PENDING_STATE:
- case RUNNING_STATE:
- break;
+ case CLOSED_STATE:
+ case FINISHED_STATE:
+ isOperationComplete = true;
+ isLogBeingGenerated = false;
+ break;
+ case CANCELED_STATE:
+ // 01000 -> warning
+ throw new SQLException("Query was cancelled", "01000");
+ case TIMEDOUT_STATE:
+ throw new SQLTimeoutException("Query timed out after " + queryTimeout + " seconds");
+ case ERROR_STATE:
+ // Get the error details from the underlying exception
+ throw new SQLException(
+ statusResp.getErrorMessage(),
+ statusResp.getSqlState(),
+ statusResp.getErrorCode());
+ case UKNOWN_STATE:
+ throw new SQLException("Unknown query", "HY000");
+ case INITIALIZED_STATE:
+ case PENDING_STATE:
+ case RUNNING_STATE:
+ break;
}
}
} catch (SQLException e) {
@@ -859,22 +863,22 @@ public class KyuubiStatement implements java.sql.Statement {
}
/**
- * Check whether query execution might be producing more logs to be fetched.
- * This method is a public API for usage outside of Hive, although it is not part of the
- * interface java.sql.Statement.
- * @return true if query execution might be producing more logs. It does not indicate if last
- * log lines have been fetched by getQueryLog.
+ * Check whether query execution might be producing more logs to be fetched. This method is a
+ * public API for usage outside of Hive, although it is not part of the interface
+ * java.sql.Statement.
+ *
+ * @return true if query execution might be producing more logs. It does not indicate if last log
+ * lines have been fetched by getQueryLog.
*/
public boolean hasMoreLogs() {
return isLogBeingGenerated;
}
/**
- * Get the execution logs of the given SQL statement.
- * This method is a public API for usage outside of Hive, although it is not part of the
- * interface java.sql.Statement.
- * This method gets the incremental logs during SQL execution, and uses fetchSize holden by
- * HiveStatement object.
+ * Get the execution logs of the given SQL statement. This method is a public API for usage
+ * outside of Hive, although it is not part of the interface java.sql.Statement. This method gets
+ * the incremental logs during SQL execution, and uses fetchSize holden by HiveStatement object.
+ *
* @return a list of logs. It can be empty if there are no new logs to be retrieved at that time.
* @throws SQLException
* @throws ClosedOrCancelledStatementException if statement has been cancelled or closed
@@ -884,11 +888,11 @@ public class KyuubiStatement implements java.sql.Statement {
}
/**
- * Get the execution logs of the given SQL statement.
- * This method is a public API for usage outside of Hive, although it is not part of the
- * interface java.sql.Statement.
- * @param incremental indicate getting logs either incrementally or from the beginning,
- * when it is true or false.
+ * Get the execution logs of the given SQL statement. This method is a public API for usage
+ * outside of Hive, although it is not part of the interface java.sql.Statement.
+ *
+ * @param incremental indicate getting logs either incrementally or from the beginning, when it is
+ * true or false.
* @param fetchSize the number of lines to fetch
* @return a list of logs. It can be empty if there are no new logs to be retrieved at that time.
* @throws SQLException
@@ -898,23 +902,23 @@ public class KyuubiStatement implements java.sql.Statement {
throws SQLException, ClosedOrCancelledStatementException {
checkConnection("getQueryLog");
if (isCancelled) {
- throw new ClosedOrCancelledStatementException("Method getQueryLog() failed. The " +
- "statement has been closed or cancelled.");
+ throw new ClosedOrCancelledStatementException(
+ "Method getQueryLog() failed. The " + "statement has been closed or cancelled.");
}
List<String> logs = new ArrayList<String>();
TFetchResultsResp tFetchResultsResp = null;
try {
if (stmtHandle != null) {
- TFetchResultsReq tFetchResultsReq = new TFetchResultsReq(stmtHandle,
- getFetchOrientation(incremental), fetchSize);
- tFetchResultsReq.setFetchType((short)1);
+ TFetchResultsReq tFetchResultsReq =
+ new TFetchResultsReq(stmtHandle, getFetchOrientation(incremental), fetchSize);
+ tFetchResultsReq.setFetchType((short) 1);
tFetchResultsResp = client.FetchResults(tFetchResultsReq);
Utils.verifySuccessWithInfo(tFetchResultsResp.getStatus());
} else {
if (isQueryClosed) {
- throw new ClosedOrCancelledStatementException("Method getQueryLog() failed. The " +
- "statement has been closed or cancelled.");
+ throw new ClosedOrCancelledStatementException(
+ "Method getQueryLog() failed. The " + "statement has been closed or cancelled.");
} else {
return logs;
}
@@ -949,9 +953,9 @@ public class KyuubiStatement implements java.sql.Statement {
}
/**
- * Returns the Yarn ATS GUID.
- * This method is a public API for usage outside of Hive, although it is not part of the
- * interface java.sql.Statement.
+ * Returns the Yarn ATS GUID. This method is a public API for usage outside of Hive, although it
+ * is not part of the interface java.sql.Statement.
+ *
* @return Yarn ATS GUID or null if it hasn't been created yet.
*/
public String getYarnATSGuid() {
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/Utils.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/Utils.java
index 4b769ba..3696682 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/Utils.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/Utils.java
@@ -27,7 +27,6 @@ import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import org.apache.hive.service.cli.HiveSQLException;
import org.apache.hive.service.rpc.thrift.TStatus;
import org.apache.hive.service.rpc.thrift.TStatusCode;
@@ -38,26 +37,21 @@ import org.slf4j.LoggerFactory;
public class Utils {
static final Logger LOG = LoggerFactory.getLogger(Utils.class.getName());
- /**
- * The required prefix for the connection URL.
- */
+ /** The required prefix for the connection URL. */
public static final String URL_PREFIX = "jdbc:hive2://";
- /**
- * If host is provided, without a port.
- */
+ /** If host is provided, without a port. */
static final String DEFAULT_PORT = "10000";
- /**
- * Kyuubi's default database name
- */
+ /** Kyuubi's default database name */
static final String DEFAULT_DATABASE = "default";
private static final String URI_JDBC_PREFIX = "jdbc:";
private static final String URI_HIVE_PREFIX = "hive2:";
- // This value is set to true by the setServiceUnavailableRetryStrategy() when the server returns 401
+ // This value is set to true by the setServiceUnavailableRetryStrategy() when the server returns
+ // 401
static final String HIVE_SERVER2_RETRY_KEY = "hive.server2.retryserver";
static final String HIVE_SERVER2_RETRY_TRUE = "true";
static final String HIVE_SERVER2_RETRY_FALSE = "false";
@@ -100,8 +94,8 @@ public class Utils {
static final String HTTP_PATH_DEPRECATED = "hive.server2.thrift.http.path";
public static final String HTTP_PATH = "httpPath";
public static final String SERVICE_DISCOVERY_MODE = "serviceDiscoveryMode";
- public static final String PROPERTY_DRIVER = "driver";
- public static final String PROPERTY_URL = "url";
+ public static final String PROPERTY_DRIVER = "driver";
+ public static final String PROPERTY_URL = "url";
// Don't use dynamic service discovery
static final String SERVICE_DISCOVERY_MODE_NONE = "none";
// Use ZooKeeper for indirection while using dynamic service discovery
@@ -130,7 +124,7 @@ public class Utils {
static final String SSL_KEY_STORE_TYPE = "JKS";
static final String SUNX509_ALGORITHM_STRING = "SunX509";
static final String SUNJSSE_ALGORITHM_STRING = "SunJSSE";
- // --------------- End 2 way ssl options ----------------------------
+ // --------------- End 2 way ssl options ----------------------------
// Non-configurable params:
// Currently supports JKS keystore format
@@ -142,17 +136,16 @@ public class Utils {
private int port = 0;
private String jdbcUriString;
private String dbName = DEFAULT_DATABASE;
- private Map<String,String> hiveConfs = new LinkedHashMap<String,String>();
- private Map<String,String> hiveVars = new LinkedHashMap<String,String>();
- private Map<String,String> sessionVars = new LinkedHashMap<String,String>();
+ private Map<String, String> hiveConfs = new LinkedHashMap<String, String>();
+ private Map<String, String> hiveVars = new LinkedHashMap<String, String>();
+ private Map<String, String> sessionVars = new LinkedHashMap<String, String>();
private boolean isEmbeddedMode = false;
private String[] authorityList;
private String zooKeeperEnsemble = null;
private String currentHostZnodePath;
private final List<String> rejectedHostZnodePaths = new ArrayList<String>();
- public JdbcConnectionParams() {
- }
+ public JdbcConnectionParams() {}
public String getHost() {
return host;
@@ -259,42 +252,42 @@ public class Utils {
// Verify success and optionally with_info status, else throw SQLException
static void verifySuccess(TStatus status, boolean withInfo) throws SQLException {
- if (status.getStatusCode() == TStatusCode.SUCCESS_STATUS ||
- (withInfo && status.getStatusCode() == TStatusCode.SUCCESS_WITH_INFO_STATUS)) {
+ if (status.getStatusCode() == TStatusCode.SUCCESS_STATUS
+ || (withInfo && status.getStatusCode() == TStatusCode.SUCCESS_WITH_INFO_STATUS)) {
return;
}
throw new HiveSQLException(status);
}
- public static JdbcConnectionParams parseURL(String uri) throws JdbcUriParseException,
- SQLException, ZooKeeperHiveClientException {
+ public static JdbcConnectionParams parseURL(String uri)
+ throws JdbcUriParseException, SQLException, ZooKeeperHiveClientException {
return parseURL(uri, new Properties());
}
/**
- * Parse JDBC connection URL
- * The new format of the URL is:
+ * Parse JDBC connection URL The new format of the URL is:
* jdbc:hive2://<host1>:<port1>,<host2>:<port2>/dbName;sess_var_list?hive_conf_list#hive_var_list
- * where the optional sess, conf and var lists are semicolon separated <key>=<val> pairs.
- * For utilizing dynamic service discovery with HiveServer2 multiple comma separated host:port pairs can
- * be specified as shown above.
- * The JDBC driver resolves the list of uris and picks a specific server instance to connect to.
- * Currently, dynamic service discovery using ZooKeeper is supported, in which case the host:port pairs represent a ZooKeeper ensemble.
+ * where the optional sess, conf and var lists are semicolon separated <key>=<val> pairs. For
+ * utilizing dynamic service discovery with HiveServer2 multiple comma separated host:port pairs
+ * can be specified as shown above. The JDBC driver resolves the list of uris and picks a specific
+ * server instance to connect to. Currently, dynamic service discovery using ZooKeeper is
+ * supported, in which case the host:port pairs represent a ZooKeeper ensemble.
*
- * As before, if the host/port is not specified, it the driver runs an embedded hive.
- * examples -
- * jdbc:hive2://ubuntu:11000/db2?hive.cli.conf.printheader=true;hive.exec.mode.local.auto.inputbytes.max=9999#stab=salesTable;icol=customerID
- * jdbc:hive2://?hive.cli.conf.printheader=true;hive.exec.mode.local.auto.inputbytes.max=9999#stab=salesTable;icol=customerID
- * jdbc:hive2://ubuntu:11000/db2;user=foo;password=bar
+ * <p>As before, if the host/port is not specified, it the driver runs an embedded hive. examples
+ * -
+ * jdbc:hive2://ubuntu:11000/db2?hive.cli.conf.printheader=true;hive.exec.mode.local.auto.inputbytes.max=9999#stab=salesTable;icol=customerID
+ * jdbc:hive2://?hive.cli.conf.printheader=true;hive.exec.mode.local.auto.inputbytes.max=9999#stab=salesTable;icol=customerID
+ * jdbc:hive2://ubuntu:11000/db2;user=foo;password=bar
*
- * Connect to http://server:10001/hs2, with specified basicAuth credentials and initial database:
- * jdbc:hive2://server:10001/db;user=foo;password=bar?hive.server2.transport.mode=http;hive.server2.thrift.http.path=hs2
+ * <p>Connect to http://server:10001/hs2, with specified basicAuth credentials and initial
+ * database:
+ * jdbc:hive2://server:10001/db;user=foo;password=bar?hive.server2.transport.mode=http;hive.server2.thrift.http.path=hs2
*
* @param uri
* @return
* @throws SQLException
*/
- static JdbcConnectionParams parseURL(String uri, Properties info) throws JdbcUriParseException,
- SQLException, ZooKeeperHiveClientException {
+ static JdbcConnectionParams parseURL(String uri, Properties info)
+ throws JdbcUriParseException, SQLException, ZooKeeperHiveClientException {
JdbcConnectionParams connParams = new JdbcConnectionParams();
if (!uri.startsWith(URL_PREFIX)) {
@@ -349,9 +342,10 @@ public class Utils {
if (sessVars != null) {
Matcher sessMatcher = pattern.matcher(sessVars);
while (sessMatcher.find()) {
- if (connParams.getSessionVars().put(sessMatcher.group(1), sessMatcher.group(2)) != null) {
- throw new JdbcUriParseException("Bad URL format: Multiple values for property "
- + sessMatcher.group(1));
+ if (connParams.getSessionVars().put(sessMatcher.group(1), sessMatcher.group(2))
+ != null) {
+ throw new JdbcUriParseException(
+ "Bad URL format: Multiple values for property " + sessMatcher.group(1));
}
}
}
@@ -378,36 +372,47 @@ public class Utils {
connParams.getHiveVars().put(varMatcher.group(1), varMatcher.group(2));
}
}
-
+
// Apply configs supplied in the JDBC connection properties object
for (Map.Entry<Object, Object> kv : info.entrySet()) {
if ((kv.getKey() instanceof String)) {
String key = (String) kv.getKey();
if (key.startsWith(JdbcConnectionParams.HIVE_VAR_PREFIX)) {
- connParams.getHiveVars().put(
- key.substring(JdbcConnectionParams.HIVE_VAR_PREFIX.length()), info.getProperty(key));
+ connParams
+ .getHiveVars()
+ .put(
+ key.substring(JdbcConnectionParams.HIVE_VAR_PREFIX.length()),
+ info.getProperty(key));
} else if (key.startsWith(JdbcConnectionParams.HIVE_CONF_PREFIX)) {
- connParams.getHiveConfs().put(
- key.substring(JdbcConnectionParams.HIVE_CONF_PREFIX.length()), info.getProperty(key));
+ connParams
+ .getHiveConfs()
+ .put(
+ key.substring(JdbcConnectionParams.HIVE_CONF_PREFIX.length()),
+ info.getProperty(key));
}
}
}
// Extract user/password from JDBC connection properties if its not supplied
// in the connection URL
if (!connParams.getSessionVars().containsKey(JdbcConnectionParams.AUTH_USER)) {
- if (info.containsKey(JdbcConnectionParams.AUTH_USER)) {
- connParams.getSessionVars().put(JdbcConnectionParams.AUTH_USER,
- info.getProperty(JdbcConnectionParams.AUTH_USER));
- }
- if (info.containsKey(JdbcConnectionParams.AUTH_PASSWD)) {
- connParams.getSessionVars().put(JdbcConnectionParams.AUTH_PASSWD,
- info.getProperty(JdbcConnectionParams.AUTH_PASSWD));
- }
+ if (info.containsKey(JdbcConnectionParams.AUTH_USER)) {
+ connParams
+ .getSessionVars()
+ .put(JdbcConnectionParams.AUTH_USER, info.getProperty(JdbcConnectionParams.AUTH_USER));
+ }
+ if (info.containsKey(JdbcConnectionParams.AUTH_PASSWD)) {
+ connParams
+ .getSessionVars()
+ .put(
+ JdbcConnectionParams.AUTH_PASSWD,
+ info.getProperty(JdbcConnectionParams.AUTH_PASSWD));
+ }
}
if (info.containsKey(JdbcConnectionParams.AUTH_TYPE)) {
- connParams.getSessionVars().put(JdbcConnectionParams.AUTH_TYPE,
- info.getProperty(JdbcConnectionParams.AUTH_TYPE));
+ connParams
+ .getSessionVars()
+ .put(JdbcConnectionParams.AUTH_TYPE, info.getProperty(JdbcConnectionParams.AUTH_TYPE));
}
// Handle all deprecations here:
@@ -415,19 +420,30 @@ public class Utils {
String usageUrlBase = "jdbc:hive2://<host>:<port>/dbName;";
// Handle deprecation of AUTH_QOP_DEPRECATED
newUsage = usageUrlBase + JdbcConnectionParams.AUTH_QOP + "=<qop_value>";
- handleParamDeprecation(connParams.getSessionVars(), connParams.getSessionVars(),
- JdbcConnectionParams.AUTH_QOP_DEPRECATED, JdbcConnectionParams.AUTH_QOP, newUsage);
+ handleParamDeprecation(
+ connParams.getSessionVars(),
+ connParams.getSessionVars(),
+ JdbcConnectionParams.AUTH_QOP_DEPRECATED,
+ JdbcConnectionParams.AUTH_QOP,
+ newUsage);
// Handle deprecation of TRANSPORT_MODE_DEPRECATED
newUsage = usageUrlBase + JdbcConnectionParams.TRANSPORT_MODE + "=<transport_mode_value>";
- handleParamDeprecation(connParams.getHiveConfs(), connParams.getSessionVars(),
- JdbcConnectionParams.TRANSPORT_MODE_DEPRECATED, JdbcConnectionParams.TRANSPORT_MODE,
+ handleParamDeprecation(
+ connParams.getHiveConfs(),
+ connParams.getSessionVars(),
+ JdbcConnectionParams.TRANSPORT_MODE_DEPRECATED,
+ JdbcConnectionParams.TRANSPORT_MODE,
newUsage);
// Handle deprecation of HTTP_PATH_DEPRECATED
newUsage = usageUrlBase + JdbcConnectionParams.HTTP_PATH + "=<http_path_value>";
- handleParamDeprecation(connParams.getHiveConfs(), connParams.getSessionVars(),
- JdbcConnectionParams.HTTP_PATH_DEPRECATED, JdbcConnectionParams.HTTP_PATH, newUsage);
+ handleParamDeprecation(
+ connParams.getHiveConfs(),
+ connParams.getSessionVars(),
+ JdbcConnectionParams.HTTP_PATH_DEPRECATED,
+ JdbcConnectionParams.HTTP_PATH,
+ newUsage);
// Extract host, port
if (connParams.isEmbeddedMode()) {
// In case of embedded mode we were supplied with an empty authority.
@@ -448,20 +464,25 @@ public class Utils {
}
/**
- * Remove the deprecatedName param from the fromMap and put the key value in the toMap.
- * Also log a deprecation message for the client.
+ * Remove the deprecatedName param from the fromMap and put the key value in the toMap. Also log a
+ * deprecation message for the client.
+ *
* @param fromMap
* @param toMap
* @param deprecatedName
* @param newName
* @param newUsage
*/
- private static void handleParamDeprecation(Map<String, String> fromMap, Map<String, String> toMap,
- String deprecatedName, String newName, String newUsage) {
+ private static void handleParamDeprecation(
+ Map<String, String> fromMap,
+ Map<String, String> toMap,
+ String deprecatedName,
+ String newName,
+ String newUsage) {
if (fromMap.containsKey(deprecatedName)) {
LOG.warn("***** JDBC param deprecation *****");
LOG.warn("The use of " + deprecatedName + " is deprecated.");
- LOG.warn("Please use " + newName +" like so: " + newUsage);
+ LOG.warn("Please use " + newName + " like so: " + newUsage);
String paramValue = fromMap.remove(deprecatedName);
toMap.put(newName, paramValue);
}
@@ -481,10 +502,9 @@ public class Utils {
String authorities;
/**
* For a jdbc uri like:
- * jdbc:hive2://<host1>:<port1>,<host2>:<port2>/dbName;sess_var_list?conf_list#var_list
- * Extract the uri host:port list starting after "jdbc:hive2://",
- * till the 1st "/" or "?" or "#" whichever comes first & in the given order
- * Examples:
+ * jdbc:hive2://<host1>:<port1>,<host2>:<port2>/dbName;sess_var_list?conf_list#var_list Extract
+ * the uri host:port list starting after "jdbc:hive2://", till the 1st "/" or "?" or "#"
+ * whichever comes first & in the given order Examples:
* jdbc:hive2://host1:port1,host2:port2,host3:port3/db;k1=v1?k2=v2#k3=v3
* jdbc:hive2://host1:port1,host2:port2,host3:port3/;k1=v1?k2=v2#k3=v3
* jdbc:hive2://host1:port1,host2:port2,host3:port3?k2=v2#k3=v3
@@ -512,8 +532,8 @@ public class Utils {
String serviceDiscoveryMode =
connParams.getSessionVars().get(JdbcConnectionParams.SERVICE_DISCOVERY_MODE);
if ((serviceDiscoveryMode != null)
- && (JdbcConnectionParams.SERVICE_DISCOVERY_MODE_ZOOKEEPER
- .equalsIgnoreCase(serviceDiscoveryMode))) {
+ && (JdbcConnectionParams.SERVICE_DISCOVERY_MODE_ZOOKEEPER.equalsIgnoreCase(
+ serviceDiscoveryMode))) {
// Set ZooKeeper ensemble in connParams for later use
connParams.setZooKeeperEnsemble(joinStringArray(connParams.getAuthorityList(), ","));
// Configure using ZooKeeper
@@ -529,9 +549,11 @@ public class Utils {
String host = jdbcURI.getHost();
int port = jdbcURI.getPort();
if (host == null) {
- throw new JdbcUriParseException("Bad URL format. Hostname not found "
- + " in authority part of the url: " + jdbcURI.getAuthority()
- + ". Are you missing a '/' after the hostname ?");
+ throw new JdbcUriParseException(
+ "Bad URL format. Hostname not found "
+ + " in authority part of the url: "
+ + jdbcURI.getAuthority()
+ + ". Are you missing a '/' after the hostname ?");
}
// Set the port to default value; we do support jdbc url like:
// jdbc:hive2://localhost/db
@@ -559,10 +581,14 @@ public class Utils {
// Update connection params (including host, port) from ZooKeeper
try {
ZooKeeperHiveClientHelper.configureConnParams(connParams);
- connParams.setJdbcUriString(connParams.getJdbcUriString().replace(
- oldServerHost + ":" + oldServerPort, connParams.getHost() + ":" + connParams.getPort()));
+ connParams.setJdbcUriString(
+ connParams
+ .getJdbcUriString()
+ .replace(
+ oldServerHost + ":" + oldServerPort,
+ connParams.getHost() + ":" + connParams.getPort()));
LOG.info("Selected HiveServer2 instance with uri: " + connParams.getJdbcUriString());
- } catch(ZooKeeperHiveClientException e) {
+ } catch (ZooKeeperHiveClientException e) {
LOG.error(e.getMessage());
return false;
}
@@ -582,21 +608,17 @@ public class Utils {
}
/**
- * Takes a version string delimited by '.' and '-' characters
- * and returns a partial version.
+ * Takes a version string delimited by '.' and '-' characters and returns a partial version.
*
- * @param fullVersion
- * version string.
- * @param position
- * position of version string to get starting at 0. eg, for a X.x.xxx
- * string, 0 will return the major version, 1 will return minor
- * version.
+ * @param fullVersion version string.
+ * @param position position of version string to get starting at 0. eg, for a X.x.xxx string, 0
+ * will return the major version, 1 will return minor version.
* @return version part, or -1 if version string was malformed.
*/
static int getVersionPart(String fullVersion, int position) {
int version = -1;
try {
- String[] tokens = fullVersion.split("[\\.-]"); //$NON-NLS-1$
+ String[] tokens = fullVersion.split("[\\.-]"); // $NON-NLS-1$
if (tokens != null && tokens.length > 1 && tokens[position] != null) {
version = Integer.parseInt(tokens[position]);
@@ -608,14 +630,15 @@ public class Utils {
}
/**
- * The function iterates through the list of cookies in the cookiestore and tries to
- * match them with the cookieName. If there is a match, the cookieStore already
- * has a valid cookie and the client need not send Credentials for validation purpose.
+ * The function iterates through the list of cookies in the cookiestore and tries to match them
+ * with the cookieName. If there is a match, the cookieStore already has a valid cookie and the
+ * client need not send Credentials for validation purpose.
+ *
* @param cookieStore The cookie Store
* @param cookieName Name of the cookie which needs to be validated
* @param isSSL Whether this is a http/https connection
- * @return true or false based on whether the client needs to send the credentials or
- * not to the server.
+ * @return true or false based on whether the client needs to send the credentials or not to the
+ * server.
*/
static boolean needToSendCredentials(CookieStore cookieStore, String cookieName, boolean isSSL) {
if (cookieName == null || cookieStore == null) {
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/XsrfHttpRequestInterceptor.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/XsrfHttpRequestInterceptor.java
index fafbcdd..b25d011 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/XsrfHttpRequestInterceptor.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/XsrfHttpRequestInterceptor.java
@@ -17,13 +17,12 @@
package org.apache.kyuubi.jdbc.hive;
+import java.io.IOException;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.protocol.HttpContext;
-import java.io.IOException;
-
public class XsrfHttpRequestInterceptor implements HttpRequestInterceptor {
// Note : This implements HttpRequestInterceptor rather than extending
@@ -41,14 +40,14 @@ public class XsrfHttpRequestInterceptor implements HttpRequestInterceptor {
private static boolean injectHeader = true;
- public static void enableHeaderInjection(boolean enabled){
+ public static void enableHeaderInjection(boolean enabled) {
injectHeader = enabled;
}
@Override
public void process(HttpRequest httpRequest, HttpContext httpContext)
throws HttpException, IOException {
- if (injectHeader){
+ if (injectHeader) {
httpRequest.addHeader("X-XSRF-HEADER", "true");
}
}
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/ZooKeeperHiveClientException.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/ZooKeeperHiveClientException.java
index edfacaf..c24bfa6 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/ZooKeeperHiveClientException.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/ZooKeeperHiveClientException.java
@@ -21,16 +21,12 @@ public class ZooKeeperHiveClientException extends Exception {
private static final long serialVersionUID = 0;
- /**
- * @param cause (original exception)
- */
+ /** @param cause (original exception) */
public ZooKeeperHiveClientException(Throwable cause) {
super(cause);
}
- /**
- * @param msg (exception message)
- */
+ /** @param msg (exception message) */
public ZooKeeperHiveClientException(String msg) {
super(msg);
}
@@ -42,5 +38,4 @@ public class ZooKeeperHiveClientException extends Exception {
public ZooKeeperHiveClientException(String msg, Throwable cause) {
super(msg, cause);
}
-
}
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/ZooKeeperHiveClientHelper.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/ZooKeeperHiveClientHelper.java
index c2f5a78..498332e 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/ZooKeeperHiveClientHelper.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/ZooKeeperHiveClientHelper.java
@@ -22,7 +22,6 @@ import java.util.List;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
@@ -34,13 +33,10 @@ class ZooKeeperHiveClientHelper {
static final Logger LOG = LoggerFactory.getLogger(ZooKeeperHiveClientHelper.class.getName());
// Pattern for key1=value1;key2=value2
private static final Pattern kvPattern = Pattern.compile("([^=;]*)=([^;]*)[;]?");
- /**
- * A no-op watcher class
- */
+ /** A no-op watcher class */
static class DummyWatcher implements Watcher {
@Override
- public void process(org.apache.zookeeper.WatchedEvent event) {
- }
+ public void process(org.apache.zookeeper.WatchedEvent event) {}
}
static void configureConnParams(Utils.JdbcConnectionParams connParams)
@@ -55,8 +51,10 @@ class ZooKeeperHiveClientHelper {
Random randomizer = new Random();
String serverNode;
CuratorFramework zooKeeperClient =
- CuratorFrameworkFactory.builder().connectString(zooKeeperEnsemble)
- .retryPolicy(new ExponentialBackoffRetry(1000, 3)).build();
+ CuratorFrameworkFactory.builder()
+ .connectString(zooKeeperEnsemble)
+ .retryPolicy(new ExponentialBackoffRetry(1000, 3))
+ .build();
try {
zooKeeperClient.start();
serverHosts = zooKeeperClient.getChildren().forPath("/" + zooKeeperNamespace);
@@ -82,8 +80,8 @@ class ZooKeeperHiveClientHelper {
if ((dataStr != null) && (!matcher.find())) {
String[] split = dataStr.split(":");
if (split.length != 2) {
- throw new ZooKeeperHiveClientException("Unable to read HiveServer2 uri from ZooKeeper: "
- + dataStr);
+ throw new ZooKeeperHiveClientException(
+ "Unable to read HiveServer2 uri from ZooKeeper: " + dataStr);
}
connParams.setHost(split[0]);
connParams.setPort(Integer.parseInt(split[1]));
@@ -91,7 +89,8 @@ class ZooKeeperHiveClientHelper {
applyConfs(dataStr, connParams);
}
} catch (Exception e) {
- throw new ZooKeeperHiveClientException("Unable to read HiveServer2 configs from ZooKeeper", e);
+ throw new ZooKeeperHiveClientException(
+ "Unable to read HiveServer2 configs from ZooKeeper", e);
} finally {
// Close the client connection with ZooKeeper
if (zooKeeperClient != null) {
@@ -115,8 +114,8 @@ class ZooKeeperHiveClientHelper {
// Have to use this if-else since switch-case on String is supported Java 7 onwards
if ((matcher.group(1) != null)) {
if ((matcher.group(2) == null)) {
- throw new Exception("Null config value for: " + matcher.group(1)
- + " published by the server.");
+ throw new Exception(
+ "Null config value for: " + matcher.group(1) + " published by the server.");
}
// Set host
if (matcher.group(1).equals("hive.server2.thrift.bind.host")) {
@@ -124,8 +123,12 @@ class ZooKeeperHiveClientHelper {
}
// Set transportMode
if ((matcher.group(1).equals("hive.server2.transport.mode"))
- && !(connParams.getSessionVars().containsKey(Utils.JdbcConnectionParams.TRANSPORT_MODE))) {
- connParams.getSessionVars().put(Utils.JdbcConnectionParams.TRANSPORT_MODE, matcher.group(2));
+ && !(connParams
+ .getSessionVars()
+ .containsKey(Utils.JdbcConnectionParams.TRANSPORT_MODE))) {
+ connParams
+ .getSessionVars()
+ .put(Utils.JdbcConnectionParams.TRANSPORT_MODE, matcher.group(2));
}
// Set port
if (matcher.group(1).equals("hive.server2.thrift.port")) {
@@ -146,38 +149,48 @@ class ZooKeeperHiveClientHelper {
connParams.getSessionVars().put(Utils.JdbcConnectionParams.HTTP_PATH, matcher.group(2));
}
// Set SSL
- if ((matcher.group(1) != null) && (matcher.group(1).equals("hive.server2.use.SSL"))
+ if ((matcher.group(1) != null)
+ && (matcher.group(1).equals("hive.server2.use.SSL"))
&& !(connParams.getSessionVars().containsKey(Utils.JdbcConnectionParams.USE_SSL))) {
connParams.getSessionVars().put(Utils.JdbcConnectionParams.USE_SSL, matcher.group(2));
}
/**
- * Note: this is pretty messy, but sticking to the current implementation.
- * Set authentication configs. Note that in JDBC driver, we have 3 auth modes: NOSASL,
- * Kerberos (including delegation token mechanism) and password based.
- * The use of JdbcConnectionParams.AUTH_TYPE==JdbcConnectionParams.AUTH_SIMPLE picks NOSASL.
- * The presence of JdbcConnectionParams.AUTH_PRINCIPAL==<principal> picks Kerberos.
- * If principal is absent, the presence of
+ * Note: this is pretty messy, but sticking to the current implementation. Set
+ * authentication configs. Note that in JDBC driver, we have 3 auth modes: NOSASL, Kerberos
+ * (including delegation token mechanism) and password based. The use of
+ * JdbcConnectionParams.AUTH_TYPE==JdbcConnectionParams.AUTH_SIMPLE picks NOSASL. The
+ * presence of JdbcConnectionParams.AUTH_PRINCIPAL==<principal> picks Kerberos. If principal
+ * is absent, the presence of
* JdbcConnectionParams.AUTH_TYPE==JdbcConnectionParams.AUTH_TOKEN uses delegation token.
* Otherwise password based (which includes NONE, PAM, LDAP, CUSTOM)
*/
if (matcher.group(1).equals("hive.server2.authentication")) {
// NOSASL
if (matcher.group(2).equalsIgnoreCase("NOSASL")
- && !(connParams.getSessionVars().containsKey(Utils.JdbcConnectionParams.AUTH_TYPE) && connParams
- .getSessionVars().get(Utils.JdbcConnectionParams.AUTH_TYPE)
- .equalsIgnoreCase(Utils.JdbcConnectionParams.AUTH_SIMPLE))) {
- connParams.getSessionVars().put(Utils.JdbcConnectionParams.AUTH_TYPE,
- Utils.JdbcConnectionParams.AUTH_SIMPLE);
+ && !(connParams.getSessionVars().containsKey(Utils.JdbcConnectionParams.AUTH_TYPE)
+ && connParams
+ .getSessionVars()
+ .get(Utils.JdbcConnectionParams.AUTH_TYPE)
+ .equalsIgnoreCase(Utils.JdbcConnectionParams.AUTH_SIMPLE))) {
+ connParams
+ .getSessionVars()
+ .put(Utils.JdbcConnectionParams.AUTH_TYPE, Utils.JdbcConnectionParams.AUTH_SIMPLE);
}
}
// KERBEROS
// If delegation token is passed from the client side, do not set the principal
if (matcher.group(1).equalsIgnoreCase("hive.server2.authentication.kerberos.principal")
- && !(connParams.getSessionVars().containsKey(Utils.JdbcConnectionParams.AUTH_TYPE) && connParams
- .getSessionVars().get(Utils.JdbcConnectionParams.AUTH_TYPE)
- .equalsIgnoreCase(Utils.JdbcConnectionParams.AUTH_TOKEN))
- && !(connParams.getSessionVars().containsKey(Utils.JdbcConnectionParams.AUTH_PRINCIPAL))) {
- connParams.getSessionVars().put(Utils.JdbcConnectionParams.AUTH_PRINCIPAL, matcher.group(2));
+ && !(connParams.getSessionVars().containsKey(Utils.JdbcConnectionParams.AUTH_TYPE)
+ && connParams
+ .getSessionVars()
+ .get(Utils.JdbcConnectionParams.AUTH_TYPE)
+ .equalsIgnoreCase(Utils.JdbcConnectionParams.AUTH_TOKEN))
+ && !(connParams
+ .getSessionVars()
+ .containsKey(Utils.JdbcConnectionParams.AUTH_PRINCIPAL))) {
+ connParams
+ .getSessionVars()
+ .put(Utils.JdbcConnectionParams.AUTH_PRINCIPAL, matcher.group(2));
}
}
}
diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/logs/InPlaceUpdateStream.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/logs/InPlaceUpdateStream.java
index a4da21c..8ca106e 100644
--- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/logs/InPlaceUpdateStream.java
+++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/logs/InPlaceUpdateStream.java
@@ -24,19 +24,18 @@ import org.slf4j.LoggerFactory;
public interface InPlaceUpdateStream {
void update(TProgressUpdateResp response);
- InPlaceUpdateStream NO_OP = new InPlaceUpdateStream() {
- private final EventNotifier eventNotifier = new EventNotifier();
- @Override
- public void update(TProgressUpdateResp response) {
+ InPlaceUpdateStream NO_OP =
+ new InPlaceUpdateStream() {
+ private final EventNotifier eventNotifier = new EventNotifier();
- }
-
- @Override
- public EventNotifier getEventNotifier() {
- return eventNotifier;
- }
+ @Override
+ public void update(TProgressUpdateResp response) {}
- };
+ @Override
+ public EventNotifier getEventNotifier() {
+ return eventNotifier;
+ }
+ };
EventNotifier getEventNotifier();
@@ -52,7 +51,6 @@ public interface InPlaceUpdateStream {
private synchronized boolean isProgressBarComplete() {
return isComplete;
-
}
public synchronized void operationLogShowedToUser() {
diff --git a/kyuubi-hive-jdbc/src/test/java/org/apache/kyuubi/jdbc/hive/KyuubiStatementTest.java b/kyuubi-hive-jdbc/src/test/java/org/apache/kyuubi/jdbc/hive/KyuubiStatementTest.java
index 66c2d10..1d0acbb 100644
--- a/kyuubi-hive-jdbc/src/test/java/org/apache/kyuubi/jdbc/hive/KyuubiStatementTest.java
+++ b/kyuubi-hive-jdbc/src/test/java/org/apache/kyuubi/jdbc/hive/KyuubiStatementTest.java
@@ -17,11 +17,10 @@
*/
package org.apache.kyuubi.jdbc.hive;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
import java.sql.SQLException;
-
-import static org.junit.Assert.assertEquals;
+import org.junit.Test;
public class KyuubiStatementTest {
diff --git a/kyuubi-hive-jdbc/src/test/java/org/apache/kyuubi/jdbc/hive/TestJdbcDriver.java b/kyuubi-hive-jdbc/src/test/java/org/apache/kyuubi/jdbc/hive/TestJdbcDriver.java
index 12b2e3e..928a548 100644
--- a/kyuubi-hive-jdbc/src/test/java/org/apache/kyuubi/jdbc/hive/TestJdbcDriver.java
+++ b/kyuubi-hive-jdbc/src/test/java/org/apache/kyuubi/jdbc/hive/TestJdbcDriver.java
@@ -18,13 +18,7 @@
package org.apache.kyuubi.jdbc.hive;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import static org.junit.Assert.assertEquals;
import java.io.BufferedWriter;
import java.io.File;
@@ -32,8 +26,13 @@ import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
-
-import static org.junit.Assert.assertEquals;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class TestJdbcDriver {
@@ -48,20 +47,21 @@ public class TestJdbcDriver {
@Parameters
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{
- // Here are some positive cases which can be executed as below :
- {"show databases;show tables;", "show databases,show tables"},
- {" show\n\r tables;", "show tables"},
- {"show databases; show\ntables;", "show databases,show tables"},
- {"show tables;", "show tables"},
- {"show tables ;", "show tables"},
- // Here are some negative cases as below :
- {"show tables", ","},
- {"show tables show tables;", "show tables show tables"},
- {"show tab les;", "show tab les"},
- {"#show tables; show\n tables;", "tables"},
- {"show tab les;show tables;", "show tab les,show tables"}
- });
+ return Arrays.asList(
+ new Object[][] {
+ // Here are some positive cases which can be executed as below :
+ {"show databases;show tables;", "show databases,show tables"},
+ {" show\n\r tables;", "show tables"},
+ {"show databases; show\ntables;", "show databases,show tables"},
+ {"show tables;", "show tables"},
+ {"show tables ;", "show tables"},
+ // Here are some negative cases as below :
+ {"show tables", ","},
+ {"show tables show tables;", "show tables show tables"},
+ {"show tab les;", "show tab les"},
+ {"#show tables; show\n tables;", "tables"},
+ {"show tab les;show tables;", "show tab les,show tables"}
+ });
}
@BeforeClass
@@ -86,9 +86,9 @@ public class TestJdbcDriver {
bw = new BufferedWriter(new FileWriter(file));
bw.write(input);
bw.flush();
- assertEquals(Arrays.asList(expected.split(",")),
- KyuubiConnection.parseInitFile(file.toString()));
- } catch(Exception e) {
+ assertEquals(
+ Arrays.asList(expected.split(",")), KyuubiConnection.parseInitFile(file.toString()));
+ } catch (Exception e) {
Assert.fail("Test was failed due to " + e);
} finally {
if (bw != null) {
diff --git a/kyuubi-hive-jdbc/src/test/java/org/apache/kyuubi/jdbc/hive/TestKyuubiPreparedStatement.java b/kyuubi-hive-jdbc/src/test/java/org/apache/kyuubi/jdbc/hive/TestKyuubiPreparedStatement.java
index 641d05f..04c8ff8 100644
--- a/kyuubi-hive-jdbc/src/test/java/org/apache/kyuubi/jdbc/hive/TestKyuubiPreparedStatement.java
+++ b/kyuubi-hive-jdbc/src/test/java/org/apache/kyuubi/jdbc/hive/TestKyuubiPreparedStatement.java
@@ -23,7 +23,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.sql.SQLException;
-
import org.apache.hive.service.rpc.thrift.TCLIService.Iface;
import org.apache.hive.service.rpc.thrift.TExecuteStatementReq;
import org.apache.hive.service.rpc.thrift.TExecuteStatementResp;
@@ -42,114 +41,114 @@ import org.mockito.MockitoAnnotations;
public class TestKyuubiPreparedStatement {
- @Mock
- private KyuubiConnection connection;
- @Mock
- private Iface client;
- @Mock
- private TSessionHandle sessHandle;
- @Mock
- TExecuteStatementResp tExecStatementResp;
- @Mock
- TGetOperationStatusResp tGetOperationStatusResp;
- private TStatus tStatus_SUCCESS = new TStatus(TStatusCode.SUCCESS_STATUS);
- @Mock
- private TOperationHandle tOperationHandle;
-
- @Before
- public void before() throws Exception {
- MockitoAnnotations.initMocks(this);
- when(tExecStatementResp.getStatus()).thenReturn(tStatus_SUCCESS);
- when(tExecStatementResp.getOperationHandle()).thenReturn(tOperationHandle);
-
- when(tGetOperationStatusResp.getStatus()).thenReturn(tStatus_SUCCESS);
- when(tGetOperationStatusResp.getOperationState()).thenReturn(TOperationState.FINISHED_STATE);
- when(tGetOperationStatusResp.isSetOperationState()).thenReturn(true);
- when(tGetOperationStatusResp.isSetOperationCompleted()).thenReturn(true);
-
- when(client.GetOperationStatus(any(TGetOperationStatusReq.class))).thenReturn(tGetOperationStatusResp);
- when(client.ExecuteStatement(any(TExecuteStatementReq.class))).thenReturn(tExecStatementResp);
- }
-
- @SuppressWarnings("resource")
- @Test
- public void testNonParameterized() throws Exception {
- String sql = "select 1";
- KyuubiPreparedStatement ps = new KyuubiPreparedStatement(connection, client, sessHandle, sql);
- ps.execute();
-
- ArgumentCaptor<TExecuteStatementReq> argument = ArgumentCaptor.forClass(TExecuteStatementReq.class);
- verify(client).ExecuteStatement(argument.capture());
- assertEquals("select 1", argument.getValue().getStatement());
- }
-
- @SuppressWarnings("resource")
- @Test
- public void unusedArgument() throws Exception {
- String sql = "select 1";
- KyuubiPreparedStatement ps = new KyuubiPreparedStatement(connection, client, sessHandle, sql);
- ps.setString(1, "asd");
- ps.execute();
- }
-
- @SuppressWarnings("resource")
- @Test(expected=SQLException.class)
- public void unsetArgument() throws Exception {
- String sql = "select 1 from x where a=?";
- KyuubiPreparedStatement ps = new KyuubiPreparedStatement(connection, client, sessHandle, sql);
- ps.execute();
- }
-
- @SuppressWarnings("resource")
- @Test
- public void oneArgument() throws Exception {
- String sql = "select 1 from x where a=?";
- KyuubiPreparedStatement ps = new KyuubiPreparedStatement(connection, client, sessHandle, sql);
- ps.setString(1, "asd");
- ps.execute();
-
- ArgumentCaptor<TExecuteStatementReq> argument = ArgumentCaptor.forClass(TExecuteStatementReq.class);
- verify(client).ExecuteStatement(argument.capture());
- assertEquals("select 1 from x where a='asd'", argument.getValue().getStatement());
- }
-
- @SuppressWarnings("resource")
- @Test
- public void escapingOfStringArgument() throws Exception {
- String sql = "select 1 from x where a=?";
- KyuubiPreparedStatement ps = new KyuubiPreparedStatement(connection, client, sessHandle, sql);
- ps.setString(1, "a'\"d");
- ps.execute();
-
- ArgumentCaptor<TExecuteStatementReq> argument = ArgumentCaptor.forClass(TExecuteStatementReq.class);
- verify(client).ExecuteStatement(argument.capture());
- assertEquals("select 1 from x where a='a\\'\"d'", argument.getValue().getStatement());
- }
-
- @SuppressWarnings("resource")
- @Test
- public void pastingIntoQuery() throws Exception {
- String sql = "select 1 from x where a='e' || ?";
- KyuubiPreparedStatement ps = new KyuubiPreparedStatement(connection, client, sessHandle, sql);
- ps.setString(1, "v");
- ps.execute();
-
- ArgumentCaptor<TExecuteStatementReq> argument = ArgumentCaptor.forClass(TExecuteStatementReq.class);
- verify(client).ExecuteStatement(argument.capture());
- assertEquals("select 1 from x where a='e' || 'v'", argument.getValue().getStatement());
- }
-
- // HIVE-13625
- @SuppressWarnings("resource")
- @Test
- public void pastingIntoEscapedQuery() throws Exception {
- String sql = "select 1 from x where a='\\044e' || ?";
- KyuubiPreparedStatement ps = new KyuubiPreparedStatement(connection, client, sessHandle, sql);
- ps.setString(1, "v");
- ps.execute();
-
- ArgumentCaptor<TExecuteStatementReq> argument = ArgumentCaptor.forClass(TExecuteStatementReq.class);
- verify(client).ExecuteStatement(argument.capture());
- assertEquals("select 1 from x where a='\\044e' || 'v'", argument.getValue().getStatement());
- }
+ @Mock private KyuubiConnection connection;
+ @Mock private Iface client;
+ @Mock private TSessionHandle sessHandle;
+ @Mock TExecuteStatementResp tExecStatementResp;
+ @Mock TGetOperationStatusResp tGetOperationStatusResp;
+ private TStatus tStatus_SUCCESS = new TStatus(TStatusCode.SUCCESS_STATUS);
+ @Mock private TOperationHandle tOperationHandle;
+
+ @Before
+ public void before() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ when(tExecStatementResp.getStatus()).thenReturn(tStatus_SUCCESS);
+ when(tExecStatementResp.getOperationHandle()).thenReturn(tOperationHandle);
+
+ when(tGetOperationStatusResp.getStatus()).thenReturn(tStatus_SUCCESS);
+ when(tGetOperationStatusResp.getOperationState()).thenReturn(TOperationState.FINISHED_STATE);
+ when(tGetOperationStatusResp.isSetOperationState()).thenReturn(true);
+ when(tGetOperationStatusResp.isSetOperationCompleted()).thenReturn(true);
+
+ when(client.GetOperationStatus(any(TGetOperationStatusReq.class)))
+ .thenReturn(tGetOperationStatusResp);
+ when(client.ExecuteStatement(any(TExecuteStatementReq.class))).thenReturn(tExecStatementResp);
+ }
+
+ @SuppressWarnings("resource")
+ @Test
+ public void testNonParameterized() throws Exception {
+ String sql = "select 1";
+ KyuubiPreparedStatement ps = new KyuubiPreparedStatement(connection, client, sessHandle, sql);
+ ps.execute();
+
+ ArgumentCaptor<TExecuteStatementReq> argument =
+ ArgumentCaptor.forClass(TExecuteStatementReq.class);
+ verify(client).ExecuteStatement(argument.capture());
+ assertEquals("select 1", argument.getValue().getStatement());
+ }
+
+ @SuppressWarnings("resource")
+ @Test
+ public void unusedArgument() throws Exception {
+ String sql = "select 1";
+ KyuubiPreparedStatement ps = new KyuubiPreparedStatement(connection, client, sessHandle, sql);
+ ps.setString(1, "asd");
+ ps.execute();
+ }
+
+ @SuppressWarnings("resource")
+ @Test(expected = SQLException.class)
+ public void unsetArgument() throws Exception {
+ String sql = "select 1 from x where a=?";
+ KyuubiPreparedStatement ps = new KyuubiPreparedStatement(connection, client, sessHandle, sql);
+ ps.execute();
+ }
+
+ @SuppressWarnings("resource")
+ @Test
+ public void oneArgument() throws Exception {
+ String sql = "select 1 from x where a=?";
+ KyuubiPreparedStatement ps = new KyuubiPreparedStatement(connection, client, sessHandle, sql);
+ ps.setString(1, "asd");
+ ps.execute();
+
+ ArgumentCaptor<TExecuteStatementReq> argument =
+ ArgumentCaptor.forClass(TExecuteStatementReq.class);
+ verify(client).ExecuteStatement(argument.capture());
+ assertEquals("select 1 from x where a='asd'", argument.getValue().getStatement());
+ }
+
+ @SuppressWarnings("resource")
+ @Test
+ public void escapingOfStringArgument() throws Exception {
+ String sql = "select 1 from x where a=?";
+ KyuubiPreparedStatement ps = new KyuubiPreparedStatement(connection, client, sessHandle, sql);
+ ps.setString(1, "a'\"d");
+ ps.execute();
+
+ ArgumentCaptor<TExecuteStatementReq> argument =
+ ArgumentCaptor.forClass(TExecuteStatementReq.class);
+ verify(client).ExecuteStatement(argument.capture());
+ assertEquals("select 1 from x where a='a\\'\"d'", argument.getValue().getStatement());
+ }
+
+ @SuppressWarnings("resource")
+ @Test
+ public void pastingIntoQuery() throws Exception {
+ String sql = "select 1 from x where a='e' || ?";
+ KyuubiPreparedStatement ps = new KyuubiPreparedStatement(connection, client, sessHandle, sql);
+ ps.setString(1, "v");
+ ps.execute();
+
+ ArgumentCaptor<TExecuteStatementReq> argument =
+ ArgumentCaptor.forClass(TExecuteStatementReq.class);
+ verify(client).ExecuteStatement(argument.capture());
+ assertEquals("select 1 from x where a='e' || 'v'", argument.getValue().getStatement());
+ }
+
+ // HIVE-13625
+ @SuppressWarnings("resource")
+ @Test
+ public void pastingIntoEscapedQuery() throws Exception {
+ String sql = "select 1 from x where a='\\044e' || ?";
+ KyuubiPreparedStatement ps = new KyuubiPreparedStatement(connection, client, sessHandle, sql);
+ ps.setString(1, "v");
+ ps.execute();
+
+ ArgumentCaptor<TExecuteStatementReq> argument =
+ ArgumentCaptor.forClass(TExecuteStatementReq.class);
+ verify(client).ExecuteStatement(argument.capture());
+ assertEquals("select 1 from x where a='\\044e' || 'v'", argument.getValue().getStatement());
+ }
}
diff --git a/pom.xml b/pom.xml
index c7eadb1..6564061 100644
--- a/pom.xml
+++ b/pom.xml
@@ -167,6 +167,7 @@
<maven.plugin.scalatest.version>2.0.2</maven.plugin.scalatest.version>
<maven.plugin.scalatest.exclude.tags>org.apache.kyuubi.tags.ExtendedSQLTest</maven.plugin.scalatest.exclude.tags>
<maven.plugin.scalatest.include.tags></maven.plugin.scalatest.include.tags>
+ <maven.plugin.spotless.version>2.17.4</maven.plugin.spotless.version>
<maven.plugin.jacoco.version>0.8.6</maven.plugin.jacoco.version>
<maven.plugin.jar.version>3.2.0</maven.plugin.jar.version>
<maven.plugin.scalastyle.version>1.0.0</maven.plugin.scalastyle.version>
@@ -1320,6 +1321,32 @@
</executions>
</plugin>
<plugin>
+ <groupId>com.diffplug.spotless</groupId>
+ <artifactId>spotless-maven-plugin</artifactId>
+ <version>${maven.plugin.spotless.version}</version>
+ <configuration>
+ <java>
+ <includes>
+ <include>src/main/java/**/*.java</include>
+ <include>src/test/java/**/*.java</include>
+ </includes>
+
+ <googleJavaFormat>
+ <version>1.7</version>
+ <style>GOOGLE</style>
+ </googleJavaFormat>
+ </java>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>${maven.plugin.download.version}</version>
@@ -1427,6 +1454,11 @@
</plugin>
<plugin>
+ <groupId>com.diffplug.spotless</groupId>
+ <artifactId>spotless-maven-plugin</artifactId>
+ </plugin>
+
+ <plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>