@Deprecated public List<TableDesc> getLookupTableDescs() { List<TableDesc> result = Lists.newArrayList(); for (TableRef table : getLookupTables()) { result.add(table.getTableDesc()); } return result; }
private void addAlias(TableRef ref) { String alias = ref.getAlias(); if (aliasMap.containsKey(alias)) throw new IllegalStateException("Alias '" + alias + "' ref to multiple tables: " + ref.getTableIdentity() + ", " + aliasMap.get(alias).getTableIdentity()); aliasMap.put(alias, ref); TableDesc table = ref.getTableDesc(); addTableName(table.getName(), ref); addTableName(table.getIdentity(), ref); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; DataModelDesc modelDesc = (DataModelDesc) o; if (!name.equals(modelDesc.name)) return false; if (!getRootFactTable().equals(modelDesc.getRootFactTable())) return false; return true; }
public static void fixUnknownModel(DataModelDesc model, String alias, TblColRef col) { checkArgument(col.table.getModel() == UNKNOWN_MODEL || col.table.getModel() == model); TableRef tableRef = model.findTable(alias); checkArgument(tableRef.getTableDesc().getIdentity().equals(col.column.getTable().getIdentity())); col.fixTableRef(tableRef); }
private boolean matchChain(Chain chain, Chain anotherChain, Map<String, String> matchUp) { String thisAlias = chain.table.getAlias(); String anotherAlias = anotherChain.table.getAlias(); String curMatch = matchUp.get(thisAlias); if (curMatch != null) return curMatch.equals(anotherAlias); if (curMatch == null && matchUp.values().contains(anotherAlias)) return false; boolean matches = false; if (chain.join == null) { matches = anotherChain.join == null && chain.table.getTableDesc().getIdentity().equals(anotherChain.table.getTableDesc().getIdentity()); } else { matches = joinDescMatcher.matches(chain.join, anotherChain.join) && matchChain(chain.fkSide, anotherChain.fkSide, matchUp); } if (matches) { matchUp.put(thisAlias, anotherAlias); } return matches; }
public boolean isFactTable(String fullTableName) { for (TableRef t : factTableRefs) { if (t.getTableIdentity().equals(fullTableName)) return true; } return false; }
public boolean containsTable(TableDesc table) { for (TableRef t : allTableRefs) { if (t.getTableIdentity().equals(table.getIdentity()) && StringUtil.equals(t.getTableDesc().getProject(), table.getProject())) return true; } return false; }
Set<String> TABLE_NAMES = new HashSet<String>(); for (TableRef tr : tables) { if (!tr.getTableDesc().isView()) { String tableName = tr.getTableName(); String schema = tr.getTableDesc().getDatabase(); String identity = String.format(Locale.ROOT, "%s.%s", schema, tableName); TABLE_NAMES.add(identity); ISampleDataDeployer sampleDataDeployer = SourceManager.getSource(model.getRootFactTable().getTableDesc()) .getSampleDataDeployer();
public String getBackupTableAlias(){ return backupTable.getAlias(); } private void markInnerColumn(InnerDataTypeEnum dataType) {
long maxCardinality = 0; for (TableRef tableRef : flatDesc.getDataModel().getAllTables()) { TableExtDesc tableExtDesc = tblManager.getTableExt(tableRef.getTableDesc()); List<TableExtDesc.ColumnStats> columnStatses = tableExtDesc.getColumnStats(); if (!columnStatses.isEmpty()) { for (TblColRef colRef : tableRef.getColumns()) { long cardinality = columnStatses.get(colRef.getColumnDesc().getZeroBasedIndex()) .getCardinality();
public boolean belongToFactTableDims(TblColRef tblColRef) { if (!belongToContextTables(tblColRef)) { return false; } KylinConfig kylinConfig = olapSchema.getConfig(); String projectName = olapSchema.getProjectName(); String factTableName = firstTableScan.getOlapTable().getTableName(); Set<IRealization> realizations = ProjectManager.getInstance(kylinConfig).getRealizationsByTable(projectName, factTableName); for (IRealization real : realizations) { DataModelDesc model = real.getModel(); TblColRef.fixUnknownModel(model, tblColRef.getTableRef().getTableIdentity(), tblColRef); // cannot be a measure column Set<String> metrics = Sets.newHashSet(model.getMetrics()); if (metrics.contains(tblColRef.getIdentity())) { tblColRef.unfixTableRef(); return false; } // must belong to a fact table for (TableRef factTable : model.getFactTables()) { if (factTable.getColumns().contains(tblColRef)) { tblColRef.unfixTableRef(); return true; } } tblColRef.unfixTableRef(); } return false; }
private static Map<String, String> matches(DataModelDesc model, OLAPContext ctx) { Map<String, String> result = Maps.newHashMap(); TableRef firstTable = ctx.firstTableScan.getTableRef(); Map<String, String> matchUp = null; if (ctx.joins.isEmpty() && model.isLookupTable(firstTable.getTableIdentity())) { // one lookup table String modelAlias = model.findFirstTable(firstTable.getTableIdentity()).getAlias(); matchUp = ImmutableMap.of(firstTable.getAlias(), modelAlias); } else if (ctx.joins.size() != ctx.allTableScans.size() - 1) { // has hanging tables ctx.realizationCheck.addModelIncapableReason(model, RealizationCheck.IncapableReason.create(RealizationCheck.IncapableType.MODEL_BAD_JOIN_SEQUENCE)); throw new IllegalStateException("Please adjust the sequence of join tables. " + toErrorMsg(ctx)); } else { // normal big joins if (ctx.joinsTree == null) { ctx.joinsTree = new JoinsTree(firstTable, ctx.joins); } matchUp = ctx.joinsTree.matches(model.getJoinsTree(), result); } if (matchUp == null) { ctx.realizationCheck.addModelIncapableReason(model, RealizationCheck.IncapableReason.create(RealizationCheck.IncapableType.MODEL_UNMATCHED_JOIN)); return null; } result.putAll(matchUp); ctx.realizationCheck.addCapableModel(model, result); return result; }
public TupleInfo newTupleInfo(List<TblColRef> groups, List<FunctionDesc> aggregations) { TupleInfo info = new TupleInfo(); int idx = 0; for (TblColRef col : groups) { info.setField(col.getName(), col, idx++); } TableRef sourceTable = groups.get(0).getTableRef(); for (FunctionDesc func : aggregations) { ColumnDesc colDesc = func.newFakeRewriteColumn(sourceTable.getTableDesc()); TblColRef col = sourceTable.makeFakeColumn(colDesc); info.setField(col.getName(), col, idx++); } return info; }
public void init(CubeDesc cubeDesc) { DataModelDesc model = cubeDesc.getModel(); if (name != null) name = name.toUpperCase(Locale.ROOT); tableRef = model.findTable(table); table = tableRef.getAlias(); join = null; for (JoinTableDesc joinTable : model.getJoinTables()) { if (joinTable.getTableRef().equals(this.tableRef)) { join = joinTable.getJoin(); break; } } if (column != null && !"{FK}".equals(column)) { column = model.findColumn(table, column).getName(); } if (derived != null && derived.length == 0) { derived = null; } if (derived != null) { for (int i = 0; i < derived.length; i++) { derived[i] = model.findColumn(table, derived[i]).getName(); } } if (derived != null && join == null) { throw new IllegalStateException( "Derived can only be defined on lookup table, cube " + cubeDesc + ", " + this); } }
private static Map<String, String> buildTableToTableAliasMap(IJoinedFlatTableDesc flatDesc) { Map<String, String> map = Maps.newHashMap(); List<TblColRef> colRefs = flatDesc.getAllColumns(); for (TblColRef colRef : colRefs) { String tableName = colRef.getTableRef().getTableName(); String alias = colRef.getTableAlias(); map.put(tableName, alias); } return map; }
@Override public void serialize(IFilterCodeSystem<?> cs, ByteBuffer buffer) { TableRef tableRef = columnRef.getTableRef(); if (tableRef == null) { // un-qualified column String table = columnRef.getTable(); BytesUtil.writeUTFString(table, buffer); String columnId = columnRef.getColumnDesc().getId(); BytesUtil.writeUTFString(columnId, buffer); String columnName = columnRef.getName(); BytesUtil.writeUTFString(columnName, buffer); String dataType = columnRef.getDatatype(); BytesUtil.writeUTFString(dataType, buffer); } else { // qualified column (from model) BytesUtil.writeUTFString(_QUALIFIED_, buffer); String model = tableRef.getModel().getName(); BytesUtil.writeUTFString(model, buffer); String alias = tableRef.getAlias(); BytesUtil.writeUTFString(alias, buffer); String col = columnRef.getName(); BytesUtil.writeUTFString(col, buffer); } }
TblColRef[] pkCols = new TblColRef[pks.length]; for (int i = 0; i < pks.length; i++) { TblColRef col = dimTable.getColumn(pks[i]); if (col == null) { col = findColumn(pks[i]); if (col == null || col.getTableRef().equals(dimTable) == false) { throw new IllegalStateException("Can't find PK column " + pks[i] + " in table " + dimTable);
sql.append(" FROM ").append(flatDesc.getDataModel().getRootFactTable().getTableIdentityQuoted("`")) .append(" as ").append(quoteIdentifier(rootTable.getAlias())).append(sep); sql.append(joinType).append(" JOIN ").append(dimTable.getTableIdentityQuoted("`")) .append(" as ").append(quoteIdentifier(dimTable.getAlias())).append(sep); sql.append("ON "); for (int i = 0; i < pk.length; i++) {
|| cube.getSnapshots().containsKey(digest.factTable)) { Set<TblColRef> dimCols = Sets.newHashSet(cube.getModel().findFirstTable(digest.factTable).getColumns());
@Override public int hashCode() { int result = 0; result = 31 * result + name.hashCode(); result = 31 * result + model.getRootFactTable().hashCode(); return result; }