Java Code Examples for org.apache.kylin.common.util.JsonUtil#readValue()

The following examples show how to use org.apache.kylin.common.util.JsonUtil#readValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AggregationGroupRuleTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: MetricsService.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
public String getMetrics(String type) throws Exception {

        if (!this.getConfig().getQueryMetrics2Enabled()) {
            throw new IllegalStateException("Please enable query metrics2");
        }

        Metrics instance = MetricsFactory.getInstance();
        String metric = null;
        if (!(instance instanceof CodahaleMetrics)) {
            throw new IllegalStateException("Please use CodahaleMetrics to collect your metrics");
        }
        try {
            metric = ((CodahaleMetrics) instance).dumpJson();
            if (StringUtils.isNotBlank(type)) {
                Map<String, Object> map = JsonUtil.readValue(metric, new TypeReference<Map<String, Object>>() {
                });
                metric = String.valueOf(map.get(type));
            }
        } catch (Exception e) {
            LOG.error("Dump metric json error, ", e);
        }
        return metric;
    }
 
Example 3
Source File: DictsReader.java    From kylin with Apache License 2.0 6 votes vote down vote up
public ImmutableMap<String, Dictionary> readDicts() throws IOException {
    metaInputStream = fs.open(metaFilePath);
    FragmentMetaInfo fragmentMetaInfo = JsonUtil.readValue(metaInputStream, FragmentMetaInfo.class);
    List<DimDictionaryMetaInfo> dimDictMetaInfos = fragmentMetaInfo.getDimDictionaryMetaInfos();
    ImmutableMap.Builder<String, Dictionary> builder = ImmutableMap.<String, Dictionary> builder();
    dataInputStream = fs.open(dataFilePath);
    Dictionary dict;
    String colName;
    logger.info("Reading dictionary from {}", dataFilePath.getName());
    for (DimDictionaryMetaInfo dimDictMetaInfo : dimDictMetaInfos) {
        dataInputStream.seek(dimDictMetaInfo.getStartOffset());
        dict = DictionarySerializer.deserialize(dataInputStream);
        colName = dimDictMetaInfo.getDimName();
        logger.info("Add dict for {}", colName);
        builder.put(colName, dict);
    }
    return builder.build();
}
 
Example 4
Source File: ZookeeperStreamMetadataStore.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public ReplicaSet getReplicaSet(int rsID) {
    try {
        ReplicaSet result = new ReplicaSet();
        result.setReplicaSetID(rsID);
        byte[] replicaSetData = client.getData().forPath(ZKPaths.makePath(replicaSetRoot, String.valueOf(rsID)));
        if (replicaSetData != null && replicaSetData.length > 0) {
            result = JsonUtil.readValue(Bytes.toString(replicaSetData), ReplicaSet.class);
        }
        readSuccess.getAndIncrement();
        return result;
    } catch (Exception e) {
        readFail.getAndIncrement();
        logger.error("Error when get replica set " + rsID, e);
        throw new StoreException(e);
    }
}
 
Example 5
Source File: DictionaryRuleTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
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));
    }
}
 
Example 6
Source File: ZookeeperStreamMetadataStore.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public Node getCoordinatorNode() {
    try {
        byte[] nodeData = client.getData().forPath(coordinatorRoot);
        readSuccess.getAndIncrement();
        return JsonUtil.readValue(nodeData, Node.class);
    } catch (Exception e) {
        readFail.getAndIncrement();
        logger.error("Error when get coordinator leader", e);
        throw new StoreException(e);
    }
}
 
Example 7
Source File: FunctionRuleTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testGoodDesc() throws IOException {
    FunctionRule rule = new FunctionRule();

    File f = new File(LocalFileMetadataTestCase.LOCALMETA_TEST_DATA + "/cube_desc/ssb.json");
    CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class);
    desc.init(config);
    ValidateContext vContext = new ValidateContext();
    rule.validate(desc, vContext);
    vContext.print(System.out);
    assertTrue(vContext.getResults().length == 0);
}
 
