Created
October 1, 2018 13:52
-
-
Save SemanticBeeng/2f98377970f7ae644f8fcdf99db9f3c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.yields.common.meta | |
import org.apache.spark.sql.Column | |
import org.apache.spark.sql.functions._ | |
import org.apache.spark.sql.types.StructType | |
import scala.annotation._ | |
import scala.meta._ | |
/** | |
* | |
*/ | |
object SparkTypeTransformer extends App { | |
val tree: Term = q"""concat_ws("--", col(rowKey), col("id"))""" | |
println(tree.structure) | |
tree match { | |
//case Term.Apply(function, List(arg1, arg2, arg3)) => | |
case q"$function(...$args)" ⇒ | |
println("calling " + function) | |
println("args " + args) | |
val exprs: Seq[Option[Column]] = args.head map { | |
case Lit(a1) => | |
Some(lit(a1)) | |
case Term.Apply(Term.Name("col"), List(Term.Name(name))) => | |
Some(col(name)) | |
case Term.Apply(Term.Name("col"), List(Lit.String(name))) => | |
Some(col(name)) | |
case _ ⇒ None | |
} | |
val expr = function match { | |
case Term.Name("concat_ws") ⇒ concat_ws(exprs(0).get.toString(), exprs(1).get, exprs(2).get) | |
} | |
println(s"expr=$expr") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment