use of org.apache.calcite.avatica.NoSuchStatementException in project calcite by apache.
the class CalciteStatement method prepare.
protected <T> CalcitePrepare.CalciteSignature<T> prepare(Queryable<T> queryable) {
final CalciteConnectionImpl calciteConnection = getConnection();
final CalcitePrepare prepare = calciteConnection.prepareFactory.apply();
final CalciteServerStatement serverStatement;
try {
serverStatement = calciteConnection.server.getStatement(handle);
} catch (NoSuchStatementException e) {
throw new AssertionError("invalid statement", e);
}
final CalcitePrepare.Context prepareContext = serverStatement.createPrepareContext();
return prepare.prepareQueryable(prepareContext, queryable);
}
use of org.apache.calcite.avatica.NoSuchStatementException in project druid by druid-io.
the class DruidMeta method prepareAndExecute.
@Override
public ExecuteResult prepareAndExecute(final StatementHandle statement, final String sql, final long maxRowCount, final int maxRowsInFirstFrame, final PrepareCallback callback) throws NoSuchStatementException {
try {
// Ignore "callback", this class is designed for use with LocalService which doesn't use it.
final DruidStatement druidStatement = getDruidStatement(statement);
final DruidConnection druidConnection = getDruidConnection(statement.connectionId);
AuthenticationResult authenticationResult = authenticateConnection(druidConnection);
if (authenticationResult == null) {
throw logFailure(new ForbiddenException("Authentication failed."), "Authentication failed for statement[%s]", druidStatement.getStatementId());
}
druidStatement.prepare(sql, maxRowCount, authenticationResult);
final Frame firstFrame = druidStatement.execute(Collections.emptyList()).nextFrame(DruidStatement.START_OFFSET, getEffectiveMaxRowsPerFrame(maxRowsInFirstFrame));
final Signature signature = druidStatement.getSignature();
LOG.debug("Successfully prepared statement[%s] and started execution", druidStatement.getStatementId());
return new ExecuteResult(ImmutableList.of(MetaResultSet.create(statement.connectionId, statement.id, false, signature, firstFrame)));
}// cannot affect these exceptions as avatica handles them
catch (NoSuchConnectionException | NoSuchStatementException e) {
throw e;
} catch (Throwable t) {
throw errorHandler.sanitize(t);
}
}
use of org.apache.calcite.avatica.NoSuchStatementException in project druid by druid-io.
the class DruidMeta method syncResults.
@Override
public boolean syncResults(final StatementHandle sh, final QueryState state, final long offset) throws NoSuchStatementException {
try {
final DruidStatement druidStatement = getDruidStatement(sh);
final boolean isDone = druidStatement.isDone();
final long currentOffset = druidStatement.getCurrentOffset();
if (currentOffset != offset) {
throw logFailure(new ISE("Requested offset[%,d] does not match currentOffset[%,d]", offset, currentOffset));
}
return !isDone;
} catch (NoSuchStatementException | NoSuchConnectionException e) {
throw e;
} catch (Throwable t) {
throw errorHandler.sanitize(t);
}
}
use of org.apache.calcite.avatica.NoSuchStatementException in project calcite-avatica by apache.
the class JdbcMeta method prepareAndExecute.
public ExecuteResult prepareAndExecute(StatementHandle h, String sql, long maxRowCount, int maxRowsInFirstFrame, PrepareCallback callback) throws NoSuchStatementException {
try {
final StatementInfo info = getStatementCache().getIfPresent(h.id);
if (info == null) {
throw new NoSuchStatementException(h);
}
final Statement statement = info.statement;
// Make sure that we limit the number of rows for the query
setMaxRows(statement, maxRowCount);
boolean ret = statement.execute(sql);
info.setResultSet(statement.getResultSet());
// Either execute(sql) returned true or the resultSet was null
assert ret || null == info.getResultSet();
final List<MetaResultSet> resultSets = new ArrayList<>();
if (null == info.getResultSet()) {
// Create a special result set that just carries update count
resultSets.add(JdbcResultSet.count(h.connectionId, h.id, AvaticaUtils.getLargeUpdateCount(statement)));
} else {
resultSets.add(JdbcResultSet.create(h.connectionId, h.id, info.getResultSet(), maxRowsInFirstFrame));
}
LOG.trace("prepAndExec statement {}", h);
// TODO: review client to ensure statementId is updated when appropriate
return new ExecuteResult(resultSets);
} catch (SQLException e) {
throw propagate(e);
}
}
use of org.apache.calcite.avatica.NoSuchStatementException in project calcite-avatica by apache.
the class JdbcMeta method executeBatch.
@Override
public ExecuteBatchResult executeBatch(StatementHandle h, List<List<TypedValue>> updateBatches) throws NoSuchStatementException {
try {
final StatementInfo info = statementCache.getIfPresent(h.id);
if (null == info) {
throw new NoSuchStatementException(h);
}
final PreparedStatement preparedStmt = (PreparedStatement) info.statement;
int rowUpdate = 1;
for (List<TypedValue> batch : updateBatches) {
int i = 1;
for (TypedValue value : batch) {
// Set the TypedValue in the PreparedStatement
try {
preparedStmt.setObject(i, value.toJdbc(calendar));
i++;
} catch (SQLException e) {
throw new RuntimeException("Failed to set value on row #" + rowUpdate + " and column #" + i, e);
}
// Track the update number for better error messages
rowUpdate++;
}
preparedStmt.addBatch();
}
return new ExecuteBatchResult(AvaticaUtils.executeLargeBatch(preparedStmt));
} catch (SQLException e) {
throw propagate(e);
}
}
Aggregations