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

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

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

JsonUtils.newObjectNode介绍

暂无

代码示例

代码示例来源: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

JsonNode toJson() {
  return JsonUtils.newObjectNode().set(_key, JsonUtils.objectToJsonNode(_value));
 }
}

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

public String toJsonString() {
 ObjectNode objectNode = JsonUtils.newObjectNode();
 objectNode.put(MAP_MODIFY_MODE_KEY, _modifyMode.toString());
 objectNode.set(MAP_KEY, JsonUtils.objectToJsonNode(_map));
 return objectNode.toString();
}

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

JsonNode toJson() {
  ArrayNode jsonLogs = JsonUtils.newArrayNode();
  for (LogEntry log : _logs) {
   jsonLogs.add(log.toJson());
  }
  return JsonUtils.newObjectNode().set(_traceId, jsonLogs);
 }
}

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

public static org.apache.avro.Schema getAvroSchema(Schema schema) {
 ObjectNode avroSchema = JsonUtils.newObjectNode();
 avroSchema.put("name", "data_gen_record");
 avroSchema.put("type", "record");
 ArrayNode fields = JsonUtils.newArrayNode();
 for (FieldSpec fieldSpec : schema.getAllFieldSpecs()) {
  JsonNode jsonObject = fieldSpec.toAvroSchemaJsonObject();
  fields.add(jsonObject);
 }
 avroSchema.set("fields", fields);
 return new org.apache.avro.Schema.Parser().parse(avroSchema.toString());
}

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

public String sendPQLRaw(String url, String pqlRequest, String traceEnabled) {
  try {
   final long startTime = System.currentTimeMillis();
   ObjectNode bqlJson = JsonUtils.newObjectNode().put("pql", pqlRequest);
   if (traceEnabled != null && !traceEnabled.isEmpty()) {
    bqlJson.put("trace", traceEnabled);
   }

   final String pinotResultString = sendPostRaw(url, bqlJson.toString(), null);

   final long bqlQueryTime = System.currentTimeMillis() - startTime;
   LOGGER.info("BQL: " + pqlRequest + " Time: " + bqlQueryTime);

   return pinotResultString;
  } catch (final Exception ex) {
   LOGGER.error("Caught exception in sendPQLRaw", ex);
   Utils.rethrowException(ex);
   throw new AssertionError("Should not reach this");
  }
 }
}

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

/**
 * Returns the {@link ObjectNode} representing the time granularity spec.
 * <p>Only contains fields with non-default value.
 * <p>NOTE: here we use {@link ObjectNode} to preserve the insertion order.
 */
public ObjectNode toJsonObject() {
 ObjectNode jsonObject = JsonUtils.newObjectNode();
 jsonObject.put("name", _name);
 jsonObject.put("dataType", _dataType.name());
 jsonObject.put("timeType", _timeType.name());
 if (_timeUnitSize != DEFAULT_TIME_UNIT_SIZE) {
  jsonObject.put("timeUnitSize", _timeUnitSize);
 }
 if (!_timeFormat.equals(DEFAULT_TIME_FORMAT)) {
  jsonObject.put("timeFormat", _timeFormat);
 }
 return jsonObject;
}

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

/**
 * Returns the {@link ObjectNode} representing the field spec.
 * <p>Only contains fields with non-default value.
 * <p>NOTE: here we use {@link ObjectNode} to preserve the insertion order.
 */
public ObjectNode toJsonObject() {
 ObjectNode jsonObject = JsonUtils.newObjectNode();
 jsonObject.put("name", _name);
 jsonObject.put("dataType", _dataType.name());
 if (!_isSingleValueField) {
  jsonObject.put("singleValueField", false);
 }
 if (_maxLength != DEFAULT_MAX_LENGTH) {
  jsonObject.put("maxLength", _maxLength);
 }
 appendDefaultNullValue(jsonObject);
 return jsonObject;
}

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

private String getTablesServedFromTenant(String tenantName) {
 Set<String> tables = new HashSet<>();
 ObjectNode resourceGetRet = JsonUtils.newObjectNode();
 for (String table : pinotHelixResourceManager.getAllTables()) {
  TableConfig tableConfig = pinotHelixResourceManager.getTableConfig(table);
  String tableConfigTenant = tableConfig.getTenantConfig().getServer();
  if (tenantName.equals(tableConfigTenant)) {
   tables.add(table);
  }
 }
 resourceGetRet.set(TABLES, JsonUtils.objectToJsonNode(tables));
 return resourceGetRet.toString();
}

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

private JsonNode formatSegments(String tableName, CommonConstants.Helix.TableType tableType) {
 return JsonUtils.newObjectNode().set(tableType.toString(), getSegments(tableName, tableType.toString()));
}

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

@Nonnull
@Override
public ObjectNode toJsonObject() {
 ObjectNode jsonObject = JsonUtils.newObjectNode();
 jsonObject.set("incomingGranularitySpec", _incomingGranularitySpec.toJsonObject());
 if (!getOutgoingGranularitySpec().equals(_incomingGranularitySpec)) {
  jsonObject.set("outgoingGranularitySpec", _outgoingGranularitySpec.toJsonObject());
 }
 appendDefaultNullValue(jsonObject);
 return jsonObject;
}

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

