Skip to content
Snippets Groups Projects
Commit 66554596 authored by Dongjoon Hyun's avatar Dongjoon Hyun Committed by Reynold Xin
Browse files

[SPARK-15265][SQL][MINOR] Fix Union query error message indentation

## What changes were proposed in this pull request?

This issue fixes the error message indentation consistently with other set queries (EXCEPT/INTERSECT).

**Before (4 lines)**
```
scala> sql("(select 1) union (select 1, 2)").head
org.apache.spark.sql.AnalysisException:
Unions can only be performed on tables with the same number of columns,
 but one table has '2' columns and another table has
 '1' columns;
```

**After (one-line)**
```
scala> sql("(select 1) union (select 1, 2)").head
org.apache.spark.sql.AnalysisException: Unions can only be performed on tables with the same number of columns, but one table has '2' columns and another table has '1' columns;
```
**Reference (EXCEPT / INTERSECT)**
```
scala> sql("(select 1) intersect (select 1, 2)").head
org.apache.spark.sql.AnalysisException: Intersect can only be performed on tables with the same number of columns, but the left table has 1 columns and the right has 2;
```

## How was this patch tested?

Manual.

Author: Dongjoon Hyun <dongjoon@apache.org>

Closes #13043 from dongjoon-hyun/SPARK-15265.
parent 3ff01205
No related branches found
No related tags found
No related merge requests found
......@@ -241,16 +241,15 @@ trait CheckAnalysis extends PredicateHelper {
case s @ SetOperation(left, right) if left.output.length != right.output.length =>
failAnalysis(
s"${s.nodeName} can only be performed on tables with the same number of columns, " +
s"but the left table has ${left.output.length} columns and the right has " +
s"${right.output.length}")
s"but the left table has ${left.output.length} columns and the right has " +
s"${right.output.length}")
case s: Union if s.children.exists(_.output.length != s.children.head.output.length) =>
val firstError = s.children.find(_.output.length != s.children.head.output.length).get
failAnalysis(
s"""
|Unions can only be performed on tables with the same number of columns,
| but one table has '${firstError.output.length}' columns and another table has
| '${s.children.head.output.length}' columns""".stripMargin)
s"Unions can only be performed on tables with the same number of columns, " +
s"but one table has '${firstError.output.length}' columns and another table has " +
s"'${s.children.head.output.length}' columns")
case p if p.expressions.exists(ScalarSubquery.hasCorrelatedScalarSubquery) =>
p match {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment