本文整理汇总了Java中org.apache.kylin.common.util.JsonUtil类的典型用法代码示例。如果您正苦于以下问题:Java JsonUtil类的具体用法?Java JsonUtil怎么用?Java JsonUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JsonUtil类属于org.apache.kylin.common.util包,在下文中一共展示了JsonUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getKylinProperties
import org.apache.kylin.common.util.JsonUtil; //导入依赖的package包/类
public String getKylinProperties() throws IOException {
String url = baseUrl + "/admin/config";
HttpGet request = new HttpGet(url);
HttpResponse response = null;
try {
response = client.execute(request);
String msg = EntityUtils.toString(response.getEntity());
Map<String, String> map = JsonUtil.readValueAsMap(msg);
msg = map.get("config");
if (response.getStatusLine().getStatusCode() != 200)
throw new IOException("Invalid response " + response.getStatusLine().getStatusCode()
+ " with cache wipe url " + url + "\n" + msg);
return msg;
} finally {
cleanup(request, response);
}
}
示例2: testBasics
import org.apache.kylin.common.util.JsonUtil; //导入依赖的package包/类
@Test
public void testBasics() throws Exception {
BadQueryHistory history = BadQueryHistoryManager.getInstance(getTestConfig())
.getBadQueriesForProject("default");
System.out.println(JsonUtil.writeValueAsIndentString(history));
NavigableSet<BadQueryEntry> entries = history.getEntries();
assertEquals(3, entries.size());
BadQueryEntry entry1 = entries.first();
assertEquals("Pushdown", entry1.getAdj());
assertEquals("sandbox.hortonworks.com", entry1.getServer());
assertEquals("select * from test_kylin_fact limit 10", entry1.getSql());
entries.pollFirst();
BadQueryEntry entry2 = entries.first();
assertTrue(entry2.getStartTime() > entry1.getStartTime());
}
示例3: buildDictionary
import org.apache.kylin.common.util.JsonUtil; //导入依赖的package包/类
public DictionaryInfo buildDictionary(TblColRef col, IReadableTable inpTable, String builderClass) throws IOException {
if (inpTable.exists() == false)
return null;
logger.info("building dictionary for " + col);
DictionaryInfo dictInfo = createDictionaryInfo(col, inpTable);
String dupInfo = checkDupByInfo(dictInfo);
if (dupInfo != null) {
logger.info("Identical dictionary input " + dictInfo.getInput() + ", reuse existing dictionary at " + dupInfo);
return getDictionaryInfo(dupInfo);
}
logger.info("Building dictionary object " + JsonUtil.writeValueAsString(dictInfo));
Dictionary<String> dictionary;
dictionary = buildDictFromReadableTable(inpTable, dictInfo, builderClass, col);
return trySaveNewDict(dictionary, dictInfo);
}
示例4: setCuboids
import org.apache.kylin.common.util.JsonUtil; //导入依赖的package包/类
public void setCuboids(Map<Long, Long> cuboids) {
if (cuboids == null)
return;
if (cuboids.isEmpty()) {
cuboidBytes = null;
return;
}
try {
String str = JsonUtil.writeValueAsString(cuboids);
byte[] compressed = CompressionUtils.compress(str.getBytes("UTF-8"));
cuboidBytes = compressed;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例5: dump
import org.apache.kylin.common.util.JsonUtil; //导入依赖的package包/类
public static void dump(File f) throws IOException {
if (f.isDirectory()) {
File[] files = f.listFiles();
if (files == null) {
return;
}
for (File c : files)
dump(c);
return;
}
if (f.getName().endsWith(".dict")) {
DictionaryInfoSerializer ser = new DictionaryInfoSerializer();
DictionaryInfo dictInfo = ser.deserialize(new DataInputStream(new FileInputStream(f)));
System.out.println("============================================================================");
System.out.println("File: " + f.getAbsolutePath());
System.out.println(new Date(dictInfo.getLastModified()));
System.out.println(JsonUtil.writeValueAsIndentString(dictInfo));
dictInfo.getDictionaryObject().dump(System.out);
System.out.println();
}
}
示例6: testGoodDesc
import org.apache.kylin.common.util.JsonUtil; //导入依赖的package包/类
@Test
public void testGoodDesc() throws IOException {
AggregationGroupRule rule = getAggregationGroupRule();
for (File f : new File(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA + "/cube_desc/").listFiles()) {
if (!f.getName().endsWith("json")) {
continue;
}
CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class);
desc.init(getTestConfig());
ValidateContext vContext = new ValidateContext();
rule.validate(desc, vContext);
//vContext.print(System.out);
assertTrue(vContext.getResults().length == 0);
}
}
示例7: testGoodBecomeBadDesc
import org.apache.kylin.common.util.JsonUtil; //导入依赖的package包/类
@Test
public void testGoodBecomeBadDesc() throws IOException {
AggregationGroupRule rule = new AggregationGroupRule() {
@Override
protected long getMaxCombinations(CubeDesc cubeDesc) {
return 2;
}
};
for (File f : new File(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA + "/cube_desc/").listFiles()) {
System.out.println(f.getName());
CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class);
try {
desc.init(getTestConfig());
} catch (Exception e) {
// Ignore any exception here, validation may fail for bad json
}
ValidateContext vContext = new ValidateContext();
rule.validate(desc, vContext);
//vContext.print(System.out);
assertTrue(vContext.getResults().length > 0);
assertTrue(vContext.getResults()[0].getMessage().startsWith("Aggregation group 1 has too many combinations"));
}
}
示例8: testCombinationIntOverflow
import org.apache.kylin.common.util.JsonUtil; //导入依赖的package包/类
@Test
public void testCombinationIntOverflow() throws IOException {
for (File f : new File(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA + "/cube_desc/").listFiles()) {
if (f.getName().endsWith("bad")) {
String path = f.getPath();
f.renameTo(new File(path.substring(0, path.length() - 4)));
}
}
ValidateContext vContext = new ValidateContext();
CubeDesc desc = JsonUtil.readValue(new FileInputStream(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA + "/cube_desc/ut_cube_desc_combination_int_overflow.json"), CubeDesc.class);
IValidatorRule<CubeDesc> rule = getAggregationGroupRule();
try {
desc.init(getTestConfig());
} catch (Exception ex) {
// as it's a failure case, it should throw exception
}
rule.validate(desc, vContext);
assertEquals(1, vContext.getResults().length);
}
示例9: testDictionaryDesc
import org.apache.kylin.common.util.JsonUtil; //导入依赖的package包/类
private void testDictionaryDesc(String expectMessage, DictionaryDesc... descs) throws IOException {
DictionaryRule rule = new DictionaryRule();
File f = new File(LocalFileMetadataTestCase.LOCALMETA_TEST_DATA + "/cube_desc/test_kylin_cube_without_slr_left_join_desc.json");
CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class);
List<DictionaryDesc> newDicts = Lists.newArrayList(desc.getDictionaries());
for (DictionaryDesc dictDesc : descs) {
newDicts.add(dictDesc);
}
desc.setDictionaries(newDicts);
desc.init(config);
ValidateContext vContext = new ValidateContext();
rule.validate(desc, vContext);
if (expectMessage == null) {
assertTrue(vContext.getResults().length == 0);
} else {
assertTrue(vContext.getResults().length == 1);
String actualMessage = vContext.getResults()[0].getMessage();
assertTrue(actualMessage.startsWith(expectMessage));
}
}
示例10: updateModelDesc
import org.apache.kylin.common.util.JsonUtil; //导入依赖的package包/类
@RequestMapping(value = "", method = { RequestMethod.PUT }, produces = { "application/json" })
@ResponseBody
public ModelRequest updateModelDesc(@RequestBody ModelRequest modelRequest) throws JsonProcessingException {
DataModelDesc modelDesc = deserializeDataModelDesc(modelRequest);
if (modelDesc == null) {
return modelRequest;
}
try {
modelDesc = modelService.updateModelAndDesc(modelRequest.getProject(), modelDesc);
} catch (AccessDeniedException accessDeniedException) {
throw new ForbiddenException("You don't have right to update this model.");
} catch (Exception e) {
logger.error("Failed to deal with the request:" + e.getLocalizedMessage(), e);
throw new InternalErrorException("Failed to deal with the request: " + e.getLocalizedMessage());
}
if (modelDesc.getError().isEmpty()) {
modelRequest.setSuccessful(true);
} else {
logger.warn("Model " + modelDesc.getName() + " fail to update because " + modelDesc.getError());
updateRequest(modelRequest, false, omitMessage(modelDesc.getError()));
}
String descData = JsonUtil.writeValueAsIndentString(modelDesc);
modelRequest.setModelDescData(descData);
return modelRequest;
}
示例11: testReadTableDesc
import org.apache.kylin.common.util.JsonUtil; //导入依赖的package包/类
@Test
public void testReadTableDesc() throws IOException {
String requestTableData = "{\"name\":\"my_table_name\",\"source_type\":1,\"columns\":[{\"id\":1,\"name\":" +
"\"amount\",\"datatype\":\"decimal\"},{\"id\":2,\"name\":\"category\",\"datatype\":\"varchar(256)\"}," +
"{\"id\":3,\"name\":\"order_time\",\"datatype\":\"timestamp\"},{\"id\":4,\"name\":\"device\"," +
"\"datatype\":\"varchar(256)\"},{\"id\":5,\"name\":\"qty\",\"datatype\":\"int\"},{\"id\":6,\"name\":" +
"\"user_id\",\"datatype\":\"varchar(256)\"},{\"id\":7,\"name\":\"user_age\",\"datatype\":\"int\"}," +
"{\"id\":8,\"name\":\"user_gender\",\"datatype\":\"varchar(256)\"},{\"id\":9,\"name\":\"currency\"," +
"\"datatype\":\"varchar(256)\"},{\"id\":10,\"name\":\"country\",\"datatype\":\"varchar(256)\"}," +
"{\"id\":11,\"name\":\"year_start\",\"datatype\":\"date\"},{\"id\":12,\"name\":\"quarter_start\"," +
"\"datatype\":\"date\"},{\"id\":13,\"name\":\"month_start\",\"datatype\":\"date\"},{\"id\":14," +
"\"name\":\"week_start\",\"datatype\":\"date\"},{\"id\":15,\"name\":\"day_start\",\"datatype\":" +
"\"date\"},{\"id\":16,\"name\":\"hour_start\",\"datatype\":\"timestamp\"},{\"id\":17,\"name\":" +
"\"minute_start\",\"datatype\":\"timestamp\"}],\"database\":\"my_database_name\"}";
TableDesc desc = JsonUtil.readValue(requestTableData, TableDesc.class);
String[] dbTable = HadoopUtil.parseHiveTableName(desc.getIdentity());
desc.setName(dbTable[1]);
desc.setDatabase(dbTable[0]);
Assert.assertEquals("my_table_name".toUpperCase(), desc.getName());
Assert.assertEquals("my_database_name".toUpperCase(), desc.getDatabase());
}
示例12: getValue
import org.apache.kylin.common.util.JsonUtil; //导入依赖的package包/类
@Override
/**
* Event type does not belong to value part, it's for classification
*/
public byte[] getValue() {
try {
ByteArrayOutputStream baos = _localBaos.get();
if (baos == null) {
baos = new ByteArrayOutputStream();
_localBaos.set(baos);
}
baos.reset();
JsonUtil.writeValue(baos, getValueRaw());
return baos.toByteArray();
} catch (IOException e) {
throw new RuntimeException(e);//in mem, should not happen
}
}
示例13: saveTableExd
import org.apache.kylin.common.util.JsonUtil; //导入依赖的package包/类
public void saveTableExd(String tableId, Map<String, String> tableExdProperties) throws IOException {
if (tableId == null) {
throw new IllegalArgumentException("tableId couldn't be null");
}
TableDesc srcTable = srcTableMap.get(tableId);
if (srcTable == null) {
throw new IllegalArgumentException("Couldn't find Source Table with identifier: " + tableId);
}
String path = TableDesc.concatExdResourcePath(tableId);
ByteArrayOutputStream os = new ByteArrayOutputStream();
JsonUtil.writeValueIndent(os, tableExdProperties);
os.flush();
InputStream is = new ByteArrayInputStream(os.toByteArray());
getStore().putResource(path, is, System.currentTimeMillis());
os.close();
is.close();
srcTableExdMap.putLocal(tableId, tableExdProperties);
}
示例14: dump
import org.apache.kylin.common.util.JsonUtil; //导入依赖的package包/类
public static void dump(File f) throws IOException {
if (f.isDirectory()) {
for (File c : f.listFiles())
dump(c);
return;
}
if (f.getName().endsWith(".dict")) {
DictionaryInfoSerializer ser = new DictionaryInfoSerializer();
DictionaryInfo dictInfo = ser.deserialize(new DataInputStream(new FileInputStream(f)));
System.out.println("============================================================================");
System.out.println("File: " + f.getAbsolutePath());
System.out.println(new Date(dictInfo.getLastModified()));
System.out.println(JsonUtil.writeValueAsIndentString(dictInfo));
dictInfo.getDictionaryObject().dump(System.out);
System.out.println();
}
}
示例15: basic
import org.apache.kylin.common.util.JsonUtil; //导入依赖的package包/类
@Test
@Ignore("hive not ready")
public void basic() throws Exception {
CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("test_kylin_cube_without_slr_desc");
TblColRef col = cubeDesc.findColumnRef("DEFAULT.TEST_CATEGORY_GROUPINGS", "META_CATEG_NAME");
DictionaryInfo info1 = dictMgr.buildDictionary(cubeDesc.getModel(), cubeDesc.getRowkey().getDictionary(col), col, null);
System.out.println(JsonUtil.writeValueAsIndentString(info1));
DictionaryInfo info2 = dictMgr.buildDictionary(cubeDesc.getModel(), cubeDesc.getRowkey().getDictionary(col), col, null);
System.out.println(JsonUtil.writeValueAsIndentString(info2));
assertTrue(info1.getUuid() == info2.getUuid());
assertTrue(info1 == dictMgr.getDictionaryInfo(info1.getResourcePath()));
assertTrue(info2 == dictMgr.getDictionaryInfo(info2.getResourcePath()));
assertTrue(info1.getDictionaryObject() == info2.getDictionaryObject());
touchDictValues(info1);
}