@Nonnull
public static JsonNode toJSONConfig(@Nonnull TableConfig tableConfig) {
 ObjectNode jsonConfig = JsonUtils.newObjectNode();
 jsonConfig.put(TABLE_NAME_KEY, tableConfig._tableName);
 jsonConfig.put(TABLE_TYPE_KEY, tableConfig._tableType.toString());
 jsonConfig.set(VALIDATION_CONFIG_KEY, JsonUtils.objectToJsonNode(tableConfig._validationConfig));
 jsonConfig.set(TENANT_CONFIG_KEY, JsonUtils.objectToJsonNode(tableConfig._tenantConfig));
 jsonConfig.set(INDEXING_CONFIG_KEY, JsonUtils.objectToJsonNode(tableConfig._indexingConfig));
 jsonConfig.set(CUSTOM_CONFIG_KEY, JsonUtils.objectToJsonNode(tableConfig._customConfig));
 if (tableConfig._quotaConfig != null) {
  jsonConfig.set(QUOTA_CONFIG_KEY, JsonUtils.objectToJsonNode(tableConfig._quotaConfig));
 }
 if (tableConfig._taskConfig != null) {
  jsonConfig.set(TASK_CONFIG_KEY, JsonUtils.objectToJsonNode(tableConfig._taskConfig));
 }
 if (tableConfig._routingConfig != null) {
  jsonConfig.set(ROUTING_CONFIG_KEY, JsonUtils.objectToJsonNode(tableConfig._routingConfig));
 }
 return jsonConfig;
}

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

@Override
 public void convert()
   throws Exception {
  try (PinotSegmentRecordReader recordReader = new PinotSegmentRecordReader(new File(_segmentDir));
    BufferedWriter recordWriter = new BufferedWriter(new FileWriter(_outputFile))) {
   GenericRow row = new GenericRow();
   while (recordReader.hasNext()) {
    row = recordReader.next(row);
    ObjectNode record = JsonUtils.newObjectNode();
    for (String column : row.getFieldNames()) {
     record.set(column, JsonUtils.objectToJsonNode(row.getValue(column)));
    }
    recordWriter.write(record.toString());
    recordWriter.newLine();
   }
  }
 }
}

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

private static String getTraceString(String key, Object value) {
  return JsonUtils.newObjectNode().set(key, JsonUtils.objectToJsonNode(value)).toString();
 }
}

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

private String listTableConfigs(@Nonnull String tableName, @Nullable String tableTypeStr) {
 try {
  ObjectNode ret = JsonUtils.newObjectNode();
  if ((tableTypeStr == null || CommonConstants.Helix.TableType.OFFLINE.name().equalsIgnoreCase(tableTypeStr))
    && _pinotHelixResourceManager.hasOfflineTable(tableName)) {
   TableConfig tableConfig = _pinotHelixResourceManager.getOfflineTableConfig(tableName);
   Preconditions.checkNotNull(tableConfig);
   ret.set(CommonConstants.Helix.TableType.OFFLINE.name(), TableConfig.toJSONConfig(tableConfig));
  }
  if ((tableTypeStr == null || CommonConstants.Helix.TableType.REALTIME.name().equalsIgnoreCase(tableTypeStr))
    && _pinotHelixResourceManager.hasRealtimeTable(tableName)) {
   TableConfig tableConfig = _pinotHelixResourceManager.getRealtimeTableConfig(tableName);
   Preconditions.checkNotNull(tableConfig);
   ret.set(CommonConstants.Helix.TableType.REALTIME.name(), TableConfig.toJSONConfig(tableConfig));
  }
  return ret.toString();
 } catch (Exception e) {
  throw new ControllerApplicationException(LOGGER, e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR, e);
 }
}

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

@Override
public T deserialize(PinotRecord record)
  throws IOException {
 ObjectNode jsonRecord = JsonUtils.newObjectNode();
 for (String column : _schema.getColumnNames()) {
  jsonRecord.set(column, JsonUtils.objectToJsonNode(record.getValue(column)));
 }
 return JsonUtils.jsonNodeToObject(jsonRecord, getJsonReaderClass(_conf));
}

代码示例来源: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

@BeforeClass
public void setUp()
  throws Exception {
 FileUtils.forceMkdir(TEMP_DIR);
 try (FileWriter fileWriter = new FileWriter(DATA_FILE)) {
  for (Object[] record : RECORDS) {
   ObjectNode jsonRecord = JsonUtils.newObjectNode();
   if (record[0] != null) {
    jsonRecord.set(COLUMNS[0], JsonUtils.objectToJsonNode(record[0]));
   }
   if (record[1] != null) {
    jsonRecord.set(COLUMNS[1], JsonUtils.objectToJsonNode(record[1]));
   }
   fileWriter.write(jsonRecord.toString());
  }
 }
}

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

@BeforeClass
public void setUp()
  throws Exception {
 super.setUp();
 // Create eight dummy server instances
 for (int i = 0; i < 8; ++i) {
  ObjectNode serverInstance = JsonUtils.newObjectNode();
  serverInstance.put("host", hostName);
  serverInstance.put("port", Integer.toString(basePort + i));
  serverInstance.put("tag", serverTenant);
  serverInstance.put("type", "server");
  sendPostRequest(_controllerRequestURLBuilder.forInstanceCreate(), serverInstance.toString());
 }
}

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

@Test
public void testSendFileWithJson()
  throws Exception {
 ObjectNode segmentJson = JsonUtils.newObjectNode();
 segmentJson.put(CommonConstants.Segment.Offline.DOWNLOAD_URL, TEST_URI);
 String jsonString = segmentJson.toString();
 try (FileUploadDownloadClient fileUploadDownloadClient = new FileUploadDownloadClient()) {
  SimpleHttpResponse response = fileUploadDownloadClient
    .sendSegmentJson(FileUploadDownloadClient.getUploadSegmentHttpURI(TEST_HOST, TEST_PORT), jsonString);
  Assert.assertEquals(response.getStatusCode(), HttpStatus.SC_OK);
  Assert.assertEquals(response.getResponse(), "OK");
 }
}

相关文章