Java Code Examples for org.apache.kylin.metadata.model.TblColRef#getName()

The following examples show how to use org.apache.kylin.metadata.model.TblColRef#getName() . 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: SparkFactDistinct.java    From kylin with Apache License 2.0 6 votes vote down vote up
private void outputDict(TblColRef col, Dictionary<String> dict,
        List<Tuple2<String, Tuple3<Writable, Writable, String>>> result)
        throws IOException {
    // output written to baseDir/colName/colName.rldict-r-00000 (etc)
    String dictFileName = col.getIdentity() + "/" + col.getName() + DICT_FILE_POSTFIX;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream outputStream = new DataOutputStream(baos)) {
        outputStream.writeUTF(dict.getClass().getName());
        dict.write(outputStream);

        result.add(new Tuple2<String, Tuple3<Writable, Writable, String>>(BatchConstants.CFG_OUTPUT_DICT,
                new Tuple3<Writable, Writable, String>(NullWritable.get(),
                        new ArrayPrimitiveWritable(baos.toByteArray()), dictFileName)));
    }
}
 
Example 2
Source File: FlatTableSqlQuoteUtils.java    From kylin with Apache License 2.0 6 votes vote down vote up
private static Map<String, Map<String, String>> buildTableToColumnsMap(IJoinedFlatTableDesc flatDesc) {
    Map<String, Map<String, String>> map = Maps.newHashMap();
    List<TblColRef> colRefs = flatDesc.getAllColumns();
    for (TblColRef colRef : colRefs) {
        String colName = colRef.getName();
        String tableName = colRef.getTableRef().getTableName();
        String colAlias = colRef.getTableAlias() + "_" + colRef.getName();
        if (map.containsKey(tableName)) {
            map.get(tableName).put(colName, colAlias);
        } else {
            Map<String, String> colToAliasMap = Maps.newHashMap();
            colToAliasMap.put(colName, colAlias);
            map.put(tableName, colToAliasMap);
        }
    }
    return map;
}
 
Example 3
Source File: SparkFactDistinct.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private void outputDict(TblColRef col, Dictionary<String> dict,
        List<Tuple2<String, Tuple3<Writable, Writable, String>>> result)
        throws IOException {
    // output written to baseDir/colName/colName.rldict-r-00000 (etc)
    String dictFileName = col.getIdentity() + "/" + col.getName() + DICT_FILE_POSTFIX;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream outputStream = new DataOutputStream(baos)) {
        outputStream.writeUTF(dict.getClass().getName());
        dict.write(outputStream);

        result.add(new Tuple2<String, Tuple3<Writable, Writable, String>>(BatchConstants.CFG_OUTPUT_DICT,
                new Tuple3<Writable, Writable, String>(NullWritable.get(),
                        new ArrayPrimitiveWritable(baos.toByteArray()), dictFileName)));
    }
}
 
Example 4
Source File: CubeSegmentTupleIterator.java    From Kylin with Apache License 2.0 5 votes vote down vote up
private String getFieldName(TblColRef column, Map<TblColRef, String> aliasMap) {
    String name = null;
    if (aliasMap != null) {
        name = aliasMap.get(column);
    }
    if (name == null) {
        name = column.getName();
    }
    return name;
}
 
Example 5
Source File: FactDistinctColumnsReducer.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private void outputDict(TblColRef col, Dictionary<String> dict) throws IOException, InterruptedException {
    // output written to baseDir/colName/colName.rldict-r-00000 (etc)
    String dictFileName = col.getIdentity() + "/" + col.getName() + DICT_FILE_POSTFIX;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream outputStream = new DataOutputStream(baos);) {
        outputStream.writeUTF(dict.getClass().getName());
        dict.write(outputStream);

        mos.write(BatchConstants.CFG_OUTPUT_DICT, NullWritable.get(),
                new ArrayPrimitiveWritable(baos.toByteArray()), dictFileName);
    }
}
 
