@Override public double plan() throws Exception { try{ final RecordingObserver recording = new RecordingObserver(); final AttemptObservers observers = AttemptObservers.of(observer, recording); observers.planStart(sql); plan = handler.getPlan(config.cloneWithNewObserver(observers), sql, sqlNode); PreparedPlan prepared = new PreparedPlan(context.getQueryId(), context.getQueryUserName(), sql, plan, recording); final Long handle = PREPARE_ID.getAndIncrement(); state = ServerPreparedStatementState.newBuilder() .setHandle(handle) .setSqlQuery(sql) .setPrepareId(context.getQueryId()) .build(); planCache.put(handle, prepared); // record a partial plan so that we can grab metadata and use it (for example during view creation of via sql). observers.planCompleted(new ExecutionPlan(plan, ImmutableList.of(), ImmutableList.of())); return 1; }catch(Exception ex){ throw SqlExceptionHelper.coerceException(logger, sql, ex, true); } }
final ServerPreparedStatementState preparedStatement = ServerPreparedStatementState.PARSER.parseFrom(query.getPreparedStatementHandle().getServerInfo()); if(preparedStatement.hasPrepareId()){ prepareId.value = preparedStatement.getPrepareId(); final long handle = preparedStatement.getHandle(); PreparedPlan plan = plans.getIfPresent(handle); if(plan != null){ Preconditions.checkArgument(plan.getQuery().equals(preparedStatement.getSqlQuery()), "Prepared statement's sql query doesn't match what sent when prepared statement was created."); if(plan.getUsername() != null){ return getSqlCommand(preparedStatement.getSqlQuery(), false);
public com.dremio.exec.proto.ExecProtos.ServerPreparedStatementState buildPartial() { com.dremio.exec.proto.ExecProtos.ServerPreparedStatementState result = new com.dremio.exec.proto.ExecProtos.ServerPreparedStatementState(this); int from_bitField0_ = bitField0_; int to_bitField0_ = 0; if (((from_bitField0_ & 0x00000001) == 0x00000001)) { to_bitField0_ |= 0x00000001; } result.sqlQuery_ = sqlQuery_; if (((from_bitField0_ & 0x00000002) == 0x00000002)) { to_bitField0_ |= 0x00000002; } result.handle_ = handle_; if (((from_bitField0_ & 0x00000004) == 0x00000004)) { to_bitField0_ |= 0x00000004; } if (prepareIdBuilder_ == null) { result.prepareId_ = prepareId_; } else { result.prepareId_ = prepareIdBuilder_.build(); } result.bitField0_ = to_bitField0_; onBuilt(); return result; }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.dremio.exec.proto.ExecProtos.ServerPreparedStatementState)) { return super.equals(obj); } com.dremio.exec.proto.ExecProtos.ServerPreparedStatementState other = (com.dremio.exec.proto.ExecProtos.ServerPreparedStatementState) obj; boolean result = true; result = result && (hasSqlQuery() == other.hasSqlQuery()); if (hasSqlQuery()) { result = result && getSqlQuery() .equals(other.getSqlQuery()); } result = result && (hasHandle() == other.hasHandle()); if (hasHandle()) { result = result && (getHandle() == other.getHandle()); } result = result && (hasPrepareId() == other.hasPrepareId()); if (hasPrepareId()) { result = result && getPrepareId() .equals(other.getPrepareId()); } result = result && getUnknownFields().equals(other.getUnknownFields()); return result; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptorForType().hashCode(); if (hasSqlQuery()) { hash = (37 * hash) + SQL_QUERY_FIELD_NUMBER; hash = (53 * hash) + getSqlQuery().hashCode(); } if (hasHandle()) { hash = (37 * hash) + HANDLE_FIELD_NUMBER; hash = (53 * hash) + hashLong(getHandle()); } if (hasPrepareId()) { hash = (37 * hash) + PREPARE_ID_FIELD_NUMBER; hash = (53 * hash) + getPrepareId().hashCode(); } hash = (29 * hash) + getUnknownFields().hashCode(); memoizedHashCode = hash; return hash; }
@Test public void invalidPrepareHandle() throws Exception { final ServerPreparedStatementState state = ServerPreparedStatementState.newBuilder() .setHandle(-23) // Handles start from 0 in the sever. This is relying on server implementation detail. May need to find a better way to test it. .setSqlQuery("SELECT sales_city, count(*) as cnt FROM cp.\"region.json\" " + "GROUP BY sales_city ORDER BY sales_city DESC LIMIT 2") .setPrepareId(QueryId.newBuilder().build()) .build(); PreparedStatement preparedStatement = PreparedStatement.newBuilder() .setServerHandle(PreparedStatementHandle.newBuilder().setServerInfo(state.toByteString()).build()) .build(); testBuilder() .unOrdered() .preparedStatement(preparedStatement.getServerHandle()) .baselineColumns("sales_city", "cnt") .baselineValues("Yakima", 1L) .baselineValues("Woodland Hills", 1L) .go(); }
public Builder toBuilder() { return newBuilder(this); }
public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder(com.dremio.exec.proto.ExecProtos.ServerPreparedStatementState prototype) {
public com.dremio.exec.proto.ExecProtos.ServerPreparedStatementState getDefaultInstanceForType() { return com.dremio.exec.proto.ExecProtos.ServerPreparedStatementState.getDefaultInstance(); }
public Builder mergeFrom(com.dremio.exec.proto.ExecProtos.ServerPreparedStatementState other) { if (other == com.dremio.exec.proto.ExecProtos.ServerPreparedStatementState.getDefaultInstance()) return this; if (other.hasSqlQuery()) { bitField0_ |= 0x00000001; sqlQuery_ = other.sqlQuery_; onChanged(); } if (other.hasHandle()) { setHandle(other.getHandle()); } if (other.hasPrepareId()) { mergePrepareId(other.getPrepareId()); } this.mergeUnknownFields(other.getUnknownFields()); return this; }
public static Builder newBuilder(com.dremio.exec.proto.ExecProtos.ServerPreparedStatementState prototype) { return newBuilder().mergeFrom(prototype); } public Builder toBuilder() { return newBuilder(this); }
public static CreatePreparedStatementResp build(BatchSchema schema, ServerPreparedStatementState handle, QueryId queryId, String catalogName) { final CreatePreparedStatementResp.Builder respBuilder = CreatePreparedStatementResp.newBuilder(); final PreparedStatement.Builder prepStmtBuilder = PreparedStatement.newBuilder(); prepStmtBuilder.setServerHandle(PreparedStatementHandle.newBuilder().setServerInfo(handle.toByteString())); for (Field field : schema) { prepStmtBuilder.addColumns(serializeColumn(field, catalogName)); } respBuilder.setStatus(RequestStatus.OK); respBuilder.setPreparedStatement(prepStmtBuilder.build()); respBuilder.setQueryId(queryId); return respBuilder.build(); }
@Override public CreatePreparedStatementResp execute() throws Exception { ServerPreparedStatementState state = ServerPreparedStatementState.newBuilder().setHandle(-1).setSqlQuery(sql).build(); return PreparedStatementProvider.build(schema, state, context.getQueryId(), context.getSession().getCatalogName()); }
private static String getSql(final RunQuery q) { if(q.getType() == QueryType.PREPARED_STATEMENT){ try{ final ServerPreparedStatementState preparedStatement = ServerPreparedStatementState.PARSER.parseFrom(q.getPreparedStatementHandle().getServerInfo()); return preparedStatement.getSqlQuery(); }catch(Exception ex){ throw UserException.connectionError(ex).message("Prepared statement provided is corrupt.").build(logger); } } else { return q.getPlan(); } }
public void writeTo(io.protostuff.Output output, com.dremio.exec.proto.ExecProtos.ServerPreparedStatementState message) throws java.io.IOException { if(message.hasSqlQuery()) output.writeString(1, message.getSqlQuery(), false); if(message.hasHandle()) output.writeInt64(2, message.getHandle(), false); if(message.hasPrepareId()) output.writeObject(3, message.getPrepareId(), com.dremio.exec.proto.SchemaUserBitShared.QueryId.WRITE, false); } public boolean isInitialized(com.dremio.exec.proto.ExecProtos.ServerPreparedStatementState message)
public com.dremio.exec.proto.ExecProtos.ServerPreparedStatementState.Builder newMessage() { return com.dremio.exec.proto.ExecProtos.ServerPreparedStatementState.newBuilder(); } public java.lang.String getFieldName(int number)
/** * <code>optional string sql_query = 1;</code> */ public Builder clearSqlQuery() { bitField0_ = (bitField0_ & ~0x00000001); sqlQuery_ = getDefaultInstance().getSqlQuery(); onChanged(); return this; } /**