QueryResultResource { @GET @Path("{cacheId}") @Produces(MediaType.APPLICATION_OCTET_STREAM) public Response getQueryResultSet(@HeaderParam(QueryResource.tajoSessionIdHeaderName) String sessionId, @PathParam("cacheId") String cacheId, @DefaultValue("-1") @QueryParam("offset") int offset, @DefaultValue("-1") @QueryParam("count") int count) { if (LOG.isDebugEnabled()) { LOG.debug("Client sent a get query result set request."); } Response response = null; try { initializeContext(); JerseyResourceDelegateContextKey<String> sessionIdKey = JerseyResourceDelegateContextKey.valueOf(sessionIdKeyName, String.class); context.put(sessionIdKey, sessionId); JerseyResourceDelegateContextKey<Long> cacheIdKey = JerseyResourceDelegateContextKey.valueOf(cacheIdKeyName, Long.class); context.put(cacheIdKey, Long.valueOf(cacheId)); JerseyResourceDelegateContextKey<Integer> offsetKey = JerseyResourceDelegateContextKey.valueOf(offsetKeyName, Integer.class); context.put(offsetKey, offset); JerseyResourceDelegateContextKey<Integer> countKey = JerseyResourceDelegateContextKey.valueOf(countKeyName, Integer.class); context.put(countKey, count); response = JerseyResourceDelegateUtil.runJerseyResourceDelegate( new GetQueryResultSetDelegate(), application, context, LOG); } catch (Throwable e) { LOG.error(e.getMessage(), e); response = ResourcesUtil.createExceptionResponse(null, e.getMessage()); } return response; }  UriInfo getUriInfo(); void setUriInfo(UriInfo uriInfo); Application getApplication(); void setApplication(Application application); String getDatabaseName(); void setDatabaseName(String databaseName); String getQueryId(); void setQueryId(String queryId); @GET @Produces(MediaType.APPLICATION_JSON) Response getQueryResult(@HeaderParam(QueryResource.tajoSessionIdHeaderName) String sessionId); @GET @Path("{cacheId}") @Produces(MediaType.APPLICATION_OCTET_STREAM) Response getQueryResultSet(@HeaderParam(QueryResource.tajoSessionIdHeaderName) String sessionId,
      @PathParam("cacheId") String cacheId,
      @DefaultValue("-1") @QueryParam("offset") int offset,
      @DefaultValue("-1") @QueryParam("count") int count);  }
@Test public void testGetQueryResultSet() throws Exception { String sessionId = generateNewSessionAndGetId(); URI queryIdURI = sendNewQueryResquest(sessionId, "select * from lineitem"); URI queryResultURI = new URI(queryIdURI + "/result"); GetQueryResultDataResponse response = restClient.target(queryResultURI) .request().header(tajoSessionIdHeaderName, sessionId) .get(new GenericType<GetQueryResultDataResponse>(GetQueryResultDataResponse.class)); assertNotNull(response); assertNotNull(response.getResultCode()); assertEquals(ResultCode.OK, response.getResultCode()); assertNotNull(response.getSchema()); assertEquals(16, response.getSchema().getRootColumns().size()); assertNotNull(response.getResultset()); assertTrue(response.getResultset().getId() != 0); assertNotNull(response.getResultset().getLink()); URI queryResultSetURI = response.getResultset().getLink(); Response queryResultSetResponse = restClient.target(queryResultSetURI) .queryParam("count", 100) .request().header(tajoSessionIdHeaderName, sessionId) .get(); assertNotNull(queryResultSetResponse); String tajoDigest = queryResultSetResponse.getHeaderString(tajoDigestHeaderName); assertTrue(tajoDigest != null && !tajoDigest.isEmpty()); DataInputStream queryResultSetInputStream = new DataInputStream(new BufferedInputStream(queryResultSetResponse.readEntity(InputStream.class))); assertNotNull(queryResultSetInputStream); boolean isFinished = false; List<Tuple> tupleList = TUtil.newList(); RowStoreUtil.RowStoreDecoder decoder = RowStoreUtil.createDecoder(response.getSchema()); MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); while (!isFinished) { try { int length = queryResultSetInputStream.readInt(); byte[] dataByteArray = new byte[length]; int readBytes = queryResultSetInputStream.read(dataByteArray); assertEquals(length, readBytes); tupleList.add(decoder.toTuple(dataByteArray)); messageDigest.update(dataByteArray); } catch (EOFException eof) { isFinished = true; } } assertEquals(5, tupleList.size()); assertEquals(tajoDigest, Base64.encodeBase64String(messageDigest.digest())); for (Tuple aTuple: tupleList) { assertTrue(aTuple.getInt4(response.getSchema().getColumnId("l_orderkey")) > 0); } }