Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-13801

DataFrame.col should return unresolved attribute

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Incomplete
    • None
    • None
    • SQL

    Description

      Recently I saw some JIRAs complain about wrong result when using DataFrame API. After checking their queries, I found it was caused by un-direct self-join and they build wrong join conditions. For example:

      val df = ...
      val df2 = df.filter(...)
      df.join(df2, (df("key") + 1) === df2("key"))
      

      In this case, the confusing part is: df("key") and df2("key2") reference to the same column, while df and df2 are different DataFrames.

      I think the biggest problem is, we give users the resolved attribute. However, resolved attribute is not real column, as logical plan's output may change. For example, we will generate new output for the right child in self-join.

      My proposal is: `DataFrame.col` should always return unresolved attribute. We can still do the resolution to make sure the given column name is resolvable, but don't return the resolved one, just get the name out and wrap it with UnresolvedAttribute.

      Now if users run the example query I gave at the beginning, they will get analysis exception, and they will understand they need to alias df and df2 before join.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              cloud_fan Wenchen Fan
              Votes:
              2 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: