/** * Guess a relation from a table name regardless of whether the given name is qualified or not. * * @param block the current block * @param tableName The table name which can be either qualified or not. * @return A corresponding relation */ public static RelationNode lookupTable(LogicalPlan.QueryBlock block, String tableName) throws AmbiguousTableException { List<RelationNode> found = new ArrayList<>(); for (RelationNode relation : block.getRelations()) { // if a table name is qualified if (relation.getCanonicalName().equals(tableName) || relation.getTableName().equals(tableName)) { found.add(relation); // if a table name is not qualified } else if (IdentifierUtil.extractSimpleName(relation.getCanonicalName()).equals(tableName) || IdentifierUtil.extractSimpleName(relation.getTableName()).equals(tableName)) { found.add(relation); } } if (found.size() == 0) { return null; } else if (found.size() > 1) { throw new AmbiguousTableException(tableName); } return found.get(0); }
/** * Guess a relation from a table name regardless of whether the given name is qualified or not. * * @param block the current block * @param tableName The table name which can be either qualified or not. * @return A corresponding relation */ public static RelationNode lookupTable(LogicalPlan.QueryBlock block, String tableName) throws AmbiguousTableException { List<RelationNode> found = TUtil.newList(); for (RelationNode relation : block.getRelations()) { // if a table name is qualified if (relation.getCanonicalName().equals(tableName) || relation.getTableName().equals(tableName)) { found.add(relation); // if a table name is not qualified } else if (CatalogUtil.extractSimpleName(relation.getCanonicalName()).equals(tableName) || CatalogUtil.extractSimpleName(relation.getTableName()).equals(tableName)) { found.add(relation); } } if (found.size() == 0) { return null; } else if (found.size() > 1) { throw new AmbiguousTableException(tableName); } return found.get(0); }
/** * Find relations such that its schema contains a given column * * @param block the current block * @param columnName The column name to find relation * @return relations including a given column */ public static Collection<RelationNode> lookupTableByColumns(LogicalPlan.QueryBlock block, String columnName) { Set<RelationNode> found = new HashSet<>(); for (RelationNode rel : block.getRelations()) { if (rel.getLogicalSchema().contains(columnName)) { found.add(rel); } } return found; }
while (!plan.getRootBlock().getName().equals(current.getName())) { LogicalPlan.QueryBlock parentBlock = plan.getParentBlock(current); for (RelationNode relationNode : parentBlock.getRelations()) { if (relationNode.getLogicalSchema().containsByQualifiedName(columnRef.getCanonicalName())) { throw new TajoRuntimeException(new NotImplementedException("Correlated subquery"));
} else { // if a column reference is not qualified Iterator<RelationNode> iterator = block.getRelations().iterator(); Schema schema; List<Column> resolvedColumns = TUtil.newList();
Collection<RelationNode> relations = block.getRelations(); if (relations.size() > 1) { throw new UnsupportedException("Index on multiple relations");
} else { // if a column reference is not qualified Iterator<RelationNode> iterator = block.getRelations().iterator(); Schema schema; List<Column> resolvedColumns = new ArrayList<>();
for (RelationNode relationNode : block.getRelations()) { vertexes.add(new RelationVertex(relationNode));
for (RelationNode relationNode : block.getRelations()) { vertexes.add(new RelationVertex(relationNode));
for (RelationNode rel : block.getRelations()) { if (rel.isNameResolveBase()) { Column found = rel.getLogicalSchema().getColumn(columnName); if (includeSelfDescTable) { List<RelationNode> candidateRels = new ArrayList<>(); for (RelationNode rel : block.getRelations()) { if (describeSchemaByItself(rel)) { candidateRels.add(rel);
for (RelationNode rel : block.getRelations()) { if (rel.isNameResolveBase()) { Column found = rel.getLogicalSchema().getColumn(columnName); if (includeSelfDescTable) { List<RelationNode> candidateRels = TUtil.newList(); for (RelationNode rel : block.getRelations()) { if (describeSchemaByItself(rel)) { candidateRels.add(rel);
/** * Trying to find a column from all relations in other blocks * * @param plan The logical plan * @param columnRef The column reference to be found * @return The found column */ static Column resolveFromAllRelsInAllBlocks(LogicalPlan plan, ColumnReferenceExpr columnRef) throws AmbiguousColumnException { List<Column> candidates = Lists.newArrayList(); // from all relations of all query blocks for (LogicalPlan.QueryBlock eachBlock : plan.getQueryBlocks()) { for (RelationNode rel : eachBlock.getRelations()) { Column found = rel.getLogicalSchema().getColumn(columnRef.getName()); if (found != null) { candidates.add(found); } } } if (!candidates.isEmpty()) { return NameResolver.ensureUniqueColumn(candidates); } else { return null; } }
/** * Trying to find a column from all relations in other blocks * * @param plan The logical plan * @param columnRef The column reference to be found * @return The found column */ static Column resolveFromAllRelsInAllBlocks(LogicalPlan plan, ColumnReferenceExpr columnRef) throws AmbiguousColumnException { List<Column> candidates = Lists.newArrayList(); // from all relations of all query blocks for (LogicalPlan.QueryBlock eachBlock : plan.getQueryBlocks()) { for (RelationNode rel : eachBlock.getRelations()) { Column found = rel.getLogicalSchema().getColumn(columnRef.getName()); if (found != null) { candidates.add(found); } } } if (!candidates.isEmpty()) { return NameResolver.ensureUniqueColumn(candidates); } else { return null; } }
@Override public boolean isEligible(LogicalPlanRewriteRuleContext context) { if (context.getQueryContext().getBool(SessionVars.INDEX_ENABLED)) { for (LogicalPlan.QueryBlock block : context.getPlan().getQueryBlocks()) { for (RelationNode relationNode : block.getRelations()) { List<AccessPathInfo> accessPathInfos = block.getAccessInfos(relationNode); // If there are any alternative access paths if (accessPathInfos.size() > 1) { for (AccessPathInfo accessPathInfo : accessPathInfos) { if (accessPathInfo.getScanType() == AccessPathInfo.ScanTypeControl.INDEX_SCAN) { return true; } } } } } } return false; }
@Override public boolean isEligible(LogicalPlanRewriteRuleContext context) { if (context.getQueryContext().getBool(SessionVars.INDEX_ENABLED)) { for (LogicalPlan.QueryBlock block : context.getPlan().getQueryBlocks()) { for (RelationNode relationNode : block.getRelations()) { List<AccessPathInfo> accessPathInfos = block.getAccessInfos(relationNode); // If there are any alternative access paths if (accessPathInfos.size() > 1) { for (AccessPathInfo accessPathInfo : accessPathInfos) { if (accessPathInfo.getScanType() == AccessPathInfo.ScanTypeControl.INDEX_SCAN) { return true; } } } } } } return false; }
/** * Find relations such that its schema contains a given column * * @param block the current block * @param columnName The column name to find relation * @return relations including a given column */ public static Collection<RelationNode> lookupTableByColumns(LogicalPlan.QueryBlock block, String columnName) { Set<RelationNode> found = TUtil.newHashSet(); for (RelationNode rel : block.getRelations()) { if (rel.getLogicalSchema().contains(columnName)) { found.add(rel); } } return found; }
@Override public boolean isEligible(LogicalPlanRewriteRuleContext context) { for (LogicalPlan.QueryBlock block : context.getPlan().getQueryBlocks()) { for (RelationNode relation : block.getRelations()) { if (relation.getType() == NodeType.SCAN) { TableDesc table = ((ScanNode)relation).getTableDesc(); if (table.hasPartition()) { return true; } } } } return false; }
@Override public boolean isEligible(LogicalPlanRewriteRuleContext context) { for (LogicalPlan.QueryBlock block : context.getPlan().getQueryBlocks()) { for (RelationNode relation : block.getRelations()) { if (relation.getType() == NodeType.SCAN) { TableDesc table = ((ScanNode)relation).getTableDesc(); if (table.hasPartition()) { return true; } } } } return false; }
public String toString() { return "block=" + queryBlock.getName() + ", relNum=" + queryBlock.getRelations().size() + ", "+ queryBlock.namedExprsMgr.toString(); }
public String toString() { return "block=" + queryBlock.getName() + ", relNum=" + queryBlock.getRelations().size() + ", "+ queryBlock.namedExprsMgr.toString(); }