org.apache.hive.jdbc

## Class HiveStatement

- java.lang.Object
- - org.apache.hive.jdbc.HiveStatement

All Implemented Interfaces:
  AutoCloseable, Statement, Wrapper

Direct Known Subclasses:
  HivePreparedStatement

    public class HiveStatement
    extends Object
    implements Statement

The object used for executing a static SQL statement and returning the results it produces.

### Field Summary

Fields
`static String` `QUERY_CANCELLED_MESSAGE`

### Fields inherited from interface java.sql.Statement

`CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO`

### Constructor Summary

Constructors
Constructor and Description
`HiveStatement(HiveConnection connection, TCLIService.Iface client, TSessionHandle sessHandle)`
`HiveStatement(HiveConnection connection, TCLIService.Iface client, TSessionHandle sessHandle, boolean isScrollableResultset, int initFetchSize, int defaultFetchSize)`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addBatch(String sql)`
`void` `cancel()`
`void` `clearBatch()`
`void` `clearWarnings()`
`void` `close()`
`void` `closeOnCompletion()`
`boolean` `execute(String sql)`
`boolean` `execute(String sql, int autoGeneratedKeys)`
`boolean` `execute(String sql, int[] columnIndexes)`
`boolean` `execute(String sql, String[] columnNames)`
`boolean` `executeAsync(String sql)` Starts the query execution asynchronously on the server, and immediately returns to the client.
`int[]` `executeBatch()`
`ResultSet` `executeQuery(String sql)`
`int` `executeUpdate(String sql)`
`int` `executeUpdate(String sql, int autoGeneratedKeys)`
`int` `executeUpdate(String sql, int[] columnIndexes)`
`int` `executeUpdate(String sql, String[] columnNames)`
`Connection` `getConnection()`
`int` `getFetchDirection()`
`int` `getFetchSize()`
`ResultSet` `getGeneratedKeys()`
`int` `getMaxFieldSize()`
`int` `getMaxRows()`
`boolean` `getMoreResults()`
`boolean` `getMoreResults(int current)`
`String` `getQueryId()` Returns the Query ID if it is running.
`List<String>` `getQueryLog()` Get the execution logs of the given SQL statement.
`List<String>` `getQueryLog(boolean incremental, int fetchSize)` Get the execution logs of the given SQL statement.
`int` `getQueryTimeout()`
`ResultSet` `getResultSet()`
`int` `getResultSetConcurrency()`
`int` `getResultSetHoldability()`
`int` `getResultSetType()`
`int` `getUpdateCount()`
`SQLWarning` `getWarnings()`
`String` `getYarnATSGuid()` Returns the Yarn ATS GUID.
`boolean` `hasMoreLogs()` Check whether query execution might be producing more logs to be fetched.
`boolean` `isClosed()`
`boolean` `isCloseOnCompletion()`
`boolean` `isPoolable()`
`boolean` `isQueryClosed()`
`boolean` `isWrapperFor(Class<?> iface)`
`void` `setCursorName(String name)`
`void` `setEscapeProcessing(boolean enable)`
`void` `setFetchDirection(int direction)`
`void` `setFetchSize(int rows)`
`void` `setInPlaceUpdateStream(InPlaceUpdateStream stream)` This is only used by the beeline client to set the stream on which in place progress updates are to be shown.
`void` `setMaxFieldSize(int max)`
`void` `setMaxRows(int max)`
`void` `setPoolable(boolean poolable)`
`void` `setQueryTimeout(int seconds)`
`<T> T` `unwrap(Class<T> iface)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface java.sql.Statement

`executeLargeBatch, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, getLargeMaxRows, getLargeUpdateCount, setLargeMaxRows`

### Field Detail

#### QUERY_CANCELLED_MESSAGE

    public static final String QUERY_CANCELLED_MESSAGE

See Also:
  Constant Field Values

### Constructor Detail

#### HiveStatement

    public HiveStatement(HiveConnection connection,
                         TCLIService.Iface client,
                         TSessionHandle sessHandle)

#### HiveStatement

    public HiveStatement(HiveConnection connection,
                         TCLIService.Iface client,
                         TSessionHandle sessHandle,
                         boolean isScrollableResultset,
                         int initFetchSize,
                         int defaultFetchSize)

### Method Detail

#### addBatch

    public void addBatch(String sql)
                  throws SQLException

Specified by:
  `addBatch` in interface `Statement`
Throws:
  `SQLException`

#### cancel

    public void cancel()
                throws SQLException

Specified by:
  `cancel` in interface `Statement`
Throws:
  `SQLException`

#### clearBatch

    public void clearBatch()
                    throws SQLException

Specified by:
  `clearBatch` in interface `Statement`
Throws:
  `SQLException`

#### clearWarnings

    public void clearWarnings()
                       throws SQLException

Specified by:
  `clearWarnings` in interface `Statement`
Throws:
  `SQLException`

#### close

    public void close()
               throws SQLException

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Statement`
Throws:
  `SQLException`

#### closeOnCompletion

    public void closeOnCompletion()
                           throws SQLException

Specified by:
  `closeOnCompletion` in interface `Statement`
Throws:
  `SQLException`

#### execute

    public boolean execute(String sql)
                    throws SQLException

Specified by:
  `execute` in interface `Statement`
Throws:
  `SQLException`

#### executeAsync

    public boolean executeAsync(String sql)
                         throws SQLException

Starts the query execution asynchronously on the server, and immediately returns to the client. The client subsequently blocks on ResultSet#next or Statement#getUpdateCount, depending on the 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.

Parameters:
  `sql` -
Returns:
  true if the first result is a ResultSet object; false if it is an update count or there are no results
Throws:
  `SQLException`

#### execute

    public boolean execute(String sql,
                           int autoGeneratedKeys)
                    throws SQLException

Specified by:
  `execute` in interface `Statement`
Throws:
  `SQLException`

#### execute

    public boolean execute(String sql,
                           int[] columnIndexes)
                    throws SQLException

Specified by:
  `execute` in interface `Statement`
Throws:
  `SQLException`

#### execute

    public boolean execute(String sql,
                           String[] columnNames)
                    throws SQLException

Specified by:
  `execute` in interface `Statement`
Throws:
  `SQLException`

#### executeBatch

    public int[] executeBatch()
                       throws SQLException

Specified by:
  `executeBatch` in interface `Statement`
Throws:
  `SQLException`

#### executeQuery

    public ResultSet executeQuery(String sql)
                           throws SQLException

Specified by:
  `executeQuery` in interface `Statement`
Throws:
  `SQLException`

#### executeUpdate

    public int executeUpdate(String sql)
                      throws SQLException

Specified by:
  `executeUpdate` in interface `Statement`
Throws:
  `SQLException`

#### executeUpdate

    public int executeUpdate(String sql,
                             int autoGeneratedKeys)
                      throws SQLException

Specified by:
  `executeUpdate` in interface `Statement`
Throws:
  `SQLException`

#### executeUpdate

    public int executeUpdate(String sql,
                             int[] columnIndexes)
                      throws SQLException

Specified by:
  `executeUpdate` in interface `Statement`
Throws:
  `SQLException`

#### executeUpdate

    public int executeUpdate(String sql,
                             String[] columnNames)
                      throws SQLException

Specified by:
  `executeUpdate` in interface `Statement`
Throws:
  `SQLException`

#### getConnection

    public Connection getConnection()
                             throws SQLException

Specified by:
  `getConnection` in interface `Statement`
Throws:
  `SQLException`

#### getFetchDirection

    public int getFetchDirection()
                          throws SQLException

Specified by:
  `getFetchDirection` in interface `Statement`
Throws:
  `SQLException`

#### getFetchSize

    public int getFetchSize()
                     throws SQLException

Specified by:
  `getFetchSize` in interface `Statement`
Throws:
  `SQLException`

#### getGeneratedKeys

    public ResultSet getGeneratedKeys()
                               throws SQLException

Specified by:
  `getGeneratedKeys` in interface `Statement`
Throws:
  `SQLException`

#### getMaxFieldSize

    public int getMaxFieldSize()
                        throws SQLException

Specified by:
  `getMaxFieldSize` in interface `Statement`
Throws:
  `SQLException`

#### getMaxRows

    public int getMaxRows()
                   throws SQLException

Specified by:
  `getMaxRows` in interface `Statement`
Throws:
  `SQLException`

#### getMoreResults

    public boolean getMoreResults()
                           throws SQLException

Specified by:
  `getMoreResults` in interface `Statement`
Throws:
  `SQLException`

#### getMoreResults

    public boolean getMoreResults(int current)
                           throws SQLException

Specified by:
  `getMoreResults` in interface `Statement`
Throws:
  `SQLException`

#### getQueryTimeout

    public int getQueryTimeout()
                        throws SQLException

Specified by:
  `getQueryTimeout` in interface `Statement`
Throws:
  `SQLException`

#### getResultSet

    public ResultSet getResultSet()
                           throws SQLException

Specified by:
  `getResultSet` in interface `Statement`
Throws:
  `SQLException`

#### getResultSetConcurrency

    public int getResultSetConcurrency()
                                throws SQLException

Specified by:
  `getResultSetConcurrency` in interface `Statement`
Throws:
  `SQLException`

#### getResultSetHoldability

    public int getResultSetHoldability()
                                throws SQLException

Specified by:
  `getResultSetHoldability` in interface `Statement`
Throws:
  `SQLException`

#### getResultSetType

    public int getResultSetType()
                         throws SQLException

Specified by:
  `getResultSetType` in interface `Statement`
Throws:
  `SQLException`

#### getUpdateCount

    public int getUpdateCount()
                       throws SQLException

Specified by:
  `getUpdateCount` in interface `Statement`
Throws:
  `SQLException`

#### getWarnings

    public SQLWarning getWarnings()
                           throws SQLException

Specified by:
  `getWarnings` in interface `Statement`
Throws:
  `SQLException`

#### isClosed

    public boolean isClosed()
                     throws SQLException

Specified by:
  `isClosed` in interface `Statement`
Throws:
  `SQLException`

#### isQueryClosed

    public boolean isQueryClosed()
                          throws SQLException

Throws:
  `SQLException`

#### isCloseOnCompletion

    public boolean isCloseOnCompletion()
                                throws SQLException

Specified by:
  `isCloseOnCompletion` in interface `Statement`
Throws:
  `SQLException`

#### isPoolable

    public boolean isPoolable()
                       throws SQLException

Specified by:
  `isPoolable` in interface `Statement`
Throws:
  `SQLException`

#### setCursorName

    public void setCursorName(String name)
                       throws SQLException

Specified by:
  `setCursorName` in interface `Statement`
Throws:
  `SQLException`

#### setEscapeProcessing

    public void setEscapeProcessing(boolean enable)
                             throws SQLException

Specified by:
  `setEscapeProcessing` in interface `Statement`
Throws:
  `SQLException`

#### setFetchDirection

    public void setFetchDirection(int direction)
                           throws SQLException

Specified by:
  `setFetchDirection` in interface `Statement`
Throws:
  `SQLException`

#### setFetchSize

    public void setFetchSize(int rows)
                      throws SQLException

Specified by:
  `setFetchSize` in interface `Statement`
Throws:
  `SQLException`

#### setMaxFieldSize

    public void setMaxFieldSize(int max)
                         throws SQLException

Specified by:
  `setMaxFieldSize` in interface `Statement`
Throws:
  `SQLException`

#### setMaxRows

    public void setMaxRows(int max)
                    throws SQLException

Specified by:
  `setMaxRows` in interface `Statement`
Throws:
  `SQLException`

#### setPoolable

    public void setPoolable(boolean poolable)
                     throws SQLException

Specified by:
  `setPoolable` in interface `Statement`
Throws:
  `SQLException`

#### setQueryTimeout

    public void setQueryTimeout(int seconds)
                         throws SQLException

Specified by:
  `setQueryTimeout` in interface `Statement`
Throws:
  `SQLException`

#### isWrapperFor

    public boolean isWrapperFor(Class<?> iface)
                         throws SQLException

Specified by:
  `isWrapperFor` in interface `Wrapper`
Throws:
  `SQLException`

#### unwrap

    public <T> T unwrap(Class<T> iface)
                 throws SQLException

Specified by:
  `unwrap` in interface `Wrapper`
Throws:
  `SQLException`

#### hasMoreLogs

    public boolean hasMoreLogs()

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.

Returns:
  true if query execution might be producing more logs. It does not indicate if last log lines have been fetched by getQueryLog.

#### getQueryLog

    public List<String> getQueryLog()
                             throws SQLException,
                                    ClosedOrCancelledStatementException

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.

Returns:
  a list of logs. It can be empty if there are no new logs to be retrieved at that time.
Throws:
  `SQLException`
  `ClosedOrCancelledStatementException` - if statement has been cancelled or closed

#### getQueryLog

    public List<String> getQueryLog(boolean incremental,
                                    int fetchSize)
                             throws SQLException,
                                    ClosedOrCancelledStatementException

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.

Parameters:
  `incremental` - indicate getting logs either incrementally or from the beginning, when it is true or false.
  `fetchSize` - the number of lines to fetch
Returns:
  a list of logs. It can be empty if there are no new logs to be retrieved at that time.
Throws:
  `SQLException`
  `ClosedOrCancelledStatementException` - if statement has been cancelled or closed

#### getYarnATSGuid

    public String getYarnATSGuid()

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:
  Yarn ATS GUID or null if it hasn't been created yet.

#### setInPlaceUpdateStream

    public void setInPlaceUpdateStream(InPlaceUpdateStream stream)

This is only used by the beeline client to set the stream on which in place progress updates are to be shown.

#### getQueryId

    @InterfaceAudience.LimitedPrivate(value="Hive and closely related projects.")
    public String getQueryId()
                                                                                                    throws SQLException

Returns the Query ID if it is running. This method is a public API for usage outside of Hive, although it is not part of the interface java.sql.Statement.

Returns:
  Valid query ID if it is running else returns NULL.
Throws:
  `SQLException` - If any internal failures.