private JsonNode sendQuery(String query) throws Exception { URLConnection urlConnection = new URL("http://" + _brokerAddress + "/query").openConnection(); urlConnection.setDoOutput(true); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(urlConnection.getOutputStream(), "UTF-8")); writer.write(JsonUtils.newObjectNode().put("pql", query).toString()); writer.flush(); BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), "UTF-8")); return JsonUtils.stringToJsonNode(reader.readLine()); }
public static TableConfig fromJsonString(String jsonString) throws IOException { return fromJSONConfig(JsonUtils.stringToJsonNode(jsonString)); }
public SegmentZKMetadataCustomMapModifier(@Nonnull String jsonString) throws IOException { JsonNode jsonNode = JsonUtils.stringToJsonNode(jsonString); _modifyMode = ModifyMode.valueOf(jsonNode.get(MAP_MODIFY_MODE_KEY).asText()); JsonNode jsonMap = jsonNode.get(MAP_KEY); if (jsonMap == null || jsonMap.size() == 0) { _map = null; } else { _map = new HashMap<>(); Iterator<String> keys = jsonMap.fieldNames(); while (keys.hasNext()) { String key = keys.next(); _map.put(key, jsonMap.get(key).asText()); } } }
@POST @Path("pql") public String post(String requestJsonStr, @Context HttpHeaders httpHeaders) { try { JsonNode requestJson = JsonUtils.stringToJsonNode(requestJsonStr); String pqlQuery = requestJson.get("pql").asText(); String traceEnabled = "false"; if (requestJson.has("trace")) { traceEnabled = requestJson.get("trace").toString(); } LOGGER.debug("Trace: {}, Running query: {}", traceEnabled, pqlQuery); return getQueryResponse(pqlQuery, traceEnabled, httpHeaders); } catch (Exception e) { LOGGER.error("Caught exception while processing post request", e); return QueryException.getException(QueryException.INTERNAL_ERROR, e).toString(); } }
ObjectNode responseJson = (ObjectNode) JsonUtils.stringToJsonNode(responseString); responseJson.put("totalTime", totalTime);
private static String getErrorMessage(HttpUriRequest request, CloseableHttpResponse response) { String controllerHost = null; String controllerVersion = null; if (response.containsHeader(CommonConstants.Controller.HOST_HTTP_HEADER)) { controllerHost = response.getFirstHeader(CommonConstants.Controller.HOST_HTTP_HEADER).getValue(); controllerVersion = response.getFirstHeader(CommonConstants.Controller.VERSION_HTTP_HEADER).getValue(); } StatusLine statusLine = response.getStatusLine(); String reason; try { reason = JsonUtils.stringToJsonNode(EntityUtils.toString(response.getEntity())).get("error").asText(); } catch (Exception e) { reason = "Failed to get reason"; } String errorMessage = String.format("Got error status code: %d (%s) with reason: \"%s\" while sending request: %s", statusLine.getStatusCode(), statusLine.getReasonPhrase(), reason, request.getURI()); if (controllerHost != null) { errorMessage = String.format("%s to controller: %s, version: %s", errorMessage, controllerHost, controllerVersion); } return errorMessage; }
@POST @Produces(MediaType.APPLICATION_JSON) @Path("query") @ApiOperation(value = "Querying pinot") @ApiResponses(value = {@ApiResponse(code = 200, message = "Query response"), @ApiResponse(code = 500, message = "Internal Server Error")}) public String processQueryPost(String query) { try { JsonNode requestJson = JsonUtils.stringToJsonNode(query); BrokerResponse brokerResponse = requestHandler.handleRequest(requestJson, null, new RequestStatistics()); return brokerResponse.toJsonString(); } catch (Exception e) { LOGGER.error("Caught exception while processing GET request", e); brokerMetrics.addMeteredGlobalValue(BrokerMeter.UNCAUGHT_GET_EXCEPTIONS, 1); throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); } } }
public JsonNode runQuery(String query) throws Exception { int brokerPort = _brokerPorts.get(RANDOM.nextInt(_brokerPorts.size())); return JsonUtils .stringToJsonNode(new PostQueryCommand().setBrokerPort(String.valueOf(brokerPort)).setQuery(query).run()); } }
private JsonNode getSegmentsFromJsonSegmentAPI(String json, String type) throws Exception { return JsonUtils.stringToJsonNode(json).get(0).get(type); }
protected JsonNode getDebugInfo(final String uri) throws Exception { return JsonUtils.stringToJsonNode(sendGetRequest(_brokerBaseApiUrl + "/" + uri)); }
public TableConfig getTableConfig() { FileUploadDownloadClient fileUploadDownloadClient = new FileUploadDownloadClient(); List<URI> tableConfigURIs = new ArrayList<>(); try { for (PushLocation pushLocation : _pushLocations) { tableConfigURIs.add(FileUploadDownloadClient .getRetrieveTableConfigURI(pushLocation.getHost(), pushLocation.getPort(), _tableName)); } } catch (URISyntaxException e) { LOGGER.error("Could not construct table config URI for table {}", _tableName); throw new RuntimeException(e); } // Return the first table config it can retrieve for (URI uri : tableConfigURIs) { try { SimpleHttpResponse response = fileUploadDownloadClient.getTableConfig(uri); JsonNode offlineTableConfig = JsonUtils.stringToJsonNode(response.getResponse()).get(OFFLINE); if (offlineTableConfig != null) { LOGGER.info("Got table config {}", offlineTableConfig); return TableConfig.fromJSONConfig(offlineTableConfig); } } catch (Exception e) { LOGGER.warn("Caught exception while trying to get table config for " + _tableName + " " + e); } } LOGGER.error("Could not get table configs from any push locations provided for " + _tableName); throw new RuntimeException("Could not get table config for table " + _tableName); }
public static JsonNode postQuery(String query, String brokerBaseApiUrl, boolean enableTrace) throws Exception { ObjectNode payload = JsonUtils.newObjectNode(); payload.put("pql", query); payload.put("trace", enableTrace); return JsonUtils.stringToJsonNode(sendPostRequest(brokerBaseApiUrl + "/query", payload.toString())); } }
LOGGER.info("QUERY: {}", query); JsonNode refResponse = JsonUtils.stringToJsonNode(_refCluster.query(query)); JsonNode starTreeResponse = JsonUtils.stringToJsonNode((_startTreeCluster.query(query)));
@Test public void testSegmentCrcMetadata() throws Exception { String segmentsCrcPath = "/tables/" + TABLE_NAME + "/segments/crc"; // Upload segments List<ImmutableSegment> immutableSegments = setUpSegments(2); // Trigger crc api to fetch crc information String response = _webTarget.path(segmentsCrcPath).request().get(String.class); JsonNode segmentsCrc = JsonUtils.stringToJsonNode(response); // Check that crc info is correct for (ImmutableSegment immutableSegment : immutableSegments) { String segmentName = immutableSegment.getSegmentName(); String crc = immutableSegment.getSegmentMetadata().getCrc(); Assert.assertEquals(segmentsCrc.get(segmentName).asText(), crc); } } }
JsonNode query = JsonUtils.stringToJsonNode(queryString); String pqlQuery = query.get("pql").asText(); JsonNode hsqls = query.get("hsqls");
JsonUtils.stringToJsonNode(_webTarget.path(segmentMetadataPath).request().get(String.class)); SegmentMetadataImpl segmentMetadata = (SegmentMetadataImpl) defaultSegment.getSegmentMetadata(); Assert.assertEquals(jsonResponse.get("segmentName").asText(), segmentMetadata.getName()); Assert.assertEquals(jsonResponse.get("columns").size(), 0); jsonResponse = JsonUtils.stringToJsonNode( _webTarget.path(segmentMetadataPath).queryParam("columns", "column1").queryParam("columns", "column2").request() .get(String.class)); Assert.assertEquals(jsonResponse.get("columns").size(), 2); jsonResponse = JsonUtils.stringToJsonNode( (_webTarget.path(segmentMetadataPath).queryParam("columns", "*").request().get(String.class))); Assert.assertEquals(jsonResponse.get("columns").size(), segmentMetadata.getAllColumns().size());
private TableConfig getTableConfig(String tableName, String tableType) throws Exception { String tableConfigString = sendGetRequest(_controllerRequestURLBuilder.forTableGet(tableName)); return TableConfig.fromJSONConfig(JsonUtils.stringToJsonNode(tableConfigString).get(tableType)); }
@Override public void handle(HttpExchange httpExchange) throws IOException { Headers requestHeaders = httpExchange.getRequestHeaders(); String uploadTypeStr = requestHeaders.getFirst(FileUploadDownloadClient.CustomHeaders.UPLOAD_TYPE); FileUploadType uploadType = FileUploadType.valueOf(uploadTypeStr); String downloadUri = null; if (uploadType == FileUploadType.JSON) { InputStream bodyStream = httpExchange.getRequestBody(); downloadUri = JsonUtils.stringToJsonNode(IOUtils.toString(bodyStream, "UTF-8")) .get(CommonConstants.Segment.Offline.DOWNLOAD_URL).asText(); } else if (uploadType == FileUploadType.URI) { downloadUri = requestHeaders.getFirst(FileUploadDownloadClient.CustomHeaders.DOWNLOAD_URI); String crypter = requestHeaders.getFirst(FileUploadDownloadClient.CustomHeaders.CRYPTER); Assert.assertEquals(crypter, TEST_CRYPTER); } else { Assert.fail(); } Assert.assertEquals(downloadUri, TEST_URI); sendResponse(httpExchange, HttpStatus.SC_OK, "OK"); }
JsonNode jsonNode = JsonUtils.stringToJsonNode(line); if (avroDataPublisher.hasNext()) { final GenericRow recordRow = avroDataPublisher.next();
@Test public void TestReadAvro() throws Exception { final String filePath = TestUtils.getFileFromResourceUrl(getClass().getClassLoader().getResource(AVRO_DATA)); final String jsonPath = TestUtils.getFileFromResourceUrl(getClass().getClassLoader().getResource(JSON_DATA)); Schema schema = new Schema.SchemaBuilder().addSingleValueDimension("column3", DataType.STRING) .addSingleValueDimension("column2", DataType.STRING).build(); final SegmentGeneratorConfig config = new SegmentGeneratorConfig(schema); config.setFormat(FileFormat.AVRO); config.setInputFilePath(filePath); config.setSegmentVersion(SegmentVersion.v1); AvroRecordReader avroDataPublisher = (AvroRecordReader) RecordReaderFactory.getRecordReader(config); int cnt = 0; for (String line : FileUtils.readLines(new File(jsonPath))) { JsonNode jsonNode = JsonUtils.stringToJsonNode(line); if (avroDataPublisher.hasNext()) { GenericRow recordRow = avroDataPublisher.next(); for (String column : recordRow.getFieldNames()) { String valueFromJson = jsonNode.get(column).asText(); String valueFromAvro = recordRow.getValue(column).toString(); if (cnt > 1) { Assert.assertEquals(valueFromJson, valueFromAvro); } } } cnt++; } Assert.assertEquals(cnt, 10001); }