Example 6
Source File: FactDistinctColumnsBase.java    From kylin with Apache License 2.0 5 votes vote down vote up
private void outputDict(TblColRef col, Dictionary<String> dict, Visitor visitor) throws IOException {
    // output written to baseDir/colName/colName.rldict-r-00000 (etc)
    String dictFileName = col.getIdentity() + "/" + col.getName() + DICT_FILE_POSTFIX;

    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
         DataOutputStream outputStream = new DataOutputStream(baos)) {
        outputStream.writeUTF(dict.getClass().getName());
        dict.write(outputStream);

        visitor.collect(BatchConstants.CFG_OUTPUT_DICT, NullWritable.get(),
                new ArrayPrimitiveWritable(baos.toByteArray()), dictFileName);
    }
}
 
Example 7
Source File: StorageContext.java    From Kylin with Apache License 2.0 5 votes vote down vote up
public String getFieldName(TblColRef col) {
    String name = null;
    if (aliasMap != null) {
        name = aliasMap.get(col);
    }
    if (name == null) {
        name = col.getName();
    }
    return name;
}
 
Example 8
Source File: SparkUHCDictionary.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public Tuple2<String, Tuple3<Writable, Writable, String>> call(Tuple2<Integer, List<String>> columnValues) throws Exception {
    if (initialized == false) {
        synchronized (SparkFactDistinct.class) {
            if (initialized == false) {
                init();
            }
        }
    }

    try (KylinConfig.SetAndUnsetThreadLocalConfig autoUnset = KylinConfig.setAndUnsetThreadLocalConfig(config);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         DataOutputStream outputStream = new DataOutputStream(baos)) {
        TblColRef col = uhcColumns.get(columnValues._1);
        logger.info("Processing column " + col.getName());
        if (cube.getDescriptor().getShardByColumns().contains(col)) {
            //for ShardByColumns
            builder = DictionaryGenerator.newDictionaryBuilder(col.getType());
            builder.init(null, 0, null);
        } else {
            //for GlobalDictionaryColumns
            DictionaryInfo dictionaryInfo = new DictionaryInfo(col.getColumnDesc(), col.getDatatype());
            String builderClass = cubeDesc.getDictionaryBuilderClass(col);
            builder = (IDictionaryBuilder) ClassUtil.newInstance(builderClass);
            builder.init(dictionaryInfo, 0, hdfsDir);
        }
        Iterator<String> values = columnValues._2.iterator();
        while (values.hasNext()) {
            builder.addValue(values.next());
        }
        Dictionary<String> dict = builder.build();
        String dictFileName = col.getIdentity() + "/" + col.getName() + DICT_FILE_POSTFIX;
        logger.info("Dictionary file name is " + dictFileName);

        outputStream.writeUTF(dict.getClass().getName());
        dict.write(outputStream);
        Tuple3 tuple3 = new Tuple3(NullWritable.get(), new ArrayPrimitiveWritable(baos.toByteArray()), dictFileName);
        return new Tuple2<>(BatchConstants.CFG_OUTPUT_DICT, tuple3);
    }
}
 
Example 9
Source File: CubeSegment.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public String getDictResPath(TblColRef col) {
    String r;
    String dictKey = col.getIdentity();
    r = getDictionaries().get(dictKey);

    // try Kylin v1.x dict key as well
    if (r == null) {
        String v1DictKey = col.getTable() + "/" + col.getName();
        r = getDictionaries().get(v1DictKey);
    }

    return r;
}
 
Example 10
Source File: CubeSegment.java    From kylin with Apache License 2.0 5 votes vote down vote up
public String getDictResPath(TblColRef col) {
    String r;
    String dictKey = col.getIdentity();
    r = getDictionaries().get(dictKey);

    // try Kylin v1.x dict key as well
    if (r == null) {
        String v1DictKey = col.getTable() + "/" + col.getName();
        r = getDictionaries().get(v1DictKey);
    }

    return r;
}
 
Example 11
Source File: SparkUHCDictionary.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public Tuple2<String, Tuple3<Writable, Writable, String>> call(Tuple2<Integer, List<String>> columnValues) throws Exception {
    if (initialized == false) {
        synchronized (SparkFactDistinct.class) {
            if (initialized == false) {
                init();
            }
        }
    }

    try (KylinConfig.SetAndUnsetThreadLocalConfig autoUnset = KylinConfig.setAndUnsetThreadLocalConfig(config);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         DataOutputStream outputStream = new DataOutputStream(baos)) {
        TblColRef col = uhcColumns.get(columnValues._1);
        logger.info("Processing column " + col.getName());
        if (cube.getDescriptor().getShardByColumns().contains(col)) {
            //for ShardByColumns
            builder = DictionaryGenerator.newDictionaryBuilder(col.getType());
            builder.init(null, 0, null);
        } else {
            //for GlobalDictionaryColumns
            DictionaryInfo dictionaryInfo = new DictionaryInfo(col.getColumnDesc(), col.getDatatype());
            String builderClass = cubeDesc.getDictionaryBuilderClass(col);
            builder = (IDictionaryBuilder) ClassUtil.newInstance(builderClass);
            builder.init(dictionaryInfo, 0, hdfsDir);
        }
        Iterator<String> values = columnValues._2.iterator();
        while (values.hasNext()) {
            builder.addValue(values.next());
        }
        Dictionary<String> dict = builder.build();
        String dictFileName = col.getIdentity() + "/" + col.getName() + DICT_FILE_POSTFIX;
        logger.info("Dictionary file name is " + dictFileName);

        outputStream.writeUTF(dict.getClass().getName());
        dict.write(outputStream);
        Tuple3 tuple3 = new Tuple3(NullWritable.get(), new ArrayPrimitiveWritable(baos.toByteArray()), dictFileName);
        return new Tuple2<>(BatchConstants.CFG_OUTPUT_DICT, tuple3);
    }
}
 
Example 12
Source File: OLAPNonEquiJoinRel.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public void implementRewrite(RewriteImplementor implementor) {
    implementor.visitChild(this, this.left);
    implementor.visitChild(this, this.right);

    this.rowType = this.deriveRowType();
    if (this.isTopJoin) {

        // add dynamic field
        Map<TblColRef, RelDataType> dynFields = this.context.dynamicFields;
        if (!dynFields.isEmpty()) {
            List<TblColRef> newCols = Lists.newArrayList(this.columnRowType.getAllColumns());
            List<RelDataTypeField> newFieldList = Lists.newArrayList();
            int paramIndex = this.rowType.getFieldList().size();
            for (TblColRef fieldCol : dynFields.keySet()) {
                RelDataType fieldType = dynFields.get(fieldCol);

                RelDataTypeField newField = new RelDataTypeFieldImpl(fieldCol.getName(), paramIndex++, fieldType);
                newFieldList.add(newField);

                newCols.add(fieldCol);
            }

            // rebuild row type
            RelDataTypeFactory.FieldInfoBuilder fieldInfo = getCluster().getTypeFactory().builder();
            fieldInfo.addAll(this.rowType.getFieldList());
            fieldInfo.addAll(newFieldList);
            this.rowType = getCluster().getTypeFactory().createStructType(fieldInfo);

            this.columnRowType = new ColumnRowType(newCols);
        }
    }
}
 
Example 13
Source File: TopNMeasureType.java    From kylin with Apache License 2.0 5 votes vote down vote up
private static DimensionEncoding[] getDimensionEncodings(FunctionDesc function, List<TblColRef> literalCols,
        Map<TblColRef, Dictionary<String>> dictionaryMap) {
    final DimensionEncoding[] dimensionEncodings = new DimensionEncoding[literalCols.size()];
    for (int i = 0; i < literalCols.size(); i++) {
        TblColRef colRef = literalCols.get(i);

        Pair<String, String> topNEncoding = TopNMeasureType.getEncoding(function, colRef);
        String encoding = topNEncoding.getFirst();
        String encodingVersionStr = topNEncoding.getSecond();
        if (StringUtils.isEmpty(encoding) || DictionaryDimEnc.ENCODING_NAME.equals(encoding)) {
            dimensionEncodings[i] = new DictionaryDimEnc(dictionaryMap.get(colRef));
        } else {
            int encodingVersion = 1;
            if (!StringUtils.isEmpty(encodingVersionStr)) {
                try {
                    encodingVersion = Integer.parseInt(encodingVersionStr);
                } catch (NumberFormatException e) {
                    throw new RuntimeException(TopNMeasureType.CONFIG_ENCODING_VERSION_PREFIX + colRef.getName()
                            + " has to be an integer");
                }
            }
            Object[] encodingConf = DimensionEncoding.parseEncodingConf(encoding);
            String encodingName = (String) encodingConf[0];
            String[] encodingArgs = (String[]) encodingConf[1];

            encodingArgs = DateDimEnc.replaceEncodingArgs(encoding, encodingArgs, encodingName,
                    literalCols.get(i).getType());

            dimensionEncodings[i] = DimensionEncodingFactory.create(encodingName, encodingArgs, encodingVersion);
        }
    }

    return dimensionEncodings;
}
 
Example 14
Source File: CubeSegment.java    From Kylin with Apache License 2.0 4 votes vote down vote up
private String dictKey(TblColRef col) {
    return col.getTable() + "/" + col.getName();
}
 
Example 15
Source File: OLAPAggregateRel.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
ColumnRowType buildColumnRowType() {
    buildGroups();
    buildAggregations();

    ColumnRowType inputColumnRowType = ((OLAPRel) getInput()).getColumnRowType();
    List<TblColRef> columns = new ArrayList<TblColRef>(this.rowType.getFieldCount());
    columns.addAll(this.groups);

    // Add group column indicators
    if (indicator) {
        final Set<String> containedNames = Sets.newHashSet();
        for (TblColRef groupCol : groups) {
            String base = "i$" + groupCol.getName();
            String name = base;
            int i = 0;
            while (containedNames.contains(name)) {
                name = base + "_" + i++;
            }
            containedNames.add(name);
            TblColRef indicatorCol = TblColRef.newInnerColumn(name, TblColRef.InnerDataTypeEnum.LITERAL);
            columns.add(indicatorCol);
        }
    }

    for (int i = 0; i < this.aggregations.size(); i++) {
        FunctionDesc aggFunc = this.aggregations.get(i);
        String aggOutName;
        if (aggFunc != null) {
            aggOutName = aggFunc.getRewriteFieldName();
        } else {
            AggregateCall aggCall = this.rewriteAggCalls.get(i);
            int index = aggCall.getArgList().get(0);
            aggOutName = getSqlFuncName(aggCall) + "_"
                    + inputColumnRowType.getColumnByIndex(index).getIdentity().replace('.', '_') + "_";
        }
        TblColRef aggOutCol = TblColRef.newInnerColumn(aggOutName, TblColRef.InnerDataTypeEnum.LITERAL);
        aggOutCol.getColumnDesc().setId("" + (i + 1)); // mark the index of aggregation
        columns.add(aggOutCol);
    }
    return new ColumnRowType(columns);
}
 
Example 16
Source File: JdbcHiveInputBase.java    From kylin with Apache License 2.0 4 votes vote down vote up
@Override
protected AbstractExecutable createSqoopToFlatHiveStep(String jobWorkingDir, String cubeName) {
    KylinConfig config = flatDesc.getDataModel().getConfig();
    PartitionDesc partitionDesc = flatDesc.getDataModel().getPartitionDesc();
    String partCol = null;
    boolean enableQuote = dataSource.getSqlConverter().getConfigurer().enableQuote();
    enableQuote = enableQuote && config.enableHiveDdlQuote();
    logger.debug("Quote switch is set to {}", enableQuote);
    SqlDialect sqlDialect = enableQuote ? dataSource.getSqlConverter().getConfigurer().getSqlDialect() : FlatTableSqlQuoteUtils.NON_QUOTE_DIALECT;
    SqlConverter.IConfigurer iconfigurer = dataSource.getSqlConverter().getConfigurer();

    if (partitionDesc.isPartitioned()) {
        partCol = partitionDesc.getPartitionDateColumn(); //tablename.colname
    }

    String splitTable;
    String splitTableAlias;
    String splitColumn;
    String splitDatabase;
    TblColRef splitColRef = determineSplitColumn();
    splitTable = splitColRef.getTableRef().getTableDesc().getName();
    splitTableAlias = splitColRef.getTableAlias();
    splitDatabase = splitColRef.getColumnDesc().getTable().getDatabase();

    if (enableQuote) {
        splitColumn = sqlDialect.quoteIdentifier(splitColRef.getTableAlias()) + "."
                + sqlDialect.quoteIdentifier(splitColRef.getName());
        splitDatabase = sqlDialect.quoteIdentifier(splitDatabase);
        splitTable = sqlDialect.quoteIdentifier(splitTable);
        splitTableAlias = sqlDialect.quoteIdentifier(splitTableAlias);
    } else {
        splitColumn = splitColRef.getTableAlias() + "." + splitColRef.getName();
    }

    String selectSql = JoinedFlatTable.generateSelectDataStatement(flatDesc, true, new String[]{partCol}, sqlDialect);
    selectSql = escapeQuotationInSql(dataSource.convertSql(selectSql));

    String hiveTable = flatDesc.getTableName();
    String filedDelimiter = config.getJdbcSourceFieldDelimiter();
    int mapperNum = config.getSqoopMapperNum();

    String bquery;
    bquery = String.format(Locale.ROOT, "SELECT min(%s), max(%s) FROM %s.%s as %s",
            splitColumn, splitColumn, splitDatabase, splitTable, splitTableAlias);
    bquery = dataSource.convertSql(bquery);

    if (partitionDesc.isPartitioned()) {
        SegmentRange segRange = flatDesc.getSegRange();
        if (segRange != null && !segRange.isInfinite()) {
            if (partitionDesc.getPartitionDateColumnRef().getTableAlias().equals(splitTableAlias)
                    && (partitionDesc.getPartitionTimeColumnRef() == null || partitionDesc
                    .getPartitionTimeColumnRef().getTableAlias().equals(splitTableAlias))) {
                String quotedPartCond = FlatTableSqlQuoteUtils.quoteIdentifierInSqlExpr(flatDesc,
                        partitionDesc.getPartitionConditionBuilder().buildDateRangeCondition(partitionDesc,
                                flatDesc.getSegment(), segRange, null), sqlDialect);
                bquery += " WHERE " + quotedPartCond;
            }
        }
    }

    bquery = escapeQuotationInSql(bquery);
    splitColumn = escapeQuotationInSql(splitColumn);
    String cmd = StringUtils.format(
            "--connect \"%s\" --driver \"%s\" --username \"%s\" --password \"%s\" --query \"%s AND \\$CONDITIONS\" "
                    + "--target-dir \"%s/%s\" --split-by \"%s\" --boundary-query \"%s\" --null-string '' "
                    + "--fields-terminated-by '%s' --num-mappers %d",
            dataSource.getJdbcUrl(), dataSource.getJdbcDriver(), dataSource.getJdbcUser(),
            dataSource.getJdbcPassword(), selectSql, jobWorkingDir, hiveTable, splitColumn, bquery,
            filedDelimiter, mapperNum);
    if (iconfigurer.getTransactionIsolationLevel() != null) {
        cmd = cmd + " --relaxed-isolation --metadata-transaction-isolation-level "
                + iconfigurer.getTransactionIsolationLevel();
    }
    logger.debug("sqoop cmd: {}", cmd);

    SqoopCmdStep step = new SqoopCmdStep();
    step.setCmd(cmd);
    step.setName(ExecutableConstants.STEP_NAME_SQOOP_TO_FLAT_HIVE_TABLE);
    return step;
}
 
Example 17
Source File: OLAPAggregateRel.java    From kylin with Apache License 2.0 4 votes vote down vote up
ColumnRowType buildColumnRowType() {
    buildGroups();
    buildAggregations();

    ColumnRowType inputColumnRowType = ((OLAPRel) getInput()).getColumnRowType();
    List<TblColRef> columns = new ArrayList<TblColRef>(this.rowType.getFieldCount());
    columns.addAll(this.groups);

    // Add group column indicators
    if (indicator) {
        final Set<String> containedNames = Sets.newHashSet();
        for (TblColRef groupCol : groups) {
            String base = "i$" + groupCol.getName();
            String name = base;
            int i = 0;
            while (containedNames.contains(name)) {
                name = base + "_" + i++;
            }
            containedNames.add(name);
            TblColRef indicatorCol = TblColRef.newInnerColumn(name, TblColRef.InnerDataTypeEnum.LITERAL);
            columns.add(indicatorCol);
        }
    }

    for (int i = 0; i < this.aggregations.size(); i++) {
        FunctionDesc aggFunc = this.aggregations.get(i);
        String aggOutName;
        if (aggFunc != null) {
            aggOutName = aggFunc.getRewriteFieldName();
        } else {
            AggregateCall aggCall = this.rewriteAggCalls.get(i);
            int index = aggCall.getArgList().get(0);
            aggOutName = getSqlFuncName(aggCall) + "_"
                    + inputColumnRowType.getColumnByIndex(index).getIdentity().replace('.', '_') + "_";
        }
        TblColRef aggOutCol = TblColRef.newInnerColumn(aggOutName, TblColRef.InnerDataTypeEnum.LITERAL);
        aggOutCol.getColumnDesc().setId("" + (i + 1)); // mark the index of aggregation
        columns.add(aggOutCol);
    }
    return new ColumnRowType(columns);
}
 
Example 18
Source File: ColumnarMemoryStorePersister.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
/**
 * This method is used to persist the dimension data to disk file, first part is the dictionary, second part is the dimension value, third part is the index.
 *
 * @param dimValueList
 * @param dimensionMetaList
 * @param indexOut
 * @param dimension
 * @param dictMaps
 * @throws IOException
 */
private void persistDimension(long cuboidId, List<Object> dimValueList, List<DimensionMetaInfo> dimensionMetaList,
        CountingOutputStream indexOut, TblColRef dimension, Map<TblColRef, Dictionary<String>> dictMaps)
        throws IOException {
    Stopwatch stopwatch = new Stopwatch();
    stopwatch.start();

    DimensionMetaInfo dimensionMeta = new DimensionMetaInfo();
    dimensionMetaList.add(dimensionMeta);

    DimensionEncoding encoding;
    IIColumnDescriptor columnDescriptor;
    if (dimensionsUseDictEncoding.contains(dimension)) {
        Dictionary<String> dict = dictMaps.get(dimension);
        encoding = new DictionaryDimEnc(dict);
        if (dict instanceof TrieDictionary) {
            columnDescriptor = new SeqIIColumnDescriptor(dimension.getName(), dict.getMinId(), dict.getMaxId());
        } else {
            columnDescriptor = new FixLenIIColumnDescriptor(dimension.getName(), encoding.getLengthOfEncoding());
        }
    } else {
        RowKeyColDesc colDesc = cubeDesc.getRowkey().getColDesc(dimension);
        encoding = DimensionEncodingFactory.create(colDesc.getEncodingName(), colDesc.getEncodingArgs(),
                colDesc.getEncodingVersion());
        columnDescriptor = new FixLenIIColumnDescriptor(dimension.getName(), encoding.getLengthOfEncoding());
    }
    dimensionMeta.setName(dimension.getName());
    dimensionMeta.setStartOffset((int) indexOut.getCount());
    int fixEncodingLen = encoding.getLengthOfEncoding();

    DataOutputStream dataOut = new DataOutputStream(indexOut);
    ColumnarStoreDimDesc cStoreDimDesc = getColumnarStoreDimDesc(dimension, encoding);
    ColumnDataWriter columnDataWriter = cStoreDimDesc.getDimWriter(dataOut, dimValueList.size());

    //Raw values are stored on disk files with fixed length encoding to make it easy for inverted index to search and scan.
    for (Object cell : dimValueList) {
        byte[] fixLenBytes = new byte[fixEncodingLen];
        if (cell != null) {
            encoding.encode((String) cell, fixLenBytes, 0);
        } else {
            encoding.encode(null, fixLenBytes, 0);
            dimensionMeta.setHasNull(true);
        }
        columnDescriptor.getWriter().addValue(fixLenBytes);
        columnDataWriter.write(fixLenBytes);
    }
    columnDataWriter.flush();
    dimensionMeta.setDataLength(dataOut.size());
    columnDescriptor.getWriter().write(indexOut);
    dimensionMeta.setIndexLength((int) indexOut.getCount() - dimensionMeta.getStartOffset()
            - dimensionMeta.getDataLength());
    dimensionMeta.setCompression(cStoreDimDesc.getCompression().name());

    stopwatch.stop();
    if (logger.isDebugEnabled()) {
        logger.debug("cuboid-{} saved dimension:{}, took: {}ms", cuboidId, dimension.getName(),
                stopwatch.elapsedMillis());
    }
}
 
Example 19
Source File: IISegment.java    From Kylin with Apache License 2.0 4 votes vote down vote up
private String dictKey(TblColRef col) {
    return col.getTable() + "/" + col.getName();
}
 
Example 20
Source File: DictionaryManager.java    From Kylin with Apache License 2.0 4 votes vote down vote up
/**
 * Get column origin
 *
 * @return 1. source table name
 * 2. column name
 * 3. column cardinal in source table
 * 4. ReadableTable object
 */

public Object[] decideSourceData(DataModelDesc model, String dict, TblColRef col, String factColumnsPath) throws IOException {
    String srcTable;
    String srcCol;
    int srcColIdx;
    ReadableTable table;
    MetadataManager metaMgr = MetadataManager.getInstance(config);

    // case of full table (dict on fact table)
    if (model == null) {
        srcTable = col.getTable();
        srcCol = col.getName();
        srcColIdx = col.getColumn().getZeroBasedIndex();
        int nColumns = metaMgr.getTableDesc(col.getTable()).getColumnCount();
        table = new FileTable(factColumnsPath + "/" + col.getName(), nColumns);
        return new Object[] { srcTable, srcCol, srcColIdx, table };
    }

    // Decide source data of dictionary:
    // 1. If 'useDict' specifies pre-defined data set, use that
    // 2. Otherwise find a lookup table to scan through

    // Note FK on fact table is supported by scan the related PK on lookup
    // table

    //String useDict = cube.getRowkey().getDictionary(col);

    // normal case, source from lookup table
    if ("true".equals(dict) || "string".equals(dict) || "number".equals(dict) || "any".equals(dict)) {
        // FK on fact table and join type is inner, use PK from lookup instead
        if (model.isFactTable(col.getTable())) {
            TblColRef pkCol = model.findPKByFK(col, "inner");
            if (pkCol != null)
                col = pkCol; // scan the counterparty PK on lookup table
            // instead
        }
        srcTable = col.getTable();
        srcCol = col.getName();
        srcColIdx = col.getColumn().getZeroBasedIndex();
        if (model.isFactTable(col.getTable())) {
            table = new FileTable(factColumnsPath + "/" + col.getName(), -1);
        } else {
            table = new HiveTable(metaMgr, col.getTable());
        }
    }
    // otherwise could refer to a data set, e.g. common_indicators.txt
    // (LEGACY PATH, since distinct values are collected from fact table)
    else {
        String dictDataSetPath = unpackDataSet(this.config.getTempHDFSDir(), dict);
        if (dictDataSetPath == null)
            throw new IllegalArgumentException("Unknown dictionary data set '" + dict + "', referred from " + col);
        srcTable = "PREDEFINED";
        srcCol = dict;
        srcColIdx = 0;
        table = new FileTable(dictDataSetPath, -1);
    }

    return new Object[] { srcTable, srcCol, srcColIdx, table };
}