Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add function descs, examples in comments, and indentation.
  • Loading branch information
dongjoon-hyun committed Jun 29, 2016
commit fcfccee5349cde657d7765d2e78948125a962045
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,23 @@ abstract class ExplodeBase(child: Expression, position: Boolean)
override def elementSchema: StructType = child.dataType match {
case ArrayType(et, containsNull) =>
if (position) {
new StructType().add("pos", IntegerType, false).add("col", et, containsNull)
new StructType()
.add("pos", IntegerType, false)
.add("col", et, containsNull)
} else {
new StructType().add("col", et, containsNull)
new StructType()
.add("col", et, containsNull)
}
case MapType(kt, vt, valueContainsNull) =>
if (position) {
new StructType().add("pos", IntegerType, false).add("key", kt, false)
new StructType()
.add("pos", IntegerType, false)
.add("key", kt, false)
.add("value", vt, valueContainsNull)
} else {
new StructType().add("key", kt, false).add("value", vt, valueContainsNull)
new StructType()
.add("key", kt, false)
.add("value", vt, valueContainsNull)
}
}

Expand Down Expand Up @@ -159,21 +166,35 @@ abstract class ExplodeBase(child: Expression, position: Boolean)

/**
* Given an input array produces a sequence of rows for each value in the array.
*
* {{{
* SELECT explode(array(10,20)) ->
* 10
* 20
* }}}
*/
// scalastyle:off line.size.limit
@ExpressionDescription(
usage = "_FUNC_(a) - Separates the elements of array a into multiple rows, or the elements of map a into multiple rows and columns.")
usage = "_FUNC_(a) - Separates the elements of array a into multiple rows, or the elements of map a into multiple rows and columns.",
extended = "> SELECT _FUNC_(array(10,20));\n 10\n 20")
// scalastyle:on line.size.limit
case class Explode(child: Expression)
extends ExplodeBase(child, position = false) with Serializable {
Copy link
Contributor

Choose a reason for hiding this comment

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

case classes are automatically serializable so you don't need this i think

Copy link
Contributor

Choose a reason for hiding this comment

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

also you don't need the { }

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm. Okay. I will try to remove Serializable.

}

/**
* Given an input array produces a sequence of rows for each position and value in the array.
Copy link
Contributor

Choose a reason for hiding this comment

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

btw since the expression description might be difficult to see without line wrapping, it'd also be better to put an example here.

Copy link
Contributor

Choose a reason for hiding this comment

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

also you don't need the { }

*
* {{{
* SELECT explode(array(10,20)) ->
* 0 10
* 1 20
* }}}
*/
// scalastyle:off line.size.limit
@ExpressionDescription(
Copy link
Contributor

Choose a reason for hiding this comment

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

an example would be useful.

usage = "_FUNC_(a) - Separates the elements of array a into multiple rows with positions, or the elements of a map into multiple rows and columns with positions.")
usage = "_FUNC_(a) - Separates the elements of array a into multiple rows with positions, or the elements of a map into multiple rows and columns with positions.",
extended = "> SELECT _FUNC_(array(10,20));\n 0\t10\n 1\t20")
// scalastyle:on line.size.limit
case class PosExplode(child: Expression)
extends ExplodeBase(child, position = true) with Serializable {
Copy link
Contributor

Choose a reason for hiding this comment

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

case classes are automatically serializable so you don't need this i think

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, this is needed. Without this, there occurs runtime errors. This happens usually when extending abstract base classes.

Expand Down