Search in sources :

Example 1 with SQLFeatureNotSupportedException

use of java.sql.SQLFeatureNotSupportedException in project hive by apache.

the class HiveQueryResultSet method next.

/**
   * Moves the cursor down one row from its current position.
   *
   * @see java.sql.ResultSet#next()
   * @throws SQLException
   *           if a database access error occurs.
   */
public boolean next() throws SQLException {
    if (isClosed) {
        throw new SQLException("Resultset is closed");
    }
    if (emptyResultSet || (maxRows > 0 && rowsFetched >= maxRows)) {
        return false;
    }
    /**
     * 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 HiveStatement)) {
        ((HiveStatement) statement).waitForOperationToComplete();
    }
    try {
        TFetchOrientation orientation = TFetchOrientation.FETCH_NEXT;
        if (fetchFirst) {
            // If we are asked to start from begining, clear the current fetched resultset
            orientation = TFetchOrientation.FETCH_FIRST;
            fetchedRows = null;
            fetchedRowsItr = null;
            fetchFirst = false;
        }
        if (fetchedRows == null || !fetchedRowsItr.hasNext()) {
            TFetchResultsReq fetchReq = new TFetchResultsReq(stmtHandle, orientation, fetchSize);
            TFetchResultsResp fetchResp;
            fetchResp = client.FetchResults(fetchReq);
            Utils.verifySuccessWithInfo(fetchResp.getStatus());
            TRowSet results = fetchResp.getResults();
            fetchedRows = RowSetFactory.create(results, protocol);
            fetchedRowsItr = fetchedRows.iterator();
        }
        if (fetchedRowsItr.hasNext()) {
            row = fetchedRowsItr.next();
        } else {
            return false;
        }
        rowsFetched++;
    } catch (SQLException eS) {
        throw eS;
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new SQLException("Error retrieving next row", ex);
    }
    // NOTE: fetchOne doesn't throw new SQLFeatureNotSupportedException("Method not supported").
    return true;
}
Also used : TRowSet(org.apache.hive.service.rpc.thrift.TRowSet) SQLException(java.sql.SQLException) TFetchResultsResp(org.apache.hive.service.rpc.thrift.TFetchResultsResp) TFetchOrientation(org.apache.hive.service.rpc.thrift.TFetchOrientation) TFetchResultsReq(org.apache.hive.service.rpc.thrift.TFetchResultsReq) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException)

Example 2 with SQLFeatureNotSupportedException

use of java.sql.SQLFeatureNotSupportedException in project cobar by alibaba.

the class ServerRouter method validateAST.

private static void validateAST(SQLStatement ast, TableConfig tc, RuleConfig rule, PartitionKeyVisitor visitor) throws SQLNonTransientException {
    if (ast instanceof DMLUpdateStatement) {
        List<Identifier> columns = null;
        List<String> ruleCols = rule.getColumns();
        DMLUpdateStatement update = (DMLUpdateStatement) ast;
        for (Pair<Identifier, Expression> pair : update.getValues()) {
            for (String ruleCol : ruleCols) {
                if (equals(pair.getKey().getIdTextUpUnescape(), ruleCol)) {
                    if (columns == null) {
                        columns = new ArrayList<Identifier>(ruleCols.size());
                    }
                    columns.add(pair.getKey());
                }
            }
        }
        if (columns == null) {
            return;
        }
        Map<String, String> alias = visitor.getTableAlias();
        for (Identifier column : columns) {
            String table = column.getLevelUnescapeUpName(2);
            table = alias.get(table);
            if (table != null && table.equals(tc.getName())) {
                throw new SQLFeatureNotSupportedException("partition key cannot be changed");
            }
        }
    }
}
Also used : Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier) Expression(com.alibaba.cobar.parser.ast.expression.Expression) ReplacableExpression(com.alibaba.cobar.parser.ast.expression.ReplacableExpression) RowExpression(com.alibaba.cobar.parser.ast.expression.primary.RowExpression) InExpression(com.alibaba.cobar.parser.ast.expression.comparison.InExpression) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) DMLUpdateStatement(com.alibaba.cobar.parser.ast.stmt.dml.DMLUpdateStatement)

Example 3 with SQLFeatureNotSupportedException

use of java.sql.SQLFeatureNotSupportedException in project druid by alibaba.

the class DruidPooledCallableStatementTest method test_getObject_1.

public void test_getObject_1() throws Exception {
    Connection conn = dataSource.getConnection();
    DruidPooledCallableStatement stmt = (DruidPooledCallableStatement) conn.prepareCall("select 1");
    stmt.execute();
    Assert.assertEquals(0, dataSource.getErrorCount());
    Exception error = null;
    try {
        stmt.getObject("1", String.class);
    } catch (SQLFeatureNotSupportedException e) {
        error = e;
    }
    Assert.assertNotNull(error);
    Assert.assertEquals(0, dataSource.getErrorCount());
    stmt.close();
    conn.close();
    Assert.assertEquals(1, dataSource.getPoolingCount());
}
Also used : DruidPooledCallableStatement(com.alibaba.druid.pool.DruidPooledCallableStatement) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) Connection(java.sql.Connection) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException)

Example 4 with SQLFeatureNotSupportedException

use of java.sql.SQLFeatureNotSupportedException in project druid by alibaba.

the class DruidPooledResultSetTest method test_notSupport_1.

public void test_notSupport_1() throws Exception {
    String sql = "select ?";
    Connection conn = dataSource.getConnection();
    PreparedStatement stmt = conn.prepareStatement(sql);
    stmt.setString(1, "xxx");
    DruidPooledResultSet rs = (DruidPooledResultSet) stmt.executeQuery();
    Exception error = null;
    try {
        rs.getObject("1", String.class);
    } catch (SQLFeatureNotSupportedException e) {
        error = e;
    }
    Assert.assertNotNull(error);
    rs.close();
    conn.close();
}
Also used : SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) DruidPooledResultSet(com.alibaba.druid.pool.DruidPooledResultSet) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException)

Example 5 with SQLFeatureNotSupportedException

use of java.sql.SQLFeatureNotSupportedException in project druid by alibaba.

the class DruidPooledResultSetTest method test_notSupport.

public void test_notSupport() throws Exception {
    String sql = "select ?";
    Connection conn = dataSource.getConnection();
    PreparedStatement stmt = conn.prepareStatement(sql);
    stmt.setString(1, "xxx");
    DruidPooledResultSet rs = (DruidPooledResultSet) stmt.executeQuery();
    Exception error = null;
    try {
        rs.getObject(1, String.class);
    } catch (SQLFeatureNotSupportedException e) {
        error = e;
    }
    Assert.assertNotNull(error);
    rs.close();
    conn.close();
}
Also used : SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) DruidPooledResultSet(com.alibaba.druid.pool.DruidPooledResultSet) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException)

Aggregations

SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)55 SQLException (java.sql.SQLException)20 Connection (java.sql.Connection)14 Test (org.testng.annotations.Test)14 BaseTest (util.BaseTest)14 PreparedStatement (java.sql.PreparedStatement)13 Statement (java.sql.Statement)11 ResultSet (java.sql.ResultSet)10 Test (org.junit.Test)5 Properties (java.util.Properties)4 CallableStatement (java.sql.CallableStatement)3 DruidPooledCallableStatement (com.alibaba.druid.pool.DruidPooledCallableStatement)2 DruidPooledResultSet (com.alibaba.druid.pool.DruidPooledResultSet)2 DruidPooledStatement (com.alibaba.druid.pool.DruidPooledStatement)2 Date (java.sql.Date)2 SQLDataException (java.sql.SQLDataException)2 Savepoint (java.sql.Savepoint)2 Vector (java.util.Vector)2 ColumnInfo (org.apache.jena.jdbc.results.metadata.columns.ColumnInfo)2 SparqlColumnInfo (org.apache.jena.jdbc.results.metadata.columns.SparqlColumnInfo)2