org.apache.kylin.common.util.JsonUtil Java Examples

The following examples show how to use org.apache.kylin.common.util.JsonUtil. 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: 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 #2
Source File: ModelController.java    From kylin with Apache License 2.0 6 votes vote down vote up
@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(), e);
    }

    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;
}
 
Example #3
Source File: DumpDictionaryCLI.java    From kylin with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #4
Source File: ZookeeperStreamMetadataStore.java    From kylin with Apache License 2.0 6 votes vote down vote up
private SegmentBuildState doGetSegmentBuildState(String cubePath, String segmentName) throws Exception {
    SegmentBuildState segmentState = new SegmentBuildState(segmentName);
    String segmentPath = ZKPaths.makePath(cubePath, segmentName);
    byte[] stateBytes = client.getData().forPath(segmentPath);
    readSuccess.getAndIncrement();
    SegmentBuildState.BuildState state;
    if (stateBytes != null && stateBytes.length > 0) {
        String stateStr = Bytes.toString(stateBytes);
        state = JsonUtil.readValue(stateStr, SegmentBuildState.BuildState.class);
        segmentState.setState(state);
    }
    String replicaSetsPath = ZKPaths.makePath(segmentPath, "replica_sets");
    List<String> replicaSets = client.getChildren().forPath(replicaSetsPath);
    for (String replicaSetID : replicaSets) {
        segmentState.addCompleteReplicaSet(Integer.valueOf(replicaSetID));
    }
    return segmentState;
}
 
Example #5
Source File: AggregationGroupRuleTest.java    From kylin-on-parquet-v2 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 #6
Source File: BadQueryHistoryManagerTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #7
Source File: StreamingControllerTest.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@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(Locale.ROOT), desc.getName());
    Assert.assertEquals("my_database_name".toUpperCase(Locale.ROOT), desc.getDatabase());
}
 
Example #8
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 #9
Source File: DictionaryManager.java    From kylin with Apache License 2.0 6 votes vote down vote up
public DictionaryInfo buildDictionary(TblColRef col, IReadableTable inpTable, String builderClass)
        throws IOException {
    if (!inpTable.exists())
        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 {}, reuse existing dictionary at {}", dictInfo.getInput(), dupInfo);
        DictionaryInfo dupDictInfo = updateExistingDictLastModifiedTime(dupInfo);
        return dupDictInfo;
    }

    logger.info("Building dictionary object {}", JsonUtil.writeValueAsString(dictInfo));

    Dictionary<String> dictionary;
    dictionary = buildDictFromReadableTable(inpTable, dictInfo, builderClass, col);
    return trySaveNewDict(dictionary, dictInfo);
}
 
Example #10
Source File: ZookeeperStreamMetadataStore.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private SegmentBuildState doGetSegmentBuildState(String cubePath, String segmentName) throws Exception {
    SegmentBuildState segmentState = new SegmentBuildState(segmentName);
    String segmentPath = ZKPaths.makePath(cubePath, segmentName);
    byte[] stateBytes = client.getData().forPath(segmentPath);
    readSuccess.getAndIncrement();
    SegmentBuildState.BuildState state;
    if (stateBytes != null && stateBytes.length > 0) {
        String stateStr = Bytes.toString(stateBytes);
        state = JsonUtil.readValue(stateStr, SegmentBuildState.BuildState.class);
        segmentState.setState(state);
    }
    String replicaSetsPath = ZKPaths.makePath(segmentPath, "replica_sets");
    List<String> replicaSets = client.getChildren().forPath(replicaSetsPath);
    for (String replicaSetID : replicaSets) {
        segmentState.addCompleteReplicaSet(Integer.valueOf(replicaSetID));
    }
    return segmentState;
}
 
Example #11
Source File: ZookeeperStreamMetadataStore.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public void saveStreamingCubeConsumeState(String cube, StreamingCubeConsumeState state) {
    checkPath(cube);
    try {
        String path = getCubeConsumeStatePath(cube);
        if (client.checkExists().forPath(path) != null) {
            client.setData().forPath(path, JsonUtil.writeValueAsBytes(state));
        } else {
            client.create().creatingParentsIfNeeded().forPath(path, JsonUtil.writeValueAsBytes(state));
        }
        writeSuccess.getAndIncrement();
    } catch (Exception e) {
        writeFail.getAndIncrement();
        logger.error("Error when save streaming cube consume state " + cube + " with " + state, e);
        throw new StoreException(e);
    }
}
 
Example #12
Source File: AggregationGroupRuleTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
@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"));
    }
}
 
Example #13
Source File: DumpDictionaryCLI.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #14
Source File: DictsReader.java    From kylin-on-parquet-v2 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 #15
Source File: ModelController.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@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(), e);
    }

    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;
}
 
Example #16
Source File: ZookeeperStreamMetadataStore.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public StreamingCubeConsumeState getStreamingCubeConsumeState(String cube) {
    try {
        String path = getCubeConsumeStatePath(cube);
        if (client.checkExists().forPath(path) != null) {
            byte[] cubeInfoData = client.getData().forPath(path);
            readSuccess.getAndIncrement();
            if (cubeInfoData != null && cubeInfoData.length > 0) {
                return JsonUtil.readValue(cubeInfoData, StreamingCubeConsumeState.class);
            } else {
                return StreamingCubeConsumeState.RUNNING;
            }
        } else {
            return StreamingCubeConsumeState.RUNNING;
        }
    } catch (Exception e) {
        readFail.getAndIncrement();
        logger.error("Error when get streaming cube consume state " + cube, e);
        throw new StoreException(e);
    }
}
 
Example #17
Source File: MetadataManager.java    From Kylin with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #18
Source File: KafkaPositionHandler.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public ISourcePosition parsePosition(String positionStr) {
    try {
        Map<Integer, Long> partitionOffsetMap = JsonUtil.readValue(positionStr,
                new TypeReference<Map<Integer, Long>>() {
                });
        return new KafkaPosition(partitionOffsetMap);
    } catch (IOException e) {
        throw new StreamingException(e);
    }
}
 
Example #19
Source File: TableService.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public TableDesc generateCsvTableDesc(String tableName, List<String> columnDescList) throws IOException {
    String[] strs = tableName.split("\\.");
    if (strs.length != 2) {
        throw new IllegalArgumentException("Invalid table name + '" + tableName + "'");
    }
    TableDesc tableDesc = new TableDesc();

    tableDesc.setDatabase(strs[0]);
    tableDesc.setName(strs[1]);
    tableDesc.setUuid(RandomUtil.randomUUID().toString());
    tableDesc.setLastModified(0);
    tableDesc.setSourceType(ISourceAware.ID_SPARK);
    List<ColumnDesc> columnDescs = new ArrayList<>();
    int index = 0;

    for (String csvColumnDescStr : columnDescList) {
        index++;
        ColumnDesc columnDesc = new ColumnDesc();
        CsvColumnDesc csvColumnDesc = JsonUtil.readValue(csvColumnDescStr, CsvColumnDesc.class);
        columnDesc.setId("" + index);
        columnDesc.setName((csvColumnDesc).getName());
        columnDesc.setDatatype((csvColumnDesc).getType());
        columnDescs.add(columnDesc);
    }

    tableDesc.setColumns(columnDescs.toArray(new ColumnDesc[columnDescs.size()]));

    return tableDesc;
}
 
Example #20
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 #21
Source File: FragmentFilesMergerTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testMerge2() throws Exception {
    int fragmentNum = 4;
    int eventCntPerMin = 100000;
    StreamingDataSimulator simulator = new StreamingDataSimulator(getTestCardinalityMap(), eventCntPerMin);
    List<DataSegmentFragment> fragments = createFragmentFiles(5, fragmentNum, simulator);
    int originRowCnt = fragmentNum * 50000;
    FragmentsMergeResult mergeResult = fragmentFilesMerger.merge(fragments);
    File mergedFragmentMetaFile = mergeResult.getMergedFragmentMetaFile();
    File mergedFragmentDataFile = mergeResult.getMergedFragmentDataFile();
    FragmentMetaInfo fragmentMetaInfo = JsonUtil.readValue(mergedFragmentMetaFile, FragmentMetaInfo.class);
    assertEquals(160000, fragmentMetaInfo.getNumberOfRows());
    assertEquals(originRowCnt, fragmentMetaInfo.getOriginNumOfRows());

    FragmentData fragmentData = new FragmentData(fragmentMetaInfo, mergedFragmentDataFile);
    Set<TblColRef> dims = testHelper.simulateDimensions("STREAMING_V2_TABLE.MINUTE_START");
    TupleFilter siteFilter = null;
    Set<TblColRef> groups = testHelper.simulateDimensions("STREAMING_V2_TABLE.MINUTE_START");
    Set<FunctionDesc> metrics = Sets.newHashSet(testHelper.simulateCountMetric());

    StreamingQueryProfile.set(new StreamingQueryProfile("test-query-id", System.currentTimeMillis()));
    DataSegmentFragment fragment = new DataSegmentFragment(baseStorePath, cubeName, segmentName, new FragmentId(0));
    FragmentFileSearcher fragmentFileSearcher = new FragmentFileSearcher(fragment, fragmentData);
    StreamingSearchContext searchRequest = new StreamingSearchContext(parsedStreamingCubeInfo.cubeDesc, dims,
            groups, metrics, siteFilter, null);
    ResultCollector resultCollector = new SingleThreadResultCollector();
    fragmentFileSearcher.search(searchRequest, resultCollector);
    int rowCnt = 0;
    int totalOriginCnt = 0;
    for (Record record : resultCollector) {
        rowCnt++;
        long everyMinuteCnt = (Long) record.getMetrics()[0];
        assertEquals(eventCntPerMin, (int) everyMinuteCnt);
        System.out.println(record);
        totalOriginCnt += everyMinuteCnt;
    }
    assertEquals(2, rowCnt);
    assertEquals(originRowCnt, totalOriginCnt);
}
 
Example #22
Source File: DictionaryRuleTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testGoodDesc() throws IOException {
    DictionaryRule rule = new DictionaryRule();

    for (File f : new File(LocalFileMetadataTestCase.LOCALMETA_TEST_DATA + "/cube_desc/").listFiles()) {
        if (!f.getName().endsWith("json")) {
            continue;
        }
        CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class);
        desc.init(config);
        ValidateContext vContext = new ValidateContext();
        rule.validate(desc, vContext);
        assertTrue(vContext.getResults().length == 0);
    }
}
 
Example #23
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 #24
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 #25
Source File: CubeInstance.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public void setCuboidsRecommend(Set<Long> cuboids) {
    if (cuboids == null)
        return;
    if (cuboids.isEmpty()) {
        cuboidBytesRecommend = null;
        return;
    }
    try {
        String str = JsonUtil.writeValueAsString(cuboids);
        byte[] compressed = CompressionUtils.compress(str.getBytes(StandardCharsets.UTF_8));
        cuboidBytesRecommend = compressed;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #26
Source File: CubeInstance.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public Set<Long> getCuboidsRecommend() {
    if (cuboidBytesRecommend == null)
        return null;
    byte[] uncompressed;
    try {
        uncompressed = CompressionUtils.decompress(cuboidBytesRecommend);
        String str = new String(uncompressed, StandardCharsets.UTF_8);
        TypeReference<Set<Long>> typeRef = new TypeReference<Set<Long>>() {
        };
        Set<Long> cuboids = JsonUtil.readValue(str, typeRef);
        return cuboids.isEmpty() ? null : cuboids;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #27
Source File: MemcachedCache.java    From kylin with Apache License 2.0 5 votes vote down vote up
protected String serializeKey(Object key) {
    try {
        return JsonUtil.writeValueAsString(key);
    } catch (JsonProcessingException e) {
        logger.warn("Can not convert key to String.", e);
    }
    return null;
}
 
Example #28
Source File: SnapshotTableSerializer.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public SnapshotTable deserialize(DataInputStream in) throws IOException {
    String json = in.readUTF();
    SnapshotTable obj = JsonUtil.readValue(json, SnapshotTable.class);

    if (infoOnly == false)
        obj.readData(in);

    return obj;
}
 
Example #29
Source File: HttpReceiverAdminClient.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public ReceiverStats getReceiverStats(Node receiver) throws IOException {
    logger.info("send request to receiver:{} to get receiver stats ", receiver);
    String url = "http://" + receiver.getHost() + ":" + receiver.getPort() + "/kylin/api/stats";

    String msg = restService.getRequest(url);
    return JsonUtil.readValue(msg, ReceiverStats.class);

}
 
Example #30
Source File: HttpReceiverAdminClient.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public void assign(Node receiver, AssignRequest assignRequest) throws IOException {
    logger.info("send assign request:{} to receiver:{}", assignRequest, receiver);
    final String url = "http://" + receiver.getHost() + ":" + receiver.getPort() + "/kylin/api/admin/assign";
    final String content = JsonUtil.writeValueAsString(assignRequest);

    retryPostRequest(url, content);
}