Example 8
Source File: ExternalFilterController.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/saveExtFilter", method = { RequestMethod.POST }, produces = { "application/json" })
@ResponseBody
public Map<String, String> saveExternalFilter(@RequestBody ExternalFilterRequest request) throws IOException {
    Map<String, String> result = new HashMap();
    String filterProject = request.getProject();
    ExternalFilterDesc desc = JsonUtil.readValue(request.getExtFilter(), ExternalFilterDesc.class);
    desc.setUuid(RandomUtil.randomUUID().toString());
    extFilterService.saveExternalFilter(desc);
    extFilterService.syncExtFilterToProject(new String[] { desc.getName() }, filterProject);
    result.put("success", "true");
    return result;
}
 
Example 9
Source File: AggregationGroupRuleTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testBadDesc2() throws IOException {

    ValidateContext vContext = new ValidateContext();
    CubeDesc desc = JsonUtil.readValue(new FileInputStream(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA + "/cube_desc/test_kylin_cube_with_slr_desc.json"), CubeDesc.class);
    desc.getAggregationGroups().get(0).getSelectRule().jointDims = new String[][] { //
            new String[] { "lstg_format_name", "lstg_site_id", "slr_segment_cd", "META_CATEG_NAME", "CATEG_LVL2_NAME" } };

    IValidatorRule<CubeDesc> rule = getAggregationGroupRule();
    rule.validate(desc, vContext);
    //vContext.print(System.out);
    assertEquals(2, vContext.getResults().length);
    assertEquals("Aggregation group 1 joint dimensions has overlap with more than 1 dimensions in same hierarchy: [CATEG_LVL2_NAME, META_CATEG_NAME]", (vContext.getResults()[0].getMessage()));
}
 
Example 10
Source File: RowKeyAttrRuleTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testGoodDesc() throws IOException {
    for (File f : new File(LocalFileMetadataTestCase.LOCALMETA_TEST_DATA + "/cube_desc/").listFiles()) {
        CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class);
        ValidateContext vContext = new ValidateContext();
        IValidatorRule<CubeDesc> rule = new RowKeyAttrRule();
        rule.validate(desc, vContext);
        vContext.print(System.out);
        assertTrue(vContext.getResults().length == 0);
    }
}
 
Example 11
Source File: FragmentFilesMergerTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testMergeWithAdditionalCuboids() throws Exception {
    setBuildAdditionalCuboids();
    StreamingDataSimulator simulator = new StreamingDataSimulator(getTestCardinalityMap(), 200000);
    List<DataSegmentFragment> fragments = createFragmentFiles(9, 3, simulator);
    FragmentsMergeResult mergeResult = fragmentFilesMerger.merge(fragments);
    File mergedFragmentMetaFile = mergeResult.getMergedFragmentMetaFile();
    File mergedFragmentDataFile = mergeResult.getMergedFragmentDataFile();
    FragmentMetaInfo fragmentMetaInfo = JsonUtil.readValue(mergedFragmentMetaFile, FragmentMetaInfo.class);
    assertEquals(160010, fragmentMetaInfo.getNumberOfRows());
}
 
Example 12
Source File: AggregationGroupRuleTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testBadDesc1() throws IOException {

    ValidateContext vContext = new ValidateContext();
    CubeDesc desc = JsonUtil.readValue(new FileInputStream(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA + "/cube_desc/test_kylin_cube_with_slr_desc.json"), CubeDesc.class);
    String[] temp = Arrays.asList(desc.getAggregationGroups().get(0).getIncludes()).subList(0, 3).toArray(new String[3]);

    desc.getAggregationGroups().get(0).setIncludes(temp);
    IValidatorRule<CubeDesc> rule = getAggregationGroupRule();
    rule.validate(desc, vContext);
    //vContext.print(System.out);
    assertEquals(1, vContext.getResults().length);
    assertEquals("Aggregation group 1 'includes' dimensions not include all the dimensions:[seller_id, META_CATEG_NAME, lstg_format_name, lstg_site_id, slr_segment_cd]", (vContext.getResults()[0].getMessage()));
}
 
