/** * It returns an original column name if it is aliased column reference. * Otherwise, it will return NULL. */ public String checkAndGetIfAliasedColumn(String name) { Expr expr = getExpr(name); if (expr != null && expr.getType() == OpType.Column) { ColumnReferenceExpr column = (ColumnReferenceExpr) expr; if (!column.getCanonicalName().equals(name)) { return column.getCanonicalName(); } } return null; }
/** * It returns an original column name if it is aliased column reference. * Otherwise, it will return NULL. */ public String checkAndGetIfAliasedColumn(String name) { Expr expr = getExpr(name); if (expr != null && expr.getType() == OpType.Column) { ColumnReferenceExpr column = (ColumnReferenceExpr) expr; if (!column.getCanonicalName().equals(name)) { return column.getCanonicalName(); } } return null; }
@Override public Column resolve(LogicalPlan plan, LogicalPlan.QueryBlock block, ColumnReferenceExpr columnRef, boolean includeSeflDescTable) throws AmbiguousColumnException, AmbiguousTableException, UndefinedColumnException, UndefinedTableException { Column column = resolveFromRelsWithinBlock(plan, block, columnRef, includeSeflDescTable); if (column != null) { return column; } throw new UndefinedColumnException(columnRef.getCanonicalName()); } }
@Override public Column resolve(LogicalPlan plan, LogicalPlan.QueryBlock block, ColumnReferenceExpr columnRef, boolean includeSeflDescTable) throws AmbiguousColumnException, AmbiguousTableException, UndefinedColumnException, UndefinedTableException { Column column = resolveFromRelsWithinBlock(plan, block, columnRef, includeSeflDescTable); if (column != null) { return column; } throw new UndefinedColumnException(columnRef.getCanonicalName()); } }
/** * It generates an unique column name from Expr. It is usually used for an expression or predicate without * a specified name (i.e., alias). * Here, some expressions require to be identified with their names in the future. * For example, expressions must be identifiable with their names when getting targets in {@link LogicalPlanner#visitCreateIndex}. */ public String generateUniqueColumnName(Expr expr) { String generatedName; if (expr.getType() == OpType.Column) { generatedName = ((ColumnReferenceExpr) expr).getCanonicalName(); } else { // if a generated column name generatedName = attachSeqIdToGeneratedColumnName(getGeneratedPrefixFromExpr(expr)); } return generatedName; }
/** * It generates an unique column name from Expr. It is usually used for an expression or predicate without * a specified name (i.e., alias). * Here, some expressions require to be identified with their names in the future. * For example, expressions must be identifiable with their names when getting targets in {@link LogicalPlanner#visitCreateIndex}. */ public String generateUniqueColumnName(Expr expr) { String generatedName; if (expr.getType() == OpType.Column) { generatedName = ((ColumnReferenceExpr) expr).getCanonicalName(); } else { // if a generated column name generatedName = attachSeqIdToGeneratedColumnName(getGeneratedPrefixFromExpr(expr)); } return generatedName; }
@Override public Column resolve(LogicalPlan plan, LogicalPlan.QueryBlock block, ColumnReferenceExpr columnRef, boolean includeSeflDescTable) throws AmbiguousColumnException, AmbiguousTableException, UndefinedColumnException, UndefinedTableException { Column column = resolveFromCurrentAndChildNode(block, columnRef); if (column != null) { return column; } column = resolveFromRelsWithinBlock(plan, block, columnRef, includeSeflDescTable); if (column != null) { return column; } throw new UndefinedColumnException(columnRef.getCanonicalName()); } }
@Override public Column resolve(LogicalPlan plan, LogicalPlan.QueryBlock block, ColumnReferenceExpr columnRef, boolean includeSeflDescTable) throws AmbiguousColumnException, AmbiguousTableException, UndefinedColumnException, UndefinedTableException { Column column = resolveFromCurrentAndChildNode(block, columnRef); if (column != null) { return column; } column = resolveFromRelsWithinBlock(plan, block, columnRef, includeSeflDescTable); if (column != null) { return column; } throw new UndefinedColumnException(columnRef.getCanonicalName()); } }
@Override public Column resolve(LogicalPlan plan, LogicalPlan.QueryBlock block, ColumnReferenceExpr columnRef, boolean includeSeflDescTable) throws AmbiguousColumnException, AmbiguousTableException, UndefinedColumnException, UndefinedTableException { Column column = resolveFromRelsWithinBlock(plan, block, columnRef, includeSeflDescTable); if (column != null) { return column; } column = resolveFromCurrentAndChildNode(block, columnRef); if (column != null) { return column; } throw new UndefinedColumnException(columnRef.getCanonicalName()); } }
@Override public Column resolve(LogicalPlan plan, LogicalPlan.QueryBlock block, ColumnReferenceExpr columnRef, boolean includeSeflDescTable) throws AmbiguousColumnException, AmbiguousTableException, UndefinedColumnException, UndefinedTableException { Column column = resolveFromRelsWithinBlock(plan, block, columnRef, includeSeflDescTable); if (column != null) { return column; } column = resolveFromCurrentAndChildNode(block, columnRef); if (column != null) { return column; } throw new UndefinedColumnException(columnRef.getCanonicalName()); } }
@Override public Expr visitColumnReference(ExprNormalizedResult ctx, Stack<Expr> stack, ColumnReferenceExpr expr) throws TajoException { if (ctx.block.isAliasedName(expr.getCanonicalName())) { String originalName = ctx.block.getOriginalName(expr.getCanonicalName()); expr.setName(originalName); return expr; } // if a column reference is not qualified, it finds and sets the qualified column name. if (!(expr.hasQualifier() && CatalogUtil.isFQTableName(expr.getQualifier()))) { if (!ctx.block.namedExprsMgr.contains(expr.getCanonicalName()) && expr.getType() == OpType.Column) { try { String normalized = NameResolver.resolve(ctx.plan, ctx.block, expr, NameResolvingMode.LEGACY).getQualifiedName(); expr.setName(normalized); } catch (UndefinedColumnException nsc) { } } } return expr; }
@Override public Expr visitColumnReference(ExprNormalizedResult ctx, Stack<Expr> stack, ColumnReferenceExpr expr) throws TajoException { if (ctx.block.isAliasedName(expr.getCanonicalName())) { String originalName = ctx.block.getOriginalName(expr.getCanonicalName()); expr.setName(originalName); return expr; } // if a column reference is not qualified, it finds and sets the qualified column name. if (!(expr.hasQualifier() && IdentifierUtil.isFQTableName(expr.getQualifier()))) { if (!ctx.block.namedExprsMgr.contains(expr.getCanonicalName()) && expr.getType() == OpType.Column) { try { String normalized = NameResolver.resolve(ctx.plan, ctx.block, expr, NameResolvingMode.LEGACY).getQualifiedName(); expr.setName(normalized); } catch (UndefinedColumnException nsc) { } } } return expr; }
leftQualifier = CatalogUtil.extractQualifier(foundColumns.iterator().next().getCanonicalName()); rightQualifier = CatalogUtil.extractQualifier(foundColumns.iterator().next().getCanonicalName());
leftQualifier = IdentifierUtil.extractQualifier(foundColumns.iterator().next().getCanonicalName()); rightQualifier = IdentifierUtil.extractQualifier(foundColumns.iterator().next().getCanonicalName());
static Column resolveColumnWithoutQualifier(LogicalPlan plan, LogicalPlan.QueryBlock block, ColumnReferenceExpr columnRef, boolean includeSeflDescTable) throws AmbiguousColumnException, UndefinedColumnException { Column found = lookupColumnFromAllRelsInBlock(block, columnRef.getName(), includeSeflDescTable); if (found != null) { return found; } found = resolveAliasedName(block, columnRef); if (found != null) { return found; } found = resolveFromCurrentAndChildNode(block, columnRef); if (found != null) { return found; } found = resolveFromAllRelsInAllBlocks(plan, columnRef); if (found != null) { return found; } throw new UndefinedColumnException(columnRef.getCanonicalName()); } }
static Column resolveColumnWithoutQualifier(LogicalPlan plan, LogicalPlan.QueryBlock block, ColumnReferenceExpr columnRef, boolean includeSeflDescTable) throws AmbiguousColumnException, UndefinedColumnException { Column found = lookupColumnFromAllRelsInBlock(block, columnRef.getName(), includeSeflDescTable); if (found != null) { return found; } found = resolveAliasedName(block, columnRef); if (found != null) { return found; } found = resolveFromCurrentAndChildNode(block, columnRef); if (found != null) { return found; } found = resolveFromAllRelsInAllBlocks(plan, columnRef); if (found != null) { return found; } throw new UndefinedColumnException(columnRef.getCanonicalName()); } }
/** * Try to find the column from the current node and child node. It can find subexprs generated from the optimizer. * * @param block The current query block * @param columnRef The column reference to be found * @return The found column */ static Column resolveFromCurrentAndChildNode(LogicalPlan.QueryBlock block, ColumnReferenceExpr columnRef) throws UndefinedColumnException { if (block.getCurrentNode() != null && block.getCurrentNode().getInSchema() != null) { Column found = block.getCurrentNode().getInSchema().getColumn(columnRef.getCanonicalName()); if (found != null) { return found; } else if (block.getLatestNode() != null) { found = block.getLatestNode().getOutSchema().getColumn(columnRef.getName()); if (found != null) { return found; } } } return null; }
/** * Try to find the column from the current node and child node. It can find subexprs generated from the optimizer. * * @param block The current query block * @param columnRef The column reference to be found * @return The found column */ static Column resolveFromCurrentAndChildNode(LogicalPlan.QueryBlock block, ColumnReferenceExpr columnRef) throws UndefinedColumnException { if (block.getCurrentNode() != null && block.getCurrentNode().getInSchema() != null) { Column found = block.getCurrentNode().getInSchema().getColumn(columnRef.getCanonicalName()); if (found != null) { return found; } else if (block.getLatestNode() != null) { found = block.getLatestNode().getOutSchema().getColumn(columnRef.getName()); if (found != null) { return found; } } } return null; }
throw new UndefinedColumnException(columnRef.getCanonicalName());
ctx.getQueryBlock().addColumnAlias(((ColumnReferenceExpr)namedExpr.getExpr()).getCanonicalName(), namedExpr.getAlias()); } else if (OpType.isLiteralType(namedExpr.getExpr().getType()) && namedExpr.hasAlias()) {