org.apache.kylin.dict.DictionaryInfoSerializer Java Examples

The following examples show how to use org.apache.kylin.dict.DictionaryInfoSerializer. 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: 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 #2
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 #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()) {
        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();
    }
}
 
Example #4
Source File: DstClusterUtil.java    From kylin with Apache License 2.0 5 votes vote down vote up
public String saveDictionary(DictionaryInfo dictInfo) throws IOException {
    String dupDict = checkDupDict(dictInfo);
    if (dupDict == null) {
        putMetaResource(dictInfo.getResourcePath(), dictInfo, DictionaryInfoSerializer.FULL_SERIALIZER);
        logger.info("saved dictionary {}", dictInfo.getResourcePath());
    }
    return dupDict;
}
 
Example #5
Source File: MergeDictReducer.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@Override
protected void doReduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
    String col = key.toString();
    logger.info("merge dictionary for column:{}", col);
    TblColRef tblColRef = colNeedDictMap.get(col);

    if (tblColRef == null) {
        logger.warn("column:{} not found in the columns need dictionary map: {}", col, colNeedDictMap.keySet());
        return;
    }

    DataType dataType = tblColRef.getType();
    List<Dictionary<String>> dicts = Lists.newLinkedList();
    for (Text value : values) {
        ByteArray byteArray = new ByteArray(value.getBytes());
        Dictionary<String> dict = (Dictionary<String>) DictionarySerializer.deserialize(byteArray);
        dicts.add(dict);
    }
    Dictionary mergedDict;
    if (dicts.size() > 1) {
        MultipleDictionaryValueEnumerator multipleDictionaryValueEnumerator = new MultipleDictionaryValueEnumerator(
                dataType, dicts);
        mergedDict = DictionaryGenerator.buildDictionary(dataType, multipleDictionaryValueEnumerator);
    } else if (dicts.size() == 1) {
        mergedDict = dicts.get(0);
    } else {
        throw new IllegalArgumentException("Dictionary missing for column " + col);
    }
    if (mergedDict == null) {
        throw new IllegalArgumentException("Merge dictionaries error for column " + col);
    }

    TableDesc tableDesc = tblColRef.getColumnDesc().getTable();
    IReadableTable.TableSignature signature = new IReadableTable.TableSignature();
    signature.setLastModifiedTime(System.currentTimeMillis());
    signature.setPath(tableDesc.getResourcePath());

    //TODO: Table signature size?
    //        signature.setSize(mergedDict.getSize());

    DictionaryInfo dictionaryInfo = new DictionaryInfo(tblColRef.getTable(), tblColRef.getName(), tblColRef
            .getColumnDesc().getZeroBasedIndex(), tblColRef.getDatatype(), signature);
    dictionaryInfo.setDictionaryObject(mergedDict);
    dictionaryInfo.setDictionaryClass(mergedDict.getClass().getName());
    dictionaryInfo.setCardinality(mergedDict.getSize());

    ByteArrayOutputStream fulBuf = new ByteArrayOutputStream();
    DataOutputStream fulDout = new DataOutputStream(fulBuf);
    DictionaryInfoSerializer.FULL_SERIALIZER.serialize(dictionaryInfo, fulDout);

    Text outValue = new Text(fulBuf.toByteArray());
    context.write(key, outValue);
    logger.debug("output dict info of column {} to path: {}", col,
            context.getConfiguration().get(FileOutputFormat.OUTDIR));
}
 
Example #6
Source File: DstClusterUtil.java    From kylin with Apache License 2.0 4 votes vote down vote up
@Override
public DictionaryInfo getDictionaryInfo(String dictPath) throws IOException {
    return resourceStore.getResource(dictPath, DictionaryInfoSerializer.FULL_SERIALIZER);
}
 
Example #7
Source File: MergeDictReducer.java    From kylin with Apache License 2.0 4 votes vote down vote up
@Override
protected void doReduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
    String col = key.toString();
    logger.info("merge dictionary for column:{}", col);
    TblColRef tblColRef = colNeedDictMap.get(col);

    if (tblColRef == null) {
        logger.warn("column:{} not found in the columns need dictionary map: {}", col, colNeedDictMap.keySet());
        return;
    }

    DataType dataType = tblColRef.getType();
    List<Dictionary<String>> dicts = Lists.newLinkedList();
    for (Text value : values) {
        ByteArray byteArray = new ByteArray(value.getBytes());
        Dictionary<String> dict = (Dictionary<String>) DictionarySerializer.deserialize(byteArray);
        dicts.add(dict);
    }
    Dictionary mergedDict;
    if (dicts.size() > 1) {
        MultipleDictionaryValueEnumerator multipleDictionaryValueEnumerator = new MultipleDictionaryValueEnumerator(
                dataType, dicts);
        mergedDict = DictionaryGenerator.buildDictionary(dataType, multipleDictionaryValueEnumerator);
    } else if (dicts.size() == 1) {
        mergedDict = dicts.get(0);
    } else {
        throw new IllegalArgumentException("Dictionary missing for column " + col);
    }
    if (mergedDict == null) {
        throw new IllegalArgumentException("Merge dictionaries error for column " + col);
    }

    TableDesc tableDesc = tblColRef.getColumnDesc().getTable();
    IReadableTable.TableSignature signature = new IReadableTable.TableSignature();
    signature.setLastModifiedTime(System.currentTimeMillis());
    signature.setPath(tableDesc.getResourcePath());

    //TODO: Table signature size?
    //        signature.setSize(mergedDict.getSize());

    DictionaryInfo dictionaryInfo = new DictionaryInfo(tblColRef.getTable(), tblColRef.getName(), tblColRef
            .getColumnDesc().getZeroBasedIndex(), tblColRef.getDatatype(), signature);
    dictionaryInfo.setDictionaryObject(mergedDict);
    dictionaryInfo.setDictionaryClass(mergedDict.getClass().getName());
    dictionaryInfo.setCardinality(mergedDict.getSize());

    ByteArrayOutputStream fulBuf = new ByteArrayOutputStream();
    DataOutputStream fulDout = new DataOutputStream(fulBuf);
    DictionaryInfoSerializer.FULL_SERIALIZER.serialize(dictionaryInfo, fulDout);

    Text outValue = new Text(fulBuf.toByteArray());
    context.write(key, outValue);
    logger.debug("output dict info of column {} to path: {}", col,
            context.getConfiguration().get(FileOutputFormat.OUTDIR));
}