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

    https://github.com/apache/spark/pull/993#discussion_r13495163
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/GeneratedRow.scala
 ---
    @@ -0,0 +1,833 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql
    +package catalyst
    +package expressions
    +
    +import types._
    +
    +object DumpByteCode {
    +  import scala.sys.process._
    +  val dumpDirectory = util.getTempFilePath("sparkSqlByteCode")
    +  dumpDirectory.mkdir()
    +
    +  def apply(obj: Any): Unit = {
    +    val generatedClass = obj.getClass
    +    val classLoader =
    +      generatedClass
    +        .getClassLoader
    +        .asInstanceOf[scala.tools.nsc.interpreter.AbstractFileClassLoader]
    +    val generatedBytes = classLoader.classBytes(generatedClass.getName)
    +
    +    val packageDir = new java.io.File(dumpDirectory, 
generatedClass.getPackage.getName)
    +    if (!packageDir.exists()) { packageDir.mkdir() }
    +
    +    val classFile =
    +      new java.io.File(packageDir, 
generatedClass.getName.split("\\.").last + ".class")
    +
    +    val outfile = new java.io.FileOutputStream(classFile)
    +    outfile.write(generatedBytes)
    +    outfile.close()
    +
    +    println(
    +      s"javap -p -v -classpath ${dumpDirectory.getCanonicalPath} 
${generatedClass.getName}".!!)
    +  }
    +}
    +
    +object CodeGeneration
    +
    +class CodeGenerator extends Logging {
    --- End diff --
    
    Would be helpful to add class header comment to describe the usage of this 
class in bigger context.


---
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.
---

Reply via email to