org.apache.pinot.common.utils.JsonUtils.stringToJsonNode()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(115)

本文整理了Java中org.apache.pinot.common.utils.JsonUtils.stringToJsonNode()方法的一些代码示例,展示了JsonUtils.stringToJsonNode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonUtils.stringToJsonNode()方法的具体详情如下:
包路径:org.apache.pinot.common.utils.JsonUtils
类名称:JsonUtils
方法名:stringToJsonNode

JsonUtils.stringToJsonNode介绍

暂无

代码示例

代码示例来源:origin: apache/incubator-pinot

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());
}

代码示例来源:origin: apache/incubator-pinot

public static TableConfig fromJsonString(String jsonString)
  throws IOException {
 return fromJSONConfig(JsonUtils.stringToJsonNode(jsonString));
}

代码示例来源:origin: apache/incubator-pinot

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());
  }
 }
}

代码示例来源:origin: apache/incubator-pinot

@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();
 }
}

代码示例来源:origin: apache/incubator-pinot

ObjectNode responseJson = (ObjectNode) JsonUtils.stringToJsonNode(responseString);
responseJson.put("totalTime", totalTime);

代码示例来源:origin: apache/incubator-pinot

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;
}

代码示例来源:origin: apache/incubator-pinot

@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);
  }
 }
}

代码示例来源:origin: apache/incubator-pinot

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());
 }
}

代码示例来源:origin: apache/incubator-pinot

private JsonNode getSegmentsFromJsonSegmentAPI(String json, String type)
  throws Exception {
 return JsonUtils.stringToJsonNode(json).get(0).get(type);
}

代码示例来源:origin: apache/incubator-pinot

protected JsonNode getDebugInfo(final String uri)
  throws Exception {
 return JsonUtils.stringToJsonNode(sendGetRequest(_brokerBaseApiUrl + "/" + uri));
}

代码示例来源:origin: apache/incubator-pinot

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);
}

代码示例来源:origin: apache/incubator-pinot

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()));
 }
}

代码示例来源:origin: apache/incubator-pinot

LOGGER.info("QUERY: {}", query);
JsonNode refResponse = JsonUtils.stringToJsonNode(_refCluster.query(query));
JsonNode starTreeResponse = JsonUtils.stringToJsonNode((_startTreeCluster.query(query)));

代码示例来源:origin: apache/incubator-pinot

@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);
  }
 }
}

代码示例来源:origin: apache/incubator-pinot

JsonNode query = JsonUtils.stringToJsonNode(queryString);
String pqlQuery = query.get("pql").asText();
JsonNode hsqls = query.get("hsqls");

代码示例来源:origin: apache/incubator-pinot

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());

代码示例来源:origin: apache/incubator-pinot

private TableConfig getTableConfig(String tableName, String tableType)
  throws Exception {
 String tableConfigString = sendGetRequest(_controllerRequestURLBuilder.forTableGet(tableName));
 return TableConfig.fromJSONConfig(JsonUtils.stringToJsonNode(tableConfigString).get(tableType));
}

代码示例来源:origin: apache/incubator-pinot

@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");
}

代码示例来源:origin: apache/incubator-pinot

JsonNode jsonNode = JsonUtils.stringToJsonNode(line);
if (avroDataPublisher.hasNext()) {
 final GenericRow recordRow = avroDataPublisher.next();

代码示例来源:origin: apache/incubator-pinot

@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);
}

相关文章