Skip to content

Commit

Permalink
Add a nice user-facing error for scalar subqueries inside VALUES clause
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirg-db committed Sep 16, 2024
1 parent 931ab06 commit fd9a01c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions common/utils/src/main/resources/error/error-conditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -1821,6 +1821,12 @@
],
"sqlState" : "42704"
},
"INLINE_TABLE_CONTAINS_SCALAR_SUBQUERY" : {
"message" : [
"Scalar subqueries inside VALUES clause are not supported"
],
"sqlState" : "0A000"
},
"INSERT_COLUMN_ARITY_MISMATCH" : {
"message" : [
"Cannot write to <tableName>, the reason is"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB
context = u.origin.getQueryContext,
summary = u.origin.context.summary)

case u: UnresolvedInlineTable if unresolvedInlineTableContainsScalarSubquery(u) =>
throw QueryCompilationErrors.inlineTableContainsScalarSubquery(u)

case command: V2PartitionCommand =>
command.table match {
case r @ ResolvedTable(_, _, table, _) => table match {
Expand Down Expand Up @@ -1559,6 +1562,14 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB
case _ =>
}
}

private def unresolvedInlineTableContainsScalarSubquery(
unresolvedInlineTable: UnresolvedInlineTable
) = {
unresolvedInlineTable.rows.exists { row =>
row.exists { _.isInstanceOf[ScalarSubquery] }
}
}
}

// a heap of the preempted error that only keeps the top priority element, representing the sole
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4112,4 +4112,12 @@ private[sql] object QueryCompilationErrors extends QueryErrorsBase with Compilat
"expr" -> expr.toString),
origin = expr.origin)
}

def inlineTableContainsScalarSubquery(inlineTable: LogicalPlan): Throwable = {
new AnalysisException(
errorClass = "INLINE_TABLE_CONTAINS_SCALAR_SUBQUERY",
messageParameters = Map(),
origin = inlineTable.origin
)
}
}

0 comments on commit fd9a01c

Please sign in to comment.