You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by dm...@apache.org on 2020/03/27 20:52:40 UTC
[hive] branch master updated: HIVE-23080: Clean Up
HivePreparedStatement (David Mollitor reviewed by Naveen Gangam)
This is an automated email from the ASF dual-hosted git repository.
dmollitor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push:
new 20fccec HIVE-23080: Clean Up HivePreparedStatement (David Mollitor reviewed by Naveen Gangam)
20fccec is described below
commit 20fccec2319e5b5c3a3772fc0d22a6ae3935875e
Author: David Mollitor <dm...@apache.org>
AuthorDate: Fri Mar 27 16:52:00 2020 -0400
HIVE-23080: Clean Up HivePreparedStatement (David Mollitor reviewed by Naveen Gangam)
---
.../apache/hive/jdbc/HivePreparedStatement.java | 469 ++++-----------------
1 file changed, 77 insertions(+), 392 deletions(-)
diff --git a/jdbc/src/java/org/apache/hive/jdbc/HivePreparedStatement.java b/jdbc/src/java/org/apache/hive/jdbc/HivePreparedStatement.java
index f86b112..dcd46f9 100644
--- a/jdbc/src/java/org/apache/hive/jdbc/HivePreparedStatement.java
+++ b/jdbc/src/java/org/apache/hive/jdbc/HivePreparedStatement.java
@@ -50,8 +50,7 @@ import org.apache.hive.service.rpc.thrift.TCLIService;
import org.apache.hive.service.rpc.thrift.TSessionHandle;
/**
- * HivePreparedStatement.
- *
+ * An object that represents a pre-compiled SQL statement.
*/
public class HivePreparedStatement extends HiveStatement implements PreparedStatement {
private final String sql;
@@ -67,23 +66,12 @@ public class HivePreparedStatement extends HiveStatement implements PreparedStat
this.sql = sql;
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#addBatch()
- */
-
+ @Override
public void addBatch() throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#clearParameters()
- */
-
+ @Override
public void clearParameters() throws SQLException {
this.parameters.clear();
}
@@ -96,7 +84,7 @@ public class HivePreparedStatement extends HiveStatement implements PreparedStat
*
* @throws SQLException
*/
-
+ @Override
public boolean execute() throws SQLException {
return super.execute(updateSql(sql, parameters));
}
@@ -107,17 +95,12 @@ public class HivePreparedStatement extends HiveStatement implements PreparedStat
* @return ResultSet
* @throws SQLException
*/
-
+ @Override
public ResultSet executeQuery() throws SQLException {
return super.executeQuery(updateSql(sql, parameters));
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#executeUpdate()
- */
-
+ @Override
public int executeUpdate() throws SQLException {
return super.executeUpdate(updateSql(sql, parameters));
}
@@ -131,41 +114,40 @@ public class HivePreparedStatement extends HiveStatement implements PreparedStat
* @throws SQLException
*/
private String updateSql(final String sql, HashMap<Integer, String> parameters) throws SQLException {
- List<String> parts=splitSqlStatement(sql);
-
+ 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 = ','']
- *
+ *
* @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) {
@@ -185,414 +167,196 @@ public class HivePreparedStatement extends HiveStatement implements PreparedStat
break;
}
}
- parts.add(sql.substring(off,sql.length()));
+ parts.add(sql.substring(off, sql.length()));
return parts;
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#getMetaData()
- */
-
+ @Override
public ResultSetMetaData getMetaData() throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#getParameterMetaData()
- */
-
+ @Override
public ParameterMetaData getParameterMetaData() throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setArray(int, java.sql.Array)
- */
-
+ @Override
public void setArray(int i, Array x) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setAsciiStream(int, java.io.InputStream)
- */
-
+ @Override
public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setAsciiStream(int, java.io.InputStream,
- * int)
- */
-
+ @Override
public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setAsciiStream(int, java.io.InputStream,
- * long)
- */
-
+ @Override
public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setBigDecimal(int, java.math.BigDecimal)
- */
-
+ @Override
public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
this.parameters.put(parameterIndex, x.toString());
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setBinaryStream(int, java.io.InputStream)
- */
-
+ @Override
public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
String str = new Scanner(x, "UTF-8").useDelimiter("\\A").next();
setString(parameterIndex, str);
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setBinaryStream(int, java.io.InputStream,
- * int)
- */
-
+ @Override
public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setBinaryStream(int, java.io.InputStream,
- * long)
- */
-
+ @Override
public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setBlob(int, java.sql.Blob)
- */
-
+ @Override
public void setBlob(int i, Blob x) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setBlob(int, java.io.InputStream)
- */
-
+ @Override
public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setBlob(int, java.io.InputStream, long)
- */
-
+ @Override
public void setBlob(int parameterIndex, InputStream inputStream, long length)
throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setBoolean(int, boolean)
- */
-
+ @Override
public void setBoolean(int parameterIndex, boolean x) throws SQLException {
this.parameters.put(parameterIndex, ""+x);
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setByte(int, byte)
- */
-
+ @Override
public void setByte(int parameterIndex, byte x) throws SQLException {
this.parameters.put(parameterIndex, ""+x);
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setBytes(int, byte[])
- */
-
+ @Override
public void setBytes(int parameterIndex, byte[] x) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setCharacterStream(int, java.io.Reader)
- */
-
+ @Override
public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setCharacterStream(int, java.io.Reader,
- * int)
- */
-
+ @Override
public void setCharacterStream(int parameterIndex, Reader reader, int length)
throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setCharacterStream(int, java.io.Reader,
- * long)
- */
-
+ @Override
public void setCharacterStream(int parameterIndex, Reader reader, long length)
throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setClob(int, java.sql.Clob)
- */
-
+ @Override
public void setClob(int i, Clob x) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setClob(int, java.io.Reader)
- */
-
+ @Override
public void setClob(int parameterIndex, Reader reader) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setClob(int, java.io.Reader, long)
- */
-
+ @Override
public void setClob(int parameterIndex, Reader reader, long length) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setDate(int, java.sql.Date)
- */
-
+ @Override
public void setDate(int parameterIndex, Date x) throws SQLException {
this.parameters.put(parameterIndex, "'" + x.toString() + "'");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setDate(int, java.sql.Date,
- * java.util.Calendar)
- */
-
+ @Override
public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setDouble(int, double)
- */
-
+ @Override
public void setDouble(int parameterIndex, double x) throws SQLException {
this.parameters.put(parameterIndex,""+x);
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setFloat(int, float)
- */
-
+ @Override
public void setFloat(int parameterIndex, float x) throws SQLException {
this.parameters.put(parameterIndex,""+x);
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setInt(int, int)
- */
-
+ @Override
public void setInt(int parameterIndex, int x) throws SQLException {
this.parameters.put(parameterIndex,""+x);
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setLong(int, long)
- */
-
+ @Override
public void setLong(int parameterIndex, long x) throws SQLException {
this.parameters.put(parameterIndex,""+x);
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setNCharacterStream(int, java.io.Reader)
- */
-
+ @Override
public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setNCharacterStream(int, java.io.Reader,
- * long)
- */
-
+ @Override
public void setNCharacterStream(int parameterIndex, Reader value, long length)
throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setNClob(int, java.sql.NClob)
- */
-
+ @Override
public void setNClob(int parameterIndex, NClob value) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setNClob(int, java.io.Reader)
- */
-
+ @Override
public void setNClob(int parameterIndex, Reader reader) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setNClob(int, java.io.Reader, long)
- */
-
+ @Override
public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setNString(int, java.lang.String)
- */
-
+ @Override
public void setNString(int parameterIndex, String value) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setNull(int, int)
- */
-
+ @Override
public void setNull(int parameterIndex, int sqlType) throws SQLException {
this.parameters.put(parameterIndex, "NULL");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setNull(int, int, java.lang.String)
- */
-
+ @Override
public void setNull(int paramIndex, int sqlType, String typeName) throws SQLException {
this.parameters.put(paramIndex, "NULL");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setObject(int, java.lang.Object)
- */
-
+ @Override
public void setObject(int parameterIndex, Object x) throws SQLException {
if (x == null) {
setNull(parameterIndex, Types.NULL);
@@ -628,69 +392,34 @@ public class HivePreparedStatement extends HiveStatement implements PreparedStat
}
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setObject(int, java.lang.Object, int)
- */
-
+ @Override
public void setObject(int parameterIndex, Object x, int targetSqlType)
throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setObject(int, java.lang.Object, int, int)
- */
-
+ @Override
public void setObject(int parameterIndex, Object x, int targetSqlType, int scale)
throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setRef(int, java.sql.Ref)
- */
-
+ @Override
public void setRef(int i, Ref x) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setRowId(int, java.sql.RowId)
- */
-
+ @Override
public void setRowId(int parameterIndex, RowId x) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setSQLXML(int, java.sql.SQLXML)
- */
-
+ @Override
public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setShort(int, short)
- */
-
+ @Override
public void setShort(int parameterIndex, short x) throws SQLException {
this.parameters.put(parameterIndex,""+x);
}
@@ -700,8 +429,8 @@ public class HivePreparedStatement extends HiveStatement implements PreparedStat
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 {
@@ -716,85 +445,41 @@ public class HivePreparedStatement extends HiveStatement implements PreparedStat
return newX.toString();
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setString(int, java.lang.String)
- */
-
+ @Override
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 + "'");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setTime(int, java.sql.Time)
- */
-
+ @Override
public void setTime(int parameterIndex, Time x) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setTime(int, java.sql.Time,
- * java.util.Calendar)
- */
-
+ @Override
public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setTimestamp(int, java.sql.Timestamp)
- */
-
+ @Override
public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
this.parameters.put(parameterIndex, "'" + x.toString() + "'");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setTimestamp(int, java.sql.Timestamp,
- * java.util.Calendar)
- */
-
+ @Override
public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setURL(int, java.net.URL)
- */
-
+ @Override
public void setURL(int parameterIndex, URL x) throws SQLException {
- // TODO Auto-generated method stub
throw new SQLFeatureNotSupportedException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#setUnicodeStream(int, java.io.InputStream,
- * int)
- */
-
- public void setUnicodeStream(int parameterIndex, InputStream x, int length)
- throws SQLException {
- // TODO Auto-generated method stub
+ @Override
+ public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
throw new SQLFeatureNotSupportedException("Method not supported");
}
}