Github user jihoonson commented on a diff in the pull request:

    https://github.com/apache/tajo/pull/422#discussion_r29865298
  
    --- Diff: 
tajo-plan/src/main/java/org/apache/tajo/plan/nameresolver/NameResolver.java ---
    @@ -240,33 +292,94 @@ static Column 
resolveAliasedName(LogicalPlan.QueryBlock block, ColumnReferenceEx
       }
     
       /**
    -   * It returns a pair of names, which the first value is 
${database}.${table} and the second value
    -   * is a simple column name.
    +   * Lookup a qualifier and a canonical name of column.
    +   *
    +   * It returns a pair of names, which the first value is the qualifier 
${database}.${table} and
    +   * the second value is column's simple name.
        *
        * @param block The current block
        * @param columnRef The column name
        * @return A pair of normalized qualifier and column name
        * @throws PlanningException
        */
    -  static Pair<String, String> 
normalizeQualifierAndCanonicalName(LogicalPlan.QueryBlock block,
    -                                                                 
ColumnReferenceExpr columnRef)
    +  static Pair<String, String> 
lookupQualifierAndCanonicalName(LogicalPlan.QueryBlock block,
    +                                                              
ColumnReferenceExpr columnRef)
           throws PlanningException {
    -    String qualifier;
    -    String canonicalName;
    +    Preconditions.checkArgument(columnRef.hasQualifier(), 
"ColumnReferenceExpr must be qualified.");
    +
    +    String [] qualifierParts = columnRef.getQualifier().split("\\.");
     
    -    if (CatalogUtil.isFQTableName(columnRef.getQualifier())) {
    -      qualifier = columnRef.getQualifier();
    -      canonicalName = columnRef.getCanonicalName();
    +    // This method assumes that column name consists of two or more dot 
chained names.
    +    // In this case, there must be three cases as follows:
    +    //
    +    // - dbname.tbname.column_name.nested_field...
    +    // - tbname.column_name.nested_field...
    +    // - column.nested_fieldX...
    +
    +    Set<RelationNode> guessedRelations = TUtil.newHashSet();
    +
    +    // this position indicates the index of column name in qualifierParts;
    +    // It must be 0 or more because a qualified column is always passed to 
lookupQualifierAndCanonicalName().
    +    int columnNamePosition = -1;
    +
    +    // check for dbname.tbname.column_name.nested_field
    +    if (qualifierParts.length >= 2) {
    +      RelationNode rel = lookupTable(block, 
CatalogUtil.buildFQName(qualifierParts[0], qualifierParts[1]));
    +      if (rel != null) {
    +        guessedRelations.add(rel);
    +        columnNamePosition = 2;
    +      }
    +    }
    +
    +    // check for tbname.column_name.nested_field
    +    if (qualifierParts.length >= 1) {
    +      RelationNode rel = lookupTable(block, qualifierParts[0]);
    +      if (rel != null) {
    +        guessedRelations.add(rel);
    +        columnNamePosition = 1;
    +      }
    +    }
    +
    +    // column.nested_fieldX...
    +    if (guessedRelations.size() == 0 && qualifierParts.length == 1) {
    --- End diff --
    
    Oh, I missed the below part that throws an AmbiguousFieldException when 
there are two ore more candidate relations.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to