Example 13
Source File: HttpReceiverAdminClient.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public ConsumerStatsResponse resumeConsumers(Node receiver, ResumeConsumerRequest resumeRequest) throws IOException {
    logger.info("send resume consumer request:{} to receiver:{}", resumeRequest, receiver);
    String url = "http://" + receiver.getHost() + ":" + receiver.getPort() + "/kylin/api/admin/consumers/resume";
    String content = JsonUtil.writeValueAsString(resumeRequest);
    String retMsg = retryPostRequest(url, content);
    return JsonUtil.readValue(retMsg, ConsumerStatsResponse.class);
}
 
Example 14
Source File: RowKeyAttrRuleTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testGoodDesc() throws IOException {
    for (File f : new File(LocalFileMetadataTestCase.LOCALMETA_TEST_DATA + "/cube_desc/").listFiles()) {
        CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class);
        ValidateContext vContext = new ValidateContext();
        IValidatorRule<CubeDesc> rule = new RowKeyAttrRule();
        rule.validate(desc, vContext);
        vContext.print(System.out);
        assertTrue(vContext.getResults().length == 0);
    }
}
 
Example 15
Source File: HttpReceiverAdminClient.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public ReceiverCubeStats getReceiverCubeStats(Node receiver, String cubeName) throws IOException {
    logger.info("send request to receiver:{} to get cube stats for cube:{}", receiver, cubeName);
    String url = "http://" + receiver.getHost() + ":" + receiver.getPort() + "/kylin/api/stats/cubes/" + cubeName;

    String msg = retryGetRequest(url);
    return JsonUtil.readValue(msg, ReceiverCubeStats.class);
}
 
Example 16
Source File: CubeDescTest.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerialize() throws Exception {
    CubeDesc desc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("test_kylin_cube_with_slr_desc");
    String str = JsonUtil.writeValueAsIndentString(desc);
    System.out.println(str);
    @SuppressWarnings("unused")
    CubeDesc desc2 = JsonUtil.readValue(str, CubeDesc.class);
}
 
Example 17
Source File: CubeDescTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerialize() throws Exception {
    CubeDesc desc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC);
    String str = JsonUtil.writeValueAsIndentString(desc);
    //System.out.println(str);
    @SuppressWarnings("unused")
    CubeDesc desc2 = JsonUtil.readValue(str, CubeDesc.class);
}
 
Example 18
Source File: ProjectController.java    From kylin with Apache License 2.0 5 votes vote down vote up
private ProjectInstance deserializeProjectDesc(ProjectRequest projectRequest) {
    ProjectInstance projectDesc = null;
    try {
        logger.debug("Saving project " + projectRequest.getProjectDescData());
        projectDesc = JsonUtil.readValue(projectRequest.getProjectDescData(), ProjectInstance.class);
    } catch (Exception e) {
        logger.error("Failed to deal with the request.", e);
        throw new InternalErrorException("Failed to deal with the request:" + e.getMessage(), e);
    }
    return projectDesc;
}
 
Example 19
Source File: JsonSerializer.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public T deserialize(DataInputStream in) throws IOException {
    return JsonUtil.readValue(in, clz);
}
 
Example 20
Source File: CubeDescTest.java    From Kylin with Apache License 2.0 4 votes vote down vote up
@Test
public void testSerializeMap()  throws Exception {
    Map<String, String> map = Maps.newHashMap();

    map.put("key1", "value1");
    map.put("key2", "value2");
    
    String mapStr = JsonUtil.writeValueAsString(map);
    
    System.out.println(mapStr);
    
    Map<?, ?> map2 = JsonUtil.readValue(mapStr, HashMap.class);
    
    Assert.assertEquals(map, map2);
    
}