本文整理了Java中org.apache.pinot.common.utils.JsonUtils.objectToJsonNode()
方法的一些代码示例,展示了JsonUtils.objectToJsonNode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonUtils.objectToJsonNode()
方法的具体详情如下:
包路径:org.apache.pinot.common.utils.JsonUtils
类名称:JsonUtils
方法名:objectToJsonNode
暂无
代码示例来源: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
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
private String listInstancesForTenant(String tenantName, String tenantType) {
ObjectNode resourceGetRet = JsonUtils.newObjectNode();
if (tenantType == null) {
resourceGetRet.set("ServerInstances",
JsonUtils.objectToJsonNode(pinotHelixResourceManager.getAllInstancesForServerTenant(tenantName)));
resourceGetRet.set("BrokerInstances",
JsonUtils.objectToJsonNode(pinotHelixResourceManager.getAllInstancesForBrokerTenant(tenantName)));
} else {
if (tenantType.equalsIgnoreCase("server")) {
resourceGetRet.set("ServerInstances",
JsonUtils.objectToJsonNode(pinotHelixResourceManager.getAllInstancesForServerTenant(tenantName)));
}
if (tenantType.equalsIgnoreCase("broker")) {
resourceGetRet.set("BrokerInstances",
JsonUtils.objectToJsonNode(pinotHelixResourceManager.getAllInstancesForBrokerTenant(tenantName)));
}
}
resourceGetRet.put(TENANT_NAME, tenantName);
return resourceGetRet.toString();
}
代码示例来源:origin: apache/incubator-pinot
protected void appendDefaultNullValue(ObjectNode jsonNode) {
assert _defaultNullValue != null;
if (!_defaultNullValue.equals(getDefaultNullValue(getFieldType(), _dataType, null))) {
if (_defaultNullValue instanceof Number) {
jsonNode.set("defaultNullValue", JsonUtils.objectToJsonNode(_defaultNullValue));
} else {
jsonNode.put("defaultNullValue", getStringValue(_defaultNullValue));
}
}
}
代码示例来源: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
@GET
@Path("/instances/{instanceName}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get instance information", produces = MediaType.APPLICATION_JSON)
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 404, message = "Instance not found"), @ApiResponse(code = 500, message = "Internal error")})
public String getInstance(
@ApiParam(value = "Instance name", required = true, example = "Server_a.b.com_20000 | Broker_my.broker.com_30000")
@PathParam("instanceName") String instanceName) {
InstanceConfig instanceConfig = pinotHelixResourceManager.getHelixInstanceConfig(instanceName);
if (instanceConfig == null) {
throw new ControllerApplicationException(LOGGER, "Instance " + instanceName + " not found",
Response.Status.NOT_FOUND);
}
ObjectNode response = JsonUtils.newObjectNode();
response.put("instanceName", instanceConfig.getInstanceName());
response.put("hostName", instanceConfig.getHostName());
response.put("enabled", instanceConfig.getInstanceEnabled());
response.put("port", instanceConfig.getPort());
response.set("tags", JsonUtils.objectToJsonNode(instanceConfig.getTags()));
return response.toString();
}
代码示例来源: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
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/tables")
@ApiOperation(value = "Lists all tables in cluster", notes = "Lists all tables in cluster")
public String listTableConfigs(@ApiParam(value = "realtime|offline") @QueryParam("type") String tableTypeStr) {
try {
List<String> tableNames;
CommonConstants.Helix.TableType tableType = null;
if (tableTypeStr != null) {
tableType = CommonConstants.Helix.TableType.valueOf(tableTypeStr.toUpperCase());
}
if (tableType == null) {
tableNames = _pinotHelixResourceManager.getAllRawTables();
} else {
if (tableType == CommonConstants.Helix.TableType.REALTIME) {
tableNames = _pinotHelixResourceManager.getAllRealtimeTables();
} else {
tableNames = _pinotHelixResourceManager.getAllOfflineTables();
}
}
Collections.sort(tableNames);
return JsonUtils.newObjectNode().set("tables", JsonUtils.objectToJsonNode(tableNames)).toString();
} catch (Exception e) {
throw new ControllerApplicationException(LOGGER, e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR, e);
}
}
代码示例来源: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
@Override
public String dumpSnapshot(String tableName)
throws Exception {
ObjectNode ret = JsonUtils.newObjectNode();
ArrayNode routingTableSnapshot = JsonUtils.newArrayNode();
for (String currentTable : _routingTableBuilderMap.keySet()) {
if (tableName == null || currentTable.startsWith(tableName)) {
ObjectNode tableEntry = JsonUtils.newObjectNode();
tableEntry.put("tableName", currentTable);
ArrayNode entries = JsonUtils.newArrayNode();
RoutingTableBuilder routingTableBuilder = _routingTableBuilderMap.get(currentTable);
List<Map<String, List<String>>> routingTables = routingTableBuilder.getRoutingTables();
for (Map<String, List<String>> routingTable : routingTables) {
entries.add(JsonUtils.objectToJsonNode(routingTable));
}
tableEntry.set("routingTableEntries", entries);
routingTableSnapshot.add(tableEntry);
}
}
ret.set("routingTableSnapshot", routingTableSnapshot);
ret.put("host", NetUtil.getHostnameOrAddress());
return JsonUtils.objectToPrettyString(ret);
}
}
代码示例来源: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
@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
@Override
public PinotRecord serialize(T t) {
_record.clear();
JsonNode jsonRecord = JsonUtils.objectToJsonNode(t);
for (FieldSpec fieldSpec : _schema.getAllFieldSpecs()) {
String column = fieldSpec.getName();
_record.putField(column, JsonUtils.extractValue(jsonRecord.get(column), fieldSpec));
}
return _record;
}
代码示例来源:origin: apache/incubator-pinot
@Test
public void testJsonResponseWithoutSplitCommit() {
SegmentCompletionProtocol.Response.Params params =
new SegmentCompletionProtocol.Response.Params().withBuildTimeSeconds(BUILD_TIME_MILLIS).withOffset(OFFSET)
.withSplitCommit(false).withStatus(SegmentCompletionProtocol.ControllerResponseStatus.COMMIT);
SegmentCompletionProtocol.Response response = new SegmentCompletionProtocol.Response(params);
JsonNode jsonNode = JsonUtils.objectToJsonNode(response);
assertEquals(jsonNode.get("offset").asInt(), OFFSET);
assertNull(jsonNode.get("segmentLocation"));
assertFalse(jsonNode.get("isSplitCommitType").asBoolean());
assertEquals(jsonNode.get("status").asText(), SegmentCompletionProtocol.ControllerResponseStatus.COMMIT.toString());
assertNull(jsonNode.get("controllerVipUrl"));
}
代码示例来源:origin: apache/incubator-pinot
@Test
public void testJsonNullSegmentLocationAndVip() {
SegmentCompletionProtocol.Response.Params params =
new SegmentCompletionProtocol.Response.Params().withBuildTimeSeconds(BUILD_TIME_MILLIS).withOffset(OFFSET)
.withSplitCommit(false).withStatus(SegmentCompletionProtocol.ControllerResponseStatus.COMMIT);
SegmentCompletionProtocol.Response response = new SegmentCompletionProtocol.Response(params);
JsonNode jsonNode = JsonUtils.objectToJsonNode(response);
assertEquals(jsonNode.get("offset").asInt(), OFFSET);
assertNull(jsonNode.get("segmentLocation"));
assertFalse(jsonNode.get("isSplitCommitType").asBoolean());
assertEquals(jsonNode.get("status").asText(), SegmentCompletionProtocol.ControllerResponseStatus.COMMIT.toString());
assertNull(jsonNode.get("controllerVipUrl"));
}
代码示例来源:origin: apache/incubator-pinot
@Test
public void testJsonResponseWithVipAndNullSegmentLocation() {
// Should never happen because if split commit, should have both location and VIP, but testing deserialization regardless
SegmentCompletionProtocol.Response.Params params =
new SegmentCompletionProtocol.Response.Params().withBuildTimeSeconds(BUILD_TIME_MILLIS).withOffset(OFFSET)
.withControllerVipUrl(CONTROLLER_VIP_URL).withSplitCommit(false)
.withStatus(SegmentCompletionProtocol.ControllerResponseStatus.COMMIT);
SegmentCompletionProtocol.Response response = new SegmentCompletionProtocol.Response(params);
JsonNode jsonNode = JsonUtils.objectToJsonNode(response);
assertEquals(jsonNode.get("offset").asInt(), OFFSET);
assertNull(jsonNode.get("segmentLocation"));
assertFalse(jsonNode.get("isSplitCommitType").asBoolean());
assertEquals(jsonNode.get("status").asText(), SegmentCompletionProtocol.ControllerResponseStatus.COMMIT.toString());
assertEquals(jsonNode.get("controllerVipUrl").asText(), CONTROLLER_VIP_URL);
}
}
代码示例来源:origin: apache/incubator-pinot
@Test
public void testJsonResponseWithAllParams() {
// Test with all params
SegmentCompletionProtocol.Response.Params params =
new SegmentCompletionProtocol.Response.Params().withBuildTimeSeconds(BUILD_TIME_MILLIS).withOffset(OFFSET)
.withSegmentLocation(SEGMENT_LOCATION).withSplitCommit(true).withControllerVipUrl(CONTROLLER_VIP_URL)
.withStatus(SegmentCompletionProtocol.ControllerResponseStatus.COMMIT);
SegmentCompletionProtocol.Response response = new SegmentCompletionProtocol.Response(params);
JsonNode jsonNode = JsonUtils.objectToJsonNode(response);
assertEquals(jsonNode.get("offset").asInt(), OFFSET);
assertEquals(jsonNode.get("segmentLocation").asText(), SEGMENT_LOCATION);
assertTrue(jsonNode.get("isSplitCommitType").asBoolean());
assertEquals(jsonNode.get("status").asText(), SegmentCompletionProtocol.ControllerResponseStatus.COMMIT.toString());
assertEquals(jsonNode.get("controllerVipUrl").asText(), CONTROLLER_VIP_URL);
}
代码示例来源:origin: apache/incubator-pinot
@Test
public void testJsonResponseWithSegmentLocationNullVip() {
// Should never happen because if split commit, should have both location and VIP, but testing deserialization regardless
SegmentCompletionProtocol.Response.Params params =
new SegmentCompletionProtocol.Response.Params().withBuildTimeSeconds(BUILD_TIME_MILLIS).withOffset(OFFSET)
.withSegmentLocation(SEGMENT_LOCATION).withSplitCommit(false)
.withStatus(SegmentCompletionProtocol.ControllerResponseStatus.COMMIT);
SegmentCompletionProtocol.Response response = new SegmentCompletionProtocol.Response(params);
JsonNode jsonNode = JsonUtils.objectToJsonNode(response);
assertEquals(jsonNode.get("offset").asInt(), OFFSET);
assertEquals(jsonNode.get("segmentLocation").asText(), SEGMENT_LOCATION);
assertFalse(jsonNode.get("isSplitCommitType").asBoolean());
assertEquals(jsonNode.get("status").asText(), SegmentCompletionProtocol.ControllerResponseStatus.COMMIT.toString());
assertNull(jsonNode.get("controllerVipUrl"));
}
代码示例来源:origin: apache/incubator-pinot
/**
* Sample main class for the query generator.
*
* @param args arguments.
*/
public static void main(String[] args)
throws Exception {
File avroFile = new File("pinot-integration-tests/src/test/resources/On_Time_On_Time_Performance_2014_1.avro");
QueryGenerator queryGenerator = new QueryGenerator(Collections.singletonList(avroFile), "mytable", "mytable");
File outputFile = new File(
"pinot-integration-tests/src/test/resources/On_Time_On_Time_Performance_2014_100k_subset.test_queries_10K");
try (BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))) {
for (int i = 0; i < 10000; i++) {
Query query = queryGenerator.generateQuery();
ObjectNode queryJson = JsonUtils.newObjectNode();
queryJson.put("pql", query.generatePql());
queryJson.set("hsqls", JsonUtils.objectToJsonNode(query.generateH2Sql()));
writer.write(queryJson.toString());
writer.newLine();
}
}
}
内容来源于网络,如有侵权,请联系作者删除!