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

    https://github.com/apache/spark/pull/14539#discussion_r74064642
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ---
    @@ -656,40 +656,37 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] 
with Logging {
        * Create an inline table (a virtual table in Hive parlance).
        */
       override def visitInlineTable(ctx: InlineTableContext): LogicalPlan = 
withOrigin(ctx) {
    -    // Get the backing expressions.
    -    val expressions = ctx.expression.asScala.map { eCtx =>
    -      val e = expression(eCtx)
    -      assert(e.foldable, "All expressions in an inline table must be 
constants.", eCtx)
    -      e
    -    }
    -
    -    // Validate and evaluate the rows.
    -    val (structType, structConstructor) = expressions.head.dataType match {
    -      case st: StructType =>
    -        (st, (e: Expression) => e)
    -      case dt =>
    -        val st = CreateStruct(Seq(expressions.head)).dataType
    -        (st, (e: Expression) => CreateStruct(Seq(e)))
    -    }
    -    val rows = expressions.map {
    -      case expression =>
    -        val safe = Cast(structConstructor(expression), structType)
    -        safe.eval().asInstanceOf[InternalRow]
    +    // Create expressions.
    +    val rows = ctx.expression.asScala.map { e =>
    +      expression(e) match {
    +        case CreateStruct(children) => children
    +        case child => Seq(child)
    +      }
         }
     
    -    // Construct attributes.
    -    val baseAttributes = 
structType.toAttributes.map(_.withNullability(true))
    -    val attributes = if (ctx.identifierList != null) {
    -      val aliases = visitIdentifierList(ctx.identifierList)
    -      assert(aliases.size == baseAttributes.size,
    -        "Number of aliases must match the number of fields in an inline 
table.", ctx)
    -      baseAttributes.zip(aliases).map(p => p._1.withName(p._2))
    +    // Resolve aliases.
    +    val numExpectedColumns = rows.head.size
    +    val aliases = if (ctx.identifierList != null) {
    +      val names = visitIdentifierList(ctx.identifierList)
    +      assert(names.size == numExpectedColumns,
    --- End diff --
    
    It uses a parser only version of assert that throws a ParseException: 
https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParserUtils.scala#L81
    
    Come to think of it, we might need to rename it because people expect that 
assert calls can be elided. That is for a different PR though.


---
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.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to