本文整理了Java中org.apache.pinot.common.utils.JsonUtils.objectToString()
方法的一些代码示例,展示了JsonUtils.objectToString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonUtils.objectToString()
方法的具体详情如下:
包路径:org.apache.pinot.common.utils.JsonUtils
类名称:JsonUtils
方法名:objectToString
暂无
代码示例来源:origin: apache/incubator-pinot
/**
* Returns the JSON equivalent of the object.
*
* @return JSON string equivalent of the object.
*/
public String toJsonString()
throws IOException {
return JsonUtils.objectToString(this);
}
代码示例来源:origin: apache/incubator-pinot
@Override
public String toJsonString()
throws IOException {
return JsonUtils.objectToString(this);
}
代码示例来源:origin: apache/incubator-pinot
@Override
public String toString() {
try {
return JsonUtils.objectToString(this);
} catch (IOException e) {
return null;
}
}
}
代码示例来源:origin: apache/incubator-pinot
/**
* Returns the JSON equivalent of the object.
*
* @return JSON string equivalent of the object.
* @throws IOException
*/
public String toJsonString()
throws IOException {
return JsonUtils.objectToString(this);
}
代码示例来源:origin: apache/incubator-pinot
public String toJsonString()
throws JsonProcessingException {
return JsonUtils.objectToString(this);
}
代码示例来源:origin: apache/incubator-pinot
public String toJsonString() {
try {
return JsonUtils.objectToString(this);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: apache/incubator-pinot
public static void printResult(QueryResponse queryResponse)
throws IOException {
LOGGER.info(JsonUtils.objectToString(queryResponse));
}
}
代码示例来源:origin: apache/incubator-pinot
private String toJson(final WebApplicationException exception) {
ErrorInfo errorInfo = new ErrorInfo(exception);
// difference between try and catch block is that
// ErrorInfo can contain more information that just message
try {
return JsonUtils.objectToString(errorInfo);
} catch (JsonProcessingException e) {
return "{\"message\":\"Error converting error message: " + e.getMessage() + " to string\"}";
}
}
}
代码示例来源:origin: apache/incubator-pinot
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get version number of Pinot components")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success")})
public String getVersionNumber() {
try {
return JsonUtils.objectToString(Utils.getComponentVersions());
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
}
代码示例来源:origin: apache/incubator-pinot
@Override
public Response toResponse(Throwable t) {
int status = 500;
if (!(t instanceof WebApplicationException)) {
LOGGER.error("Server error: ", t);
} else {
status = ((WebApplicationException) t).getResponse().getStatus();
}
ErrorInfo einfo = new ErrorInfo(status, t.getMessage());
try {
return Response.status(status).entity(JsonUtils.objectToString(einfo)).type(MediaType.APPLICATION_JSON).build();
} catch (JsonProcessingException e) {
String err = String.format("{\"status\":%d, \"error\":%s}", einfo.code, einfo.error);
return Response.status(status).entity(err).type(MediaType.APPLICATION_JSON).build();
}
}
代码示例来源:origin: apache/incubator-pinot
public String run()
throws Exception {
if (_brokerHost == null) {
_brokerHost = NetUtil.getHostAddress();
}
LOGGER.info("Executing command: " + toString());
String request = JsonUtils.objectToString(Collections.singletonMap("pql", _query));
return sendPostRequest("http://" + _brokerHost + ":" + _brokerPort + "/query", request);
}
代码示例来源:origin: apache/incubator-pinot
public static void main(String[] args)
throws Exception {
if (args.length != 3) {
LOGGER.error("Incorrect arguments");
LOGGER.info("Usage: <exec> <UntarredSegmentDir> <QueryFile> <outputFile>");
System.exit(1);
}
String segDir = args[0];
String queryFile = args[1];
String outputFile = args[2];
String query;
ScanBasedQueryProcessor scanBasedQueryProcessor = new ScanBasedQueryProcessor(segDir);
BufferedReader bufferedReader = new BufferedReader(new FileReader(queryFile));
PrintWriter printWriter = new PrintWriter(outputFile);
while ((query = bufferedReader.readLine()) != null) {
QueryResponse queryResponse = scanBasedQueryProcessor.processQuery(query);
printResult(queryResponse);
printWriter.println("Query: " + query);
printWriter.println("Result: " + JsonUtils.objectToString(queryResponse));
}
bufferedReader.close();
printWriter.close();
}
代码示例来源:origin: apache/incubator-pinot
private String getInstanceToSegmentsMap(@Nonnull String tableName,
@Nullable CommonConstants.Helix.TableType tableType) {
List<String> tableNamesWithType = getExistingTableNamesWithType(tableName, tableType);
ArrayNode result = JsonUtils.newArrayNode();
for (String tableNameWithType : tableNamesWithType) {
ObjectNode resultForTable = JsonUtils.newObjectNode();
resultForTable.put(FileUploadPathProvider.TABLE_NAME, tableNameWithType);
try {
// NOTE: for backward-compatibility, we put serialized map string as the value
resultForTable.put("segments",
JsonUtils.objectToString(_pinotHelixResourceManager.getServerToSegmentsMap(tableNameWithType)));
} catch (JsonProcessingException e) {
throw new ControllerApplicationException(LOGGER,
"Caught JSON exception while getting instance to segments map for table: " + tableNameWithType,
Response.Status.INTERNAL_SERVER_ERROR, e);
}
result.add(resultForTable);
}
return result.toString();
}
代码示例来源:origin: apache/incubator-pinot
@Test
public void testSerDe()
throws Exception {
ColumnPartitionMetadata expected = new ColumnPartitionMetadata(FUNCTION_NAME, NUM_PARTITIONS, PARTITIONS);
ColumnPartitionMetadata actual =
JsonUtils.stringToObject(JsonUtils.objectToString(expected), ColumnPartitionMetadata.class);
assertEquals(actual, expected);
}
代码示例来源:origin: apache/incubator-pinot
@Override
public void handle(HttpExchange httpExchange)
throws IOException {
if (sleepTimeMs > 0) {
try {
Thread.sleep(sleepTimeMs);
} catch (InterruptedException e) {
LOGGER.info("Handler interrupted during sleep");
}
}
String json = JsonUtils.objectToString(tableSize);
httpExchange.sendResponseHeaders(status, json.length());
OutputStream responseBody = httpExchange.getResponseBody();
responseBody.write(json.getBytes());
responseBody.close();
}
};
代码示例来源:origin: apache/incubator-pinot
@Override
public void handle(HttpExchange httpExchange)
throws IOException {
if (sleepTimeMs > 0) {
try {
Thread.sleep(sleepTimeMs);
} catch (InterruptedException e) {
LOGGER.info("Handler interrupted during sleep");
}
}
TableSizeInfo tableInfo = new TableSizeInfo("myTable", 0);
tableInfo.segments = segmentSizes;
for (SegmentSizeInfo segmentSize : segmentSizes) {
tableInfo.diskSizeInBytes += segmentSize.diskSizeInBytes;
}
String json = JsonUtils.objectToString(tableInfo);
httpExchange.sendResponseHeaders(status, json.length());
OutputStream responseBody = httpExchange.getResponseBody();
responseBody.write(json.getBytes());
responseBody.close();
}
};
代码示例来源:origin: apache/incubator-pinot
public static String buildServerTenantCreateRequestJSON(String tenantName, int numberOfInstances,
int offlineInstances, int realtimeInstances)
throws JsonProcessingException {
Tenant tenant = new TenantBuilder(tenantName).setRole(TenantRole.SERVER).setTotalInstances(numberOfInstances)
.setOfflineInstances(offlineInstances).setRealtimeInstances(realtimeInstances).build();
return JsonUtils.objectToString(tenant);
}
}
代码示例来源:origin: apache/incubator-pinot
public static String buildBrokerTenantCreateRequestJSON(String tenantName, int numberOfInstances)
throws JsonProcessingException {
Tenant tenant = new TenantBuilder(tenantName).setRole(TenantRole.BROKER).setTotalInstances(numberOfInstances)
.setOfflineInstances(0).setRealtimeInstances(0).build();
return JsonUtils.objectToString(tenant);
}
代码示例来源:origin: apache/incubator-pinot
@Test
public void testSegmentPartitionConfig()
throws IOException {
int numColumns = 5;
Map<String, ColumnPartitionConfig> expectedColumnPartitionMap = new HashMap<>(5);
for (int i = 0; i < numColumns; i++) {
expectedColumnPartitionMap.put("column_" + i, new ColumnPartitionConfig("function_" + i, i + 1));
}
SegmentPartitionConfig expectedPartitionConfig = new SegmentPartitionConfig(expectedColumnPartitionMap);
IndexingConfig expectedIndexingConfig = new IndexingConfig();
expectedIndexingConfig.setSegmentPartitionConfig(expectedPartitionConfig);
IndexingConfig actualIndexingConfig =
JsonUtils.stringToObject(JsonUtils.objectToString(expectedIndexingConfig), IndexingConfig.class);
SegmentPartitionConfig actualPartitionConfig = actualIndexingConfig.getSegmentPartitionConfig();
Map<String, ColumnPartitionConfig> actualColumnPartitionMap = actualPartitionConfig.getColumnPartitionMap();
assertEquals(actualColumnPartitionMap.size(), expectedColumnPartitionMap.size());
for (String column : expectedColumnPartitionMap.keySet()) {
assertEquals(actualPartitionConfig.getFunctionName(column), expectedPartitionConfig.getFunctionName(column));
assertEquals(actualPartitionConfig.getNumPartitions(column), expectedPartitionConfig.getNumPartitions(column));
}
}
代码示例来源:origin: apache/incubator-pinot
@Test
public void testDeserializeFromJson()
throws IOException {
Tenant tenant = new Tenant();
tenant.setTenantRole(TenantRole.SERVER);
tenant.setTenantName("newTenant");
tenant.setNumberOfInstances(10);
tenant.setOfflineInstances(5);
tenant.setRealtimeInstances(5);
tenant = JsonUtils.stringToObject(JsonUtils.objectToString(tenant), Tenant.class);
assertEquals(tenant.getTenantRole(), TenantRole.SERVER);
assertEquals(tenant.getTenantName(), "newTenant");
assertEquals(tenant.getNumberOfInstances(), 10);
assertEquals(tenant.getOfflineInstances(), 5);
assertEquals(tenant.getRealtimeInstances(), 5);
}
}
内容来源于网络,如有侵权,请联系作者删除!