Java Code Examples for org.apache.kylin.cube.model.DimensionDesc#getTable()

The following examples show how to use org.apache.kylin.cube.model.DimensionDesc#getTable() . 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: DictionaryGeneratorCLI.java    From Kylin with Apache License 2.0 6 votes vote down vote up
private static void processSegment(KylinConfig config, CubeSegment cubeSeg, String factColumnsPath) throws IOException {
    CubeManager cubeMgr = CubeManager.getInstance(config);

    for (DimensionDesc dim : cubeSeg.getCubeDesc().getDimensions()) {
        // dictionary
        for (TblColRef col : dim.getColumnRefs()) {
            if (cubeSeg.getCubeDesc().getRowkey().isUseDictionary(col)) {
                logger.info("Building dictionary for " + col);
                cubeMgr.buildDictionary(cubeSeg, col, factColumnsPath);
            }
        }

        // build snapshot
        if (dim.getTable() != null && !dim.getTable().equalsIgnoreCase(cubeSeg.getCubeDesc().getFactTable())) {
            // CubeSegment seg = cube.getTheOnlySegment();
            logger.info("Building snapshot of " + dim.getTable());
            cubeMgr.buildSnapshotTable(cubeSeg, dim.getTable());
            logger.info("Checking snapshot of " + dim.getTable());
            cubeMgr.getLookupTable(cubeSeg, dim); // load the table for
                                                  // sanity check
        }
    }
}
 
Example 2
Source File: CubeManager.java    From Kylin with Apache License 2.0 6 votes vote down vote up
public LookupStringTable getLookupTable(CubeSegment cubeSegment, DimensionDesc dim) {

        String tableName = dim.getTable();
        String[] pkCols = dim.getJoin().getPrimaryKey();
        String snapshotResPath = cubeSegment.getSnapshotResPath(tableName);
        if (snapshotResPath == null)
            throw new IllegalStateException("No snaphot for table '" + tableName + "' found on cube segment" + cubeSegment.getCubeInstance().getName() + "/" + cubeSegment);

        try {
            SnapshotTable snapshot = getSnapshotManager().getSnapshotTable(snapshotResPath);
            TableDesc tableDesc = getMetadataManager().getTableDesc(tableName);
            return new LookupStringTable(tableDesc, pkCols, snapshot);
        } catch (IOException e) {
            throw new IllegalStateException("Failed to load lookup table " + tableName + " from snapshot " + snapshotResPath, e);
        }
    }
 
Example 3
Source File: NewBaseCuboidMapper.java    From Kylin with Apache License 2.0 5 votes vote down vote up
private void prepareJoins() throws IOException {
    this.lookupTables = new HashMap<String, LookupBytesTable>();
    this.tableJoins = new LinkedList<TableJoin>();
    this.factTblColAsRowKey = new LinkedList<Pair<Integer, Integer>>();

    for (DimensionDesc dim : cubeDesc.getDimensions()) {
        JoinDesc join = dim.getJoin();
        if (join != null) {
            String joinType = join.getType().toUpperCase();
            String lookupTableName = dim.getTable();

            // load lookup tables
            if (!lookupTables.containsKey(lookupTableName)) {
                HiveTable htable = new HiveTable(metadataManager, lookupTableName);
                LookupBytesTable btable = new LookupBytesTable(metadataManager.getTableDesc(lookupTableName), join.getPrimaryKey(), htable);
                lookupTables.put(lookupTableName, btable);
            }

            // create join infos
            LinkedList<Integer> fkIndice = new LinkedList<Integer>();
            for (TblColRef colRef : join.getForeignKeyColumns()) {
                fkIndice.add(colRef.getColumn().getZeroBasedIndex());
            }
            this.tableJoins.add(new TableJoin(joinType, fkIndice, lookupTableName, this.findColumnRowKeyRelationships(dim)));

        } else {

            this.factTblColAsRowKey.addAll(this.findColumnRowKeyRelationships(dim));
        }
    }

    // put composite keys joins ahead of single key joins
    Collections.sort(tableJoins, new Comparator<TableJoin>() {
        @Override
        public int compare(TableJoin o1, TableJoin o2) {
            return Integer.valueOf(o2.fkIndice.size()).compareTo(Integer.valueOf(o1.fkIndice.size()));
        }
    });
}