use of org.apache.calcite.jdbc.CalcitePrepare.Context in project calcite by apache.
the class CalciteMetaImpl method prepare.
@Override
public StatementHandle prepare(ConnectionHandle ch, String sql, long maxRowCount) {
final StatementHandle h = createStatement(ch);
final CalciteConnectionImpl calciteConnection = getConnection();
final CalciteServerStatement statement;
try {
statement = calciteConnection.server.getStatement(h);
} catch (NoSuchStatementException e) {
// Not possible. We just created a statement.
throw new AssertionError("missing statement", e);
}
final Context context = statement.createPrepareContext();
final CalcitePrepare.Query<Object> query = toQuery(context, sql);
h.signature = calciteConnection.parseQuery(query, context, maxRowCount);
statement.setSignature(h.signature);
return h;
}
use of org.apache.calcite.jdbc.CalcitePrepare.Context in project calcite by apache.
the class CalciteMetaImpl method prepareAndExecute.
@Override
public ExecuteResult prepareAndExecute(StatementHandle h, String sql, long maxRowCount, int maxRowsInFirstFrame, PrepareCallback callback) throws NoSuchStatementException {
final CalcitePrepare.CalciteSignature<Object> signature;
try {
synchronized (callback.getMonitor()) {
callback.clear();
final CalciteConnectionImpl calciteConnection = getConnection();
final CalciteServerStatement statement = calciteConnection.server.getStatement(h);
final Context context = statement.createPrepareContext();
final CalcitePrepare.Query<Object> query = toQuery(context, sql);
signature = calciteConnection.parseQuery(query, context, maxRowCount);
statement.setSignature(signature);
final int updateCount;
switch(signature.statementType) {
case CREATE:
case DROP:
case ALTER:
case OTHER_DDL:
// DDL produces no result set
updateCount = 0;
break;
default:
// SELECT and DML produces result set
updateCount = -1;
break;
}
callback.assign(signature, null, updateCount);
}
callback.execute();
final MetaResultSet metaResultSet = MetaResultSet.create(h.connectionId, h.id, false, signature, null);
return new ExecuteResult(ImmutableList.of(metaResultSet));
} catch (SQLException e) {
throw new RuntimeException(e);
}
// TODO: share code with prepare and createIterable
}
Aggregations