connection.getClient().executePreparedStatement(preparedStatement.getServerHandle(), resultsListener); } else { connection.getClient().runQuery(QueryType.SQL, signature.sql, resultsListener);
/** * Create a prepared statement for a query that joins two tables and has ORDER BY clause. */ @Test public void joinOrderByQuery() throws Exception { String query = "SELECT l.l_quantity, l.l_shipdate, o.o_custkey FROM cp.\"tpch/lineitem.parquet\" l JOIN cp.\"tpch/orders.parquet\" o " + "ON l.l_orderkey = o.o_orderkey LIMIT 2"; PreparedStatement preparedStatement = createPrepareStmt(query, false, null); List<ExpectedColumnResult> expMetadata = ImmutableList.of( new ExpectedColumnResult("l_quantity", "DOUBLE", true, 24, 0, 0, true, Double.class.getName()), new ExpectedColumnResult("l_shipdate", "DATE", true, 10, 0, 0, false, Date.class.getName()), new ExpectedColumnResult("o_custkey", "INTEGER", true, 11, 0, 0, true, Integer.class.getName()) ); verifyMetadata(expMetadata, preparedStatement.getColumnsList()); }
public com.dremio.exec.proto.UserProtos.PreparedStatement buildPartial() { com.dremio.exec.proto.UserProtos.PreparedStatement result = new com.dremio.exec.proto.UserProtos.PreparedStatement(this); int from_bitField0_ = bitField0_; int to_bitField0_ = 0; if (columnsBuilder_ == null) { if (((bitField0_ & 0x00000001) == 0x00000001)) { columns_ = java.util.Collections.unmodifiableList(columns_); bitField0_ = (bitField0_ & ~0x00000001); } result.columns_ = columns_; } else { result.columns_ = columnsBuilder_.build(); } if (((from_bitField0_ & 0x00000002) == 0x00000002)) { to_bitField0_ |= 0x00000001; } if (serverHandleBuilder_ == null) { result.serverHandle_ = serverHandle_; } else { result.serverHandle_ = serverHandleBuilder_.build(); } result.bitField0_ = to_bitField0_; onBuilt(); return result; }
rpc.executePreparedStatement(resp.getPreparedStatement().getServerHandle(), new UserResultsListener() {
public Builder mergeFrom(com.dremio.exec.proto.UserProtos.PreparedStatement other) { if (other == com.dremio.exec.proto.UserProtos.PreparedStatement.getDefaultInstance()) return this; if (columnsBuilder_ == null) { if (!other.columns_.isEmpty()) { if (other.hasServerHandle()) { mergeServerHandle(other.getServerHandle()); this.mergeUnknownFields(other.getUnknownFields()); return this;
public void mergeFrom(io.protostuff.Input input, com.dremio.exec.proto.UserProtos.CreatePreparedStatementResp.Builder builder) throws java.io.IOException { for(int number = input.readFieldNumber(this);; number = input.readFieldNumber(this)) { switch(number) { case 0: return; case 1: builder.setStatus(com.dremio.exec.proto.UserProtos.RequestStatus.valueOf(input.readEnum())); break; case 2: builder.setPreparedStatement(input.mergeObject(com.dremio.exec.proto.UserProtos.PreparedStatement.newBuilder(), com.dremio.exec.proto.SchemaUserProtos.PreparedStatement.MERGE)); break; case 3: builder.setError(input.mergeObject(com.dremio.exec.proto.UserBitShared.DremioPBError.newBuilder(), com.dremio.exec.proto.SchemaUserBitShared.DremioPBError.MERGE)); break; case 13: builder.setQueryId(input.mergeObject(com.dremio.exec.proto.UserBitShared.QueryId.newBuilder(), com.dremio.exec.proto.SchemaUserBitShared.QueryId.MERGE)); break; default: input.handleUnknownField(number, this); } } } public boolean isInitialized(com.dremio.exec.proto.UserProtos.CreatePreparedStatementResp.Builder builder)
/** * Simple query. * @throws Exception */ @Test public void simple() throws Exception { String query = "SELECT * FROM cp.\"region.json\" ORDER BY region_id LIMIT 1"; PreparedStatement preparedStatement = createPrepareStmt(query, false, null); List<ExpectedColumnResult> expMetadata = ImmutableList.of( new ExpectedColumnResult("region_id", "BIGINT", true, 20, 0, 0, true, Long.class.getName()), new ExpectedColumnResult("sales_city", "CHARACTER VARYING", true, 65536, 65536, 0, false, String.class.getName()), new ExpectedColumnResult("sales_state_province", "CHARACTER VARYING", true, 65536, 65536, 0, false, String.class.getName()), new ExpectedColumnResult("sales_district", "CHARACTER VARYING", true, 65536, 65536, 0, false, String.class.getName()), new ExpectedColumnResult("sales_region", "CHARACTER VARYING", true, 65536, 65536, 0, false, String.class.getName()), new ExpectedColumnResult("sales_country", "CHARACTER VARYING", true, 65536, 65536, 0, false, String.class.getName()), new ExpectedColumnResult("sales_district_id", "BIGINT", true, 20, 0, 0, true, Long.class.getName()) ); verifyMetadata(expMetadata, preparedStatement.getColumnsList()); testBuilder() .unOrdered() .preparedStatement(preparedStatement.getServerHandle()) .baselineColumns("region_id", "sales_city", "sales_state_province", "sales_district", "sales_region", "sales_country", "sales_district_id") .baselineValues(0L, "None", "None", "No District", "No Region", "No Country", 0L) .go(); }
public Builder clear() { super.clear(); status_ = com.dremio.exec.proto.UserProtos.RequestStatus.UNKNOWN_STATUS; bitField0_ = (bitField0_ & ~0x00000001); if (preparedStatementBuilder_ == null) { preparedStatement_ = com.dremio.exec.proto.UserProtos.PreparedStatement.getDefaultInstance(); } else { preparedStatementBuilder_.clear(); } bitField0_ = (bitField0_ & ~0x00000002); if (errorBuilder_ == null) { error_ = com.dremio.exec.proto.UserBitShared.DremioPBError.getDefaultInstance(); } else { errorBuilder_.clear(); } bitField0_ = (bitField0_ & ~0x00000004); if (queryIdBuilder_ == null) { queryId_ = com.dremio.exec.proto.UserBitShared.QueryId.getDefaultInstance(); } else { queryIdBuilder_.clear(); } bitField0_ = (bitField0_ & ~0x00000008); return this; }
@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(); }
/** * Create a prepared statement for a query that has GROUP BY clause in it */ @Test public void groupByQuery() throws Exception { String query = "SELECT sales_city, count(*) as cnt FROM cp.\"region.json\" " + "GROUP BY sales_city ORDER BY sales_city DESC LIMIT 1"; PreparedStatement preparedStatement = createPrepareStmt(query, false, null); List<ExpectedColumnResult> expMetadata = ImmutableList.of( new ExpectedColumnResult("sales_city", "CHARACTER VARYING", true, 65536, 65536, 0, false, String.class.getName()), new ExpectedColumnResult("cnt", "BIGINT", true, 20, 0, 0, true, Long.class.getName()) ); verifyMetadata(expMetadata, preparedStatement.getColumnsList()); testBuilder() .unOrdered() .preparedStatement(preparedStatement.getServerHandle()) .baselineColumns("sales_city", "cnt") .baselineValues("Yakima", 1L) .go(); }
/** * <code>optional .exec.user.PreparedStatement prepared_statement = 2;</code> */ public Builder mergePreparedStatement(com.dremio.exec.proto.UserProtos.PreparedStatement value) { if (preparedStatementBuilder_ == null) { if (((bitField0_ & 0x00000002) == 0x00000002) && preparedStatement_ != com.dremio.exec.proto.UserProtos.PreparedStatement.getDefaultInstance()) { preparedStatement_ = com.dremio.exec.proto.UserProtos.PreparedStatement.newBuilder(preparedStatement_).mergeFrom(value).buildPartial(); } else { preparedStatement_ = value; } onChanged(); } else { preparedStatementBuilder_.mergeFrom(value); } bitField0_ |= 0x00000002; return this; } /**
public int getSerializedSize() { int size = memoizedSerializedSize; if (size != -1) return size; size = 0; for (int i = 0; i < columns_.size(); i++) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(1, columns_.get(i)); } if (((bitField0_ & 0x00000001) == 0x00000001)) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(2, serverHandle_); } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; return size; }
protected DremioPreparedStatementImpl(DremioConnectionImpl connection, StatementHandle h, Meta.Signature signature, PreparedStatement preparedStatementHandle, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { super(connection, h, signature, resultSetType, resultSetConcurrency, resultSetHoldability); connection.openStatementsRegistry.addStatement(this); this.preparedStatementHandle = preparedStatementHandle; if (preparedStatementHandle != null) { ((DremioColumnMetaDataList) signature.columns).updateColumnMetaData(preparedStatementHandle.getColumnsList()); } }
public Builder toBuilder() { return newBuilder(this); }
public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder(com.dremio.exec.proto.UserProtos.PreparedStatement prototype) {
public static Builder newBuilder(com.dremio.exec.proto.UserProtos.PreparedStatement prototype) { return newBuilder().mergeFrom(prototype); } public Builder toBuilder() { return newBuilder(this); }
/** * <code>optional .exec.user.PreparedStatement prepared_statement = 2;</code> */ public Builder clearPreparedStatement() { if (preparedStatementBuilder_ == null) { preparedStatement_ = com.dremio.exec.proto.UserProtos.PreparedStatement.getDefaultInstance(); onChanged(); } else { preparedStatementBuilder_.clear(); } bitField0_ = (bitField0_ & ~0x00000002); return this; } /**
public com.dremio.exec.proto.UserProtos.PreparedStatement getDefaultInstanceForType() { return com.dremio.exec.proto.UserProtos.PreparedStatement.getDefaultInstance(); }
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(); }
public void writeTo(io.protostuff.Output output, com.dremio.exec.proto.UserProtos.PreparedStatement message) throws java.io.IOException { for(com.dremio.exec.proto.UserProtos.ResultColumnMetadata columns : message.getColumnsList()) output.writeObject(1, columns, com.dremio.exec.proto.SchemaUserProtos.ResultColumnMetadata.WRITE, true); if(message.hasServerHandle()) output.writeObject(2, message.getServerHandle(), com.dremio.exec.proto.SchemaUserProtos.PreparedStatementHandle.WRITE, false); } public boolean isInitialized(com.dremio.exec.proto.UserProtos.PreparedStatement message)