Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,17 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
// Add where.
val withFilter = relation.optionalMap(where)(filter)

// Add project.
val namedExpressions = expressions.map {
case e: NamedExpression => e
case e: Expression => UnresolvedAlias(e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: case e: _ => UnresolvedAlias(e)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the type of expressions is Expression, so i think
case e: _ => UnresolvedAlias(e) and case e: Expression => UnresolvedAlias(e) is equivalent.
Did have other reasons to change this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a style issue.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The style is updated, review this, please.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried, "case e: _ => UnresolveAlias(e)" will occur "unbound wildcard type" complie error. I will revert to "case e: Expression => UnresolvedAlias(e)".

}
val withProject = if (namedExpressions.nonEmpty) {
Project(namedExpressions, withFilter)
} else {
withFilter
}

// Create the attributes.
val (attributes, schemaLess) = if (colTypeList != null) {
// Typed return columns.
Expand All @@ -358,7 +369,7 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
expressions,
string(script),
attributes,
withFilter,
withProject,
withScriptIOSchema(
ctx, inRowFormat, recordWriter, outRowFormat, recordReader, schemaLess))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,17 @@ class HiveDDLCommandSuite extends PlanTest with SQLTestUtils with TestHiveSingle
"func", Seq.empty, plans.table("e"), null)

comparePlans(plan1,
p.copy(child = p.child.where('f < 10), output = Seq('key.string, 'value.string)))
p.copy(
child = p.child.where('f < 10).select(UnresolvedAttribute("a"), UnresolvedAttribute("b")),
output = Seq('key.string, 'value.string)))
comparePlans(plan2,
p.copy(output = Seq('c.string, 'd.string)))
p.copy(
child = p.child.select(UnresolvedAttribute("a"), UnresolvedAttribute("b")),
output = Seq('c.string, 'd.string)))
comparePlans(plan3,
p.copy(output = Seq('c.int, 'd.decimal(10, 0))))
p.copy(
child = p.child.select(UnresolvedAttribute("a"), UnresolvedAttribute("b")),
output = Seq('c.int, 'd.decimal(10, 0))))
}

test("use backticks in output of Script Transform") {
Expand Down