Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7bf45dd
Adds zip function to sparksql
DylanGuedes Apr 11, 2018
99848fe
Changes zip construction
DylanGuedes Apr 13, 2018
27b0bc2
Changes tests and uses builtin namespace in pyspark
DylanGuedes Apr 13, 2018
93826b6
fixes examples string and uses struct instead of arrays
DylanGuedes Apr 26, 2018
a7e29f6
working pyspark zip_lists
DylanGuedes May 11, 2018
7130fec
Fixes java version when arrays have different lengths
DylanGuedes May 11, 2018
d552216
remove unused variables
DylanGuedes May 11, 2018
1fecef4
rename zip_lists to zip
DylanGuedes May 11, 2018
f71151a
adds expression tests and uses strip margin syntax
DylanGuedes May 12, 2018
6b4bc94
Adds variable number of inputs to zip function
DylanGuedes May 15, 2018
1549928
uses foldleft instead of while for iterating
DylanGuedes May 15, 2018
9f7bba1
rewritten some notation
DylanGuedes May 16, 2018
3ba2b4f
fix dogencode generation
DylanGuedes May 17, 2018
3a59201
Adds new tests, uses lazy val and split calls
DylanGuedes May 17, 2018
6462fa8
uses splitFunction
DylanGuedes May 17, 2018
8b1eb7c
move arraytypes to private member
DylanGuedes May 18, 2018
2bfba80
adds binary and array of array tests
DylanGuedes May 18, 2018
c3b062c
uses stored array types names
DylanGuedes May 18, 2018
d9b95c4
split input function using ctxsplitexpression
DylanGuedes May 18, 2018
26bbf66
uses splitexpression for inputs
DylanGuedes May 19, 2018
d9ad04d
Refactor cases, add new tests with empty seq, check size of array
DylanGuedes May 22, 2018
f29ee1c
Check empty seq as input
DylanGuedes May 22, 2018
c58d09c
Uses switch instead of if
DylanGuedes May 23, 2018
38fa996
refactor switch and else methods
DylanGuedes May 23, 2018
5b3066b
uses if instead of switch
DylanGuedes May 30, 2018
759a4d4
Not using storedarrtype anymore
DylanGuedes Jun 4, 2018
68e69db
split between empty and nonempty codegen
DylanGuedes Jun 4, 2018
12b3835
remove ternary if
DylanGuedes Jun 4, 2018
643cb9b
Fixes null values evaluation and adds back tests
DylanGuedes Jun 4, 2018
5876082
move to else
DylanGuedes Jun 4, 2018
0223960
remove unused lines
DylanGuedes Jun 4, 2018
2b88387
use zip alias
DylanGuedes Jun 5, 2018
bbc20ee
using same docs for all apis
DylanGuedes Jun 8, 2018
8d3a838
adds transient to method
DylanGuedes Jun 8, 2018
d8f3dea
rename zip function to arrays_zip
DylanGuedes Jun 10, 2018
3d68ea9
adds pretty_name for arrays_zip
DylanGuedes Jun 11, 2018
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
uses splitexpression for inputs
Signed-off-by: DylanGuedes <[email protected]>
  • Loading branch information
DylanGuedes committed Jun 4, 2018
commit 26bbf66ce9af9e66544bee60976181b15b84a553
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,25 @@ case class Zip(children: Seq[Expression]) extends Expression with ExpectsInputTy
| $arrCardinality[$index] = 0;
|}
|$storedArrTypes[$index] = "${arrayElementTypes(index)}";
|$biggestCardinality[0] = Math.max($biggestCardinality[0], $arrCardinality[$index]);
|$biggestCardinality = Math.max($biggestCardinality, $arrCardinality[$index]);
""".stripMargin
}

val inputsSplitted = ctx.splitExpressions(
expressions = inputs,
funcName = "getInputAndCardinality",
returnType = "int",
makeSplitFunction = body =>
s"""
|$body
|return $biggestCardinality;
""".stripMargin,
foldFunctions = _.map(funcCall => s"$biggestCardinality = $funcCall;").mkString("\n"),
arguments =
("ArrayData[]", arrVals) ::
("int[]", arrCardinality) ::
("String[]", storedArrTypes) ::
("int[]", biggestCardinality) :: Nil)
("int", biggestCardinality) :: Nil)

val myobject = ctx.freshName("myobject")
val j = ctx.freshName("j")
Expand All @@ -205,32 +212,24 @@ case class Zip(children: Seq[Expression]) extends Expression with ExpectsInputTy
val fillValue = arrayElementTypes.distinct.map { case (elementType) =>
val getArrValsItem = CodeGenerator.getValue(s"$arrVals[$j]", elementType, i)
s"""
| if ($storedArrTypes[$j] == "${elementType}") {
| $myobject[$j] = $getArrValsItem;
| }
|if ($storedArrTypes[$j] == "${elementType}") {
| $myobject[$j] = $getArrValsItem;
|}
Copy link
Member

Choose a reason for hiding this comment

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

Should continue to avoid extra evaluation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't get it, how?

""".stripMargin
}

val fillValueSplitted = ctx.splitExpressions(
expressions = fillValue,
funcName = "fillValue",
arguments =
("int", j) ::
("Array[] Object", myobject) :: Nil)
}.mkString("\n")

ev.copy(s"""
|ArrayData[] $arrVals = new ArrayData[$numberOfArrays];
|int[] $arrCardinality = new int[$numberOfArrays];
|int[] $biggestCardinality = new int[1];
|$biggestCardinality[0] = 0;
|int $biggestCardinality = 0;
|String[] $storedArrTypes = new String[$numberOfArrays];
|$inputsSplitted
|Object[] $args = new Object[$biggestCardinality[0]];
|for (int $i = 0; $i < $biggestCardinality[0]; $i ++) {
|Object[] $args = new Object[$biggestCardinality];
|for (int $i = 0; $i < $biggestCardinality; $i ++) {
| Object[] $myobject = new Object[$numberOfArrays];
| for (int $j = 0; $j < $numberOfArrays; $j ++) {
| if ($arrVals[$j] != null && $arrCardinality[$j] > $i && !$arrVals[$j].isNullAt($i)) {
| $fillValueSplitted
| $fillValue
| } else {
| $myobject[$j] = null;
| }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package org.apache.spark.sql.catalyst.expressions

import org.apache.spark.SparkFunSuite
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.Row
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.types._

class CollectionExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
Expand Down Expand Up @@ -377,6 +377,25 @@ class CollectionExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper

checkEvaluation(Zip(Seq(literals(7), literals(10))),
List(Row(null, Array[Byte](1.toByte, 5.toByte))))
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add some tests with many input arrays? eg.100 or 1000 if needed in order to force the splitExpression to actually split the generated code in order to have test coverage for that? you can check if splitExpression is splitting the code in debug mode to be sure that it happens. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I checked and looks like the functions are being correctly splitted.


val longLiteral =
Literal.create((0 to 1000).toSeq, ArrayType(IntegerType))

checkEvaluation(Zip(Seq(literals(0), longLiteral)),
List(Row(9001, 0), Row(9002, 1), Row(9003, 2)) ++
(3 to 1000).map { Row(null, _) }.toList)

val manyLiterals = (0 to 1000).map { case (number) =>
Copy link
Member

Choose a reason for hiding this comment

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

... .map { _ => ?

Literal.create(Seq(1), ArrayType(IntegerType))
}.toSeq

val numbers = List(
Seq(9001) ++ (0 to 1000).map { case (number) => 1 }.toSeq,
Copy link
Member

Choose a reason for hiding this comment

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

ditto.

Seq(9002) ++ (0 to 1000).map { case (number) => null }.toSeq,
Seq(9003) ++ (0 to 1000).map { case (number) => null }.toSeq,
Seq(null) ++ (0 to 1000).map { case (number) => null }.toSeq)
Copy link
Member

Choose a reason for hiding this comment

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

How about creating Row here?

checkEvaluation(Zip(Seq(literals(0)) ++ manyLiterals),
List(Row(numbers(0): _*), Row(numbers(1): _*), Row(numbers(2): _*), Row(numbers(3): _*)))
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a case for something like Zip(Seq(null, literals(0))) or Zip(Seq(literals(0), null))?

Copy link
Member

Choose a reason for hiding this comment

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

Also what if Zip(Seq())?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to test the case with Seq(null, literals(0)), but it breaks before reaching checkEvalWithCodeGen/withoutCodegen (looks like when you iterate in a sequence with a null element it explodes). I checked and I don't saw any tests that accept Seq[Expression] testing this case (for instance: Concat turn null inputs in Literals with null values).

Should I change something?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried, but looks like I can't create an empty genericarray. I'm pushing a code with the tests that cover these scenarios commented so maybe anyone could give me suggestions while I look for another solution.


test("Array Min") {
Expand Down