Github user JoshRosen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10894#discussion_r52691349
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GenerateOrdering.scala
 ---
    @@ -138,3 +138,32 @@ object GenerateOrdering extends 
CodeGenerator[Seq[SortOrder], Ordering[InternalR
         
CodeGenerator.compile(code).generate(ctx.references.toArray).asInstanceOf[BaseOrdering]
       }
     }
    +
    +/**
    + * A lazily generate row ordering comparator.
    + */
    +class LazilyGenerateOrdering(val ordering: Seq[SortOrder]) extends 
Ordering[InternalRow] {
    +
    +  def this(ordering: Seq[SortOrder], inputSchema: Seq[Attribute]) =
    +    this(ordering.map(BindReferences.bindReference(_, inputSchema)))
    +
    +  @transient
    +  lazy val generatedOrdering = GenerateOrdering.generate(ordering)
    --- End diff --
    
    Will this use of `lazy val` incur a performance penalty due to having to 
check whether it has been initialized on each call to `compare()`? If so, I 
wonder whether we could eagerly initialize the ordering in the constructor then 
re-initialize on executors as part of `readObject()`, e.g. `@transient 
private[this] var generatedOrdering = ...`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to