Java Code Examples for org.apache.kylin.metadata.model.DataModelDesc#getRootFactTable()

The following examples show how to use org.apache.kylin.metadata.model.DataModelDesc#getRootFactTable() . 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: FactTableRealizationSetCalculator.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private String getRootFactTableForRealization(IRealization realization) {
    if (realization == null) {
        logger.warn("Cannot find realization %s", realization);
        return null;
    }
    DataModelDesc model = realization.getModel();
    if (model == null) {
        logger.warn("The model for realization %s is null", realization.getName());
        return null;
    }
    TableRef rootFactTable = model.getRootFactTable();
    if (rootFactTable == null) {
        logger.warn("The root table for model %s is null", model.getName());
        return null;
    }
    return rootFactTable.getTableIdentity();
}
 
Example 2
Source File: FactTableRealizationSetCalculator.java    From kylin with Apache License 2.0 6 votes vote down vote up
private String getRootFactTableForRealization(IRealization realization) {
    if (realization == null) {
        logger.warn("Cannot find realization %s", realization);
        return null;
    }
    DataModelDesc model = realization.getModel();
    if (model == null) {
        logger.warn("The model for realization %s is null", realization.getName());
        return null;
    }
    TableRef rootFactTable = model.getRootFactTable();
    if (rootFactTable == null) {
        logger.warn("The root table for model %s is null", model.getName());
        return null;
    }
    return rootFactTable.getTableIdentity();
}
 
Example 3
Source File: JoinedFlatTable.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
static void appendJoinStatement(IJoinedFlatTableDesc flatDesc, StringBuilder sql, boolean singleLine, SqlDialect sqlDialect) {
    final String sep = singleLine ? " " : "\n";
    Set<TableRef> dimTableCache = new HashSet<>();

    DataModelDesc model = flatDesc.getDataModel();
    TableRef rootTable = model.getRootFactTable();
    sql.append(" FROM ").append(quoteTableIdentity(flatDesc.getDataModel().getRootFactTable(), sqlDialect))
            .append(" as ").append(quoteIdentifier(rootTable.getAlias(), sqlDialect)).append(sep);

    for (JoinTableDesc lookupDesc : model.getJoinTables()) {
        JoinDesc join = lookupDesc.getJoin();
        if (join != null && join.getType().equals("") == false) {
            TableRef dimTable = lookupDesc.getTableRef();
            if (!dimTableCache.contains(dimTable)) {
                TblColRef[] pk = join.getPrimaryKeyColumns();
                TblColRef[] fk = join.getForeignKeyColumns();
                if (pk.length != fk.length) {
                    throw new RuntimeException("Invalid join condition of lookup table:" + lookupDesc);
                }
                String joinType = join.getType().toUpperCase(Locale.ROOT);
                sql.append(joinType).append(" JOIN ").append(quoteTableIdentity(dimTable, sqlDialect))
                        .append(" as ").append(quoteIdentifier(dimTable.getAlias(), sqlDialect)).append(sep);
                sql.append("ON ");
                for (int i = 0; i < pk.length; i++) {
                    if (i > 0) {
                        sql.append(" AND ");
                    }
                    sql.append(getQuotedColExpressionInSourceDB(flatDesc, fk[i], sqlDialect)).append(" = ")
                            .append(getQuotedColExpressionInSourceDB(flatDesc, pk[i], sqlDialect));
                }
                sql.append(sep);

                dimTableCache.add(dimTable);
            }
        }
    }
}
 
Example 4
Source File: JoinedFlatTable.java    From kylin with Apache License 2.0 5 votes vote down vote up
public static void appendJoinStatement(IJoinedFlatTableDesc flatDesc, StringBuilder sql, boolean singleLine,
        SqlDialect sqlDialect) {
    final String sep = singleLine ? " " : "\n";
    Set<TableRef> dimTableCache = new HashSet<>();

    DataModelDesc model = flatDesc.getDataModel();
    TableRef rootTable = model.getRootFactTable();
    sql.append(" FROM ").append(quoteTableIdentity(flatDesc.getDataModel().getRootFactTable(), sqlDialect))
            .append(" as ").append(quoteIdentifier(rootTable.getAlias(), sqlDialect)).append(sep);

    for (JoinTableDesc lookupDesc : model.getJoinTables()) {
        JoinDesc join = lookupDesc.getJoin();
        if (join != null && join.getType().equals("") == false) {
            TableRef dimTable = lookupDesc.getTableRef();
            if (!dimTableCache.contains(dimTable)) {
                TblColRef[] pk = join.getPrimaryKeyColumns();
                TblColRef[] fk = join.getForeignKeyColumns();
                if (pk.length != fk.length) {
                    throw new RuntimeException("Invalid join condition of lookup table:" + lookupDesc);
                }
                String joinType = join.getType().toUpperCase(Locale.ROOT);
                sql.append(joinType).append(" JOIN ").append(quoteTableIdentity(dimTable, sqlDialect))
                        .append(" as ").append(quoteIdentifier(dimTable.getAlias(), sqlDialect)).append(sep);
                sql.append("ON ");
                for (int i = 0; i < pk.length; i++) {
                    if (i > 0) {
                        sql.append(" AND ");
                    }
                    sql.append(getQuotedColExpressionInSourceDB(flatDesc, fk[i], sqlDialect)).append(" = ")
                            .append(getQuotedColExpressionInSourceDB(flatDesc, pk[i], sqlDialect));
                }
                sql.append(sep);

                dimTableCache.add(dimTable);
            }
        }
    }
}