You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by jv...@apache.org on 2010/08/30 05:37:11 UTC
svn commit: r990690 - in /hadoop/hive/trunk: CHANGES.txt
jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveDatabaseMetaData.java
jdbc/src/java/org/apache/hadoop/hive/jdbc/HivePreparedStatement.java
Author: jvs
Date: Mon Aug 30 03:37:09 2010
New Revision: 990690
URL: http://svn.apache.org/viewvc?rev=990690&view=rev
Log:
HIVE-1536. Add support for JDBC PreparedStatements
(Sean Flatley via jvs)
Modified:
hadoop/hive/trunk/CHANGES.txt
hadoop/hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveDatabaseMetaData.java
hadoop/hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HivePreparedStatement.java
Modified: hadoop/hive/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/CHANGES.txt?rev=990690&r1=990689&r2=990690&view=diff
==============================================================================
--- hadoop/hive/trunk/CHANGES.txt (original)
+++ hadoop/hive/trunk/CHANGES.txt Mon Aug 30 03:37:09 2010
@@ -111,6 +111,9 @@ Trunk - Unreleased
HIVE-1523. Enable some tests in miniMR mode
(Joydeep Sen Sarma via namit)
+ HIVE-1536. Add support for JDBC PreparedStatements
+ (Sean Flatley via jvs)
+
OPTIMIZATIONS
BUG FIXES
Modified: hadoop/hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveDatabaseMetaData.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveDatabaseMetaData.java?rev=990690&r1=990689&r2=990690&view=diff
==============================================================================
--- hadoop/hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveDatabaseMetaData.java (original)
+++ hadoop/hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveDatabaseMetaData.java Mon Aug 30 03:37:09 2010
@@ -44,9 +44,12 @@ import java.util.jar.Manifest;
*/
public class HiveDatabaseMetaData implements java.sql.DatabaseMetaData {
- private HiveInterface client;
+ private final HiveInterface client;
private static final String CATALOG_SEPARATOR = ".";
+ // The maximum column length = MFieldSchema.FNAME in metastore/src/model/package.jdo
+ private static final int maxColumnNameLength = 128;
+
/**
*
*/
@@ -346,8 +349,13 @@ public class HiveDatabaseMetaData implem
throw new SQLException("Method not supported");
}
+ /**
+ * Returns the value of maxColumnNameLength.
+ *
+ * @param int
+ */
public int getMaxColumnNameLength() throws SQLException {
- throw new SQLException("Method not supported");
+ return maxColumnNameLength;
}
public int getMaxColumnsInGroupBy() throws SQLException {
Modified: hadoop/hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HivePreparedStatement.java
URL: http://svn.apache.org/viewvc/hadoop/hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HivePreparedStatement.java?rev=990690&r1=990689&r2=990690&view=diff
==============================================================================
--- hadoop/hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HivePreparedStatement.java (original)
+++ hadoop/hive/trunk/jdbc/src/java/org/apache/hadoop/hive/jdbc/HivePreparedStatement.java Mon Aug 30 03:37:09 2010
@@ -42,6 +42,7 @@ import java.sql.Timestamp;
import java.util.Calendar;
import org.apache.hadoop.hive.service.HiveInterface;
+import org.apache.hadoop.hive.service.HiveServerException;
/**
* HivePreparedStatement.
@@ -51,6 +52,28 @@ public class HivePreparedStatement imple
private String sql;
private JdbcSessionState session;
private HiveInterface client;
+ /**
+ * We need to keep a reference to the result set to support the following:
+ * <code>
+ * statement.execute(String sql);
+ * statement.getResultSet();
+ * </code>.
+ */
+ private ResultSet resultSet = null;
+ /**
+ * The maximum number of rows this statement should return (0 => all rows).
+ */
+ private final int maxRows = 0;
+
+ /**
+ * Add SQLWarnings to the warningChain if needed.
+ */
+ private final SQLWarning warningChain = null;
+
+ /**
+ * Keep state so we can fail certain calls made after close().
+ */
+ private boolean isClosed = false;
/**
*
@@ -84,30 +107,29 @@ public class HivePreparedStatement imple
// throw new SQLException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#execute()
+ /**
+ * 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
*/
public boolean execute() throws SQLException {
- // TODO Auto-generated method stub
- throw new SQLException("Method not supported");
+ ResultSet rs = executeImmediate(sql);
+ return rs != null;
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.PreparedStatement#executeQuery()
+ /**
+ * Invokes executeQuery(sql) using the sql provided to the constructor.
+ *
+ * @return ResultSet
+ * @throws
*/
public ResultSet executeQuery() throws SQLException {
- try {
- client.execute(sql);
- } catch (Exception ex) {
- throw new SQLException(ex.toString());
- }
- return new HiveQueryResultSet(client);
+ return executeImmediate(sql);
}
/*
@@ -121,6 +143,36 @@ public class HivePreparedStatement imple
throw new SQLException("Method not supported");
}
+ /**
+ * Executes the SQL statement.
+ *
+ * @param sql The sql, as a string, to execute
+ * @return ResultSet
+ * @throws SQLException if the prepared statement is closed or there is a database error.
+ * caught Exceptions are thrown as SQLExceptions with the description
+ * "08S01".
+ */
+
+ protected ResultSet executeImmediate(String sql) throws SQLException {
+ if (isClosed) {
+ throw new SQLException("Can't execute after statement has been closed");
+ }
+
+ try {
+ clearWarnings();
+ resultSet = null;
+ client.execute(sql);
+ } catch (HiveServerException e) {
+ throw new SQLException(e.getMessage(), e.getSQLState(), e.getErrorCode());
+ } catch (Exception ex) {
+ throw new SQLException(ex.toString(), "08S01");
+ }
+ resultSet = new HiveQueryResultSet(client, maxRows);
+ return resultSet;
+ }
+
+
+
/*
* (non-Javadoc)
*
@@ -734,15 +786,19 @@ public class HivePreparedStatement imple
throw new SQLException("Method not supported");
}
- /*
- * (non-Javadoc)
- *
- * @see java.sql.Statement#close()
+ /**
+ * Closes the prepared statement.
+ *
+ * @throws
*/
public void close() throws SQLException {
- // TODO Auto-generated method stub
- throw new SQLException("Method not supported");
+ client = null;
+ if (resultSet!=null) {
+ resultSet.close();
+ resultSet = null;
+ }
+ isClosed = true;
}
/*