Skip to content

[SPARK-25444][SQL] Refactor GenArrayData.genCodeToCreateArrayData method#22439

Closed
kiszk wants to merge 3 commits intoapache:masterfrom
kiszk:SPARK-25444
Closed

[SPARK-25444][SQL] Refactor GenArrayData.genCodeToCreateArrayData method#22439
kiszk wants to merge 3 commits intoapache:masterfrom
kiszk:SPARK-25444

Conversation

@kiszk
Copy link
Copy Markdown
Member

@kiszk kiszk commented Sep 17, 2018

What changes were proposed in this pull request?

This PR makes GenArrayData.genCodeToCreateArrayData method simple by using ArrayData.createArrayData method.

Before this PR, genCodeToCreateArrayData method was complicated

  • Generated a temporary Java array to create ArrayData
  • Had separate code generation path to assign values for GenericArrayData and UnsafeArrayData

After this PR, the method

  • Directly generates GenericArrayData or UnsafeArrayData without a temporary array
  • Has only code generation path to assign values

How was this patch tested?

Existing UTs

@SparkQA
Copy link
Copy Markdown

SparkQA commented Sep 17, 2018

Test build #96120 has finished for PR 22439 at commit 24fbf74.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

val isNullAssignment = if (!isMapKey) {
s"$arrayDataName.setNullAt($i);"

if (eval.isNull == TrueLiteral) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need this case?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Since I saw the following case, I added this condition to reduce the generated Java byte code size.

if (true) {
 ...
} else {
 ...
}

I am neutral on keeping or removing this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think we need the case because there are very few expressions that set isNull to TrueLiteral.

arrayDataName, elementType, i.toString, eval.value)

val assignment = if (eval.isNull == FalseLiteral) {
s"\n$setArrayElement\n"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: do we need to surround setArrayElement with \ns? Only setArrayElement should work?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It works functionally without \n. This is only for readability of generation code to avoid this output:
arrayData.setInt(0, 0);arrayData.setInt(1, 1);...

WDYT?

val setArrayElement = CodeGenerator.setArrayElement(
arrayDataName, elementType, i.toString, eval.value)

val assignment = if (eval.isNull == FalseLiteral) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about taking an argument elements: Seq[Expression] instead of elementCodes: Seq[ExprCode] and use element.nullable instead of eval.isNull if we want to skip null-check when the nullable is false?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I see. We will do if (!element.nullable || eval.isNull == FalseLiteral) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we don't need || eval.isNull == FalseLiteral?

val setArrayElement = CodeGenerator.setArrayElement(
arrayDataName, elementType, i.toString, eval.value)

val assignment = if (!expr.nullable || eval.isNull == FalseLiteral) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we don't need || eval.isNull == FalseLiteral?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I see, looks redudant

@SparkQA
Copy link
Copy Markdown

SparkQA commented Sep 17, 2018

Test build #96133 has finished for PR 22439 at commit 2286b6e.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@ueshin
Copy link
Copy Markdown
Member

ueshin commented Sep 17, 2018

LGTM.

@SparkQA
Copy link
Copy Markdown

SparkQA commented Sep 17, 2018

Test build #96144 has finished for PR 22439 at commit fff3361.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@ueshin
Copy link
Copy Markdown
Member

ueshin commented Sep 18, 2018

Thanks! merging to master.

@asfgit asfgit closed this in acc6452 Sep 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants