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

Misleading Error Message for Aggregation Without Window/GroupBy

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0
    • Fix Version/s: 2.0.2, 2.1.0
    • Component/s: SQL
    • Labels:
      None
    • Environment:

      Databricks

      Description

      The following error message points to a random column I'm not actually using in my query, making it hard to diagnose.

      org.apache.spark.sql.AnalysisException: expression '`randomColumn`' is neither present in the group by, nor is it an aggregate function. Add to group by or wrap in first() (or first_value) if you don't care which value you get.;
      

      Note in the code below, I forgot to add .over(weeklyWindow) in the line for withColumn("user_count"...

      spark.read.load("/some-data")
        .withColumn("date_dt", to_date($"date"))
        .withColumn("year", year($"date_dt"))
        .withColumn("week", weekofyear($"date_dt"))
        .withColumn("user_count", count($"userId"))
        .withColumn("daily_max_in_week", max($"user_count").over(weeklyWindow))
      )
      

      CC: Michael Armbrust

        Attachments

          Activity

            People

            • Assignee:
              jiangxb1987 Xingbo Jiang
              Reporter:
              cheffpj Pat McDonough
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: