Skip to content

Conversation

@viirya
Copy link
Member

@viirya viirya commented Oct 25, 2015

JIRA: https://issues.apache.org/jira/browse/SPARK-9162

Currently ScalaUDF extends CodegenFallback and doesn't provide code generation implementation. This path implements code generation for ScalaUDF.

Copy link
Contributor

Choose a reason for hiding this comment

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

can we put these branches in a loop?

Copy link
Member Author

Choose a reason for hiding this comment

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

You meant using a script to generate it like the f?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm missing something, but I think you can just write a loop instead of having branches?

...
val funcClassName = callFunc.getClass.getName
...
val evals = children.map(_.gen(ctx))
...
// generate callFunc

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, part of this can be reduced like you show. But seems we will still have a (smaller) pattern matching, at least for something like this: classOf[(Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any) => Any].getName. I will do it later.

Copy link
Contributor

Choose a reason for hiding this comment

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

For that one, can you just do callFunc.getClass.getName?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why wouldn't it work? Isn't that better because we can even specialize it?

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, you are right. I should have it a try.

Copy link
Member Author

Choose a reason for hiding this comment

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

As I tried, using function.getClass.getName causes java.lang.Exception: failed to compile: org.codehaus.janino.JaninoRuntimeException: Incompatible return types in ZeroArgument UDF test. If I use classOf[() => Any].getName for this zero argument function, it is ok then.

Because other tests are passed, I added a condition to take care of zero argument function now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like function.getClass.getName will cause other problem (java.lang.IncompatibleClassChangeError) as the following failed tests show.

Copy link
Member Author

Choose a reason for hiding this comment

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

But classOf[(Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any) => Any].getName works. So I will revert to it then.

@SparkQA
Copy link

SparkQA commented Oct 25, 2015

Test build #44315 has finished for PR 9270 at commit 5e8efea.

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

@SparkQA
Copy link

SparkQA commented Oct 26, 2015

Test build #44337 has finished for PR 9270 at commit b92ca97.

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

@viirya
Copy link
Member Author

viirya commented Oct 26, 2015

retest this please.

…sChangeError. But classOf[(Any) => Any].getName works.
@SparkQA
Copy link

SparkQA commented Oct 26, 2015

Test build #44343 has finished for PR 9270 at commit a9f31c9.

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

@viirya
Copy link
Member Author

viirya commented Oct 28, 2015

@rxin any other comments?

@viirya
Copy link
Member Author

viirya commented Oct 30, 2015

ping @rxin

@rxin
Copy link
Contributor

rxin commented Nov 1, 2015

I'm traveling right now. Will take a look when I get back.

cc @davies also.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why index here? All freshName will be unique.

@davies
Copy link
Contributor

davies commented Nov 2, 2015

@viirya Could you add unit tests for every data types? it's easy to be wrong for some types.

@SparkQA
Copy link

SparkQA commented Nov 3, 2015

Test build #44893 has finished for PR 9270 at commit 4a1ec67.

  • This patch fails Scala style tests.
  • This patch does not merge cleanly.
  • This patch adds the following public classes (experimental):\n * case class RegisteredExecutor(hostname: String) extends CoarseGrainedClusterMessage\n * public class JavaIsotonicRegressionExample\n * public class JavaNaiveBayesExample\n * case class UnresolvedStar(target: Option[Seq[String]]) extends Star with Unevaluable\n

@viirya
Copy link
Member Author

viirya commented Nov 3, 2015

@davies May I ask what the data types you meant? scala.Function0 to scala.Function22?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to save the index when you push the expression into ctx.references, otherwise it's easy to be wrong.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added that. Thanks.

@davies
Copy link
Contributor

davies commented Nov 3, 2015

@viirya I meant the SQL data types, for example, DateType, ArrayType, StructType and so on.

@SparkQA
Copy link

SparkQA commented Nov 3, 2015

Test build #44897 has finished for PR 9270 at commit abb3750.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):\n * case class UnresolvedStar(target: Option[Seq[String]]) extends Star with Unevaluable\n

@SparkQA
Copy link

SparkQA commented Nov 3, 2015

Test build #44898 has finished for PR 9270 at commit 6b94a38.

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

@davies
Copy link
Contributor

davies commented Nov 6, 2015

@viirya Do you have time to add more tests for this?

@viirya
Copy link
Member Author

viirya commented Nov 6, 2015

@davies yes. I will do it soon.

@SparkQA
Copy link

SparkQA commented Nov 6, 2015

Test build #45199 has finished for PR 9270 at commit b355895.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):\n * final class ShuffleSortDataFormat extends SortDataFormat<PackedRecordPointer, LongArray>\n * final class UnsafeSortDataFormat extends SortDataFormat<RecordPointerAndKeyPrefix, LongArray>\n

@davies
Copy link
Contributor

davies commented Nov 6, 2015

@viirya This patch looks good to me now. Another thing is that we can generate code for catalyst converter now (see RowEncoder), and we have a plan to replace catalyst converter with the generated one. Do you want to try it in this PR or leave that as a follow up one?

cc @marmbrus

@viirya
Copy link
Member Author

viirya commented Nov 6, 2015

@davies I think it would be better to do that in a follow up pr. Thanks.

@davies
Copy link
Contributor

davies commented Nov 6, 2015

LGTM, merging this into master and 1.6 branch.

asfgit pushed a commit that referenced this pull request Nov 6, 2015
JIRA: https://issues.apache.org/jira/browse/SPARK-9162

Currently ScalaUDF extends CodegenFallback and doesn't provide code generation implementation. This path implements code generation for ScalaUDF.

Author: Liang-Chi Hsieh <[email protected]>

Closes #9270 from viirya/scalaudf-codegen.

(cherry picked from commit 574141a)
Signed-off-by: Davies Liu <[email protected]>
@asfgit asfgit closed this in 574141a Nov 6, 2015
@viirya viirya deleted the scalaudf-codegen branch December 27, 2023 18:18
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.

4 participants