Skip to content

Commit

Permalink
Merge e74313d into fb3c27f
Browse files Browse the repository at this point in the history
  • Loading branch information
RustedBones authored Oct 17, 2023
2 parents fb3c27f + e74313d commit 179431b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,31 @@ private[types] object ConverterProvider {
import c.universe._
val tpe = weakTypeOf[T]
val r = fromAvroInternal(c)(tpe)
debug(s"ConverterProvider.fromAvroImpl[$tpe]:")
debug(r)
debug(c)(s"ConverterProvider.fromAvroImpl[$tpe]:", r)
c.Expr[GenericRecord => T](r)
}

def toAvroImpl[T: c.WeakTypeTag](c: blackbox.Context): c.Expr[T => GenericRecord] = {
import c.universe._
val tpe = weakTypeOf[T]
val r = toAvroInternal(c)(tpe)
debug(s"ConverterProvider.toAvroInternal[$tpe]:")
debug(r)
debug(c)(s"ConverterProvider.toAvroInternal[$tpe]:", r)
c.Expr[T => GenericRecord](r)
}

def fromTableRowImpl[T: c.WeakTypeTag](c: blackbox.Context): c.Expr[TableRow => T] = {
import c.universe._
val tpe = weakTypeOf[T]
val r = fromTableRowInternal(c)(tpe)
debug(s"ConverterProvider.fromTableRowImpl[$tpe]:")
debug(r)
debug(c)(s"ConverterProvider.fromTableRowImpl[$tpe]:", r)
c.Expr[TableRow => T](r)
}

def toTableRowImpl[T: c.WeakTypeTag](c: blackbox.Context): c.Expr[T => TableRow] = {
import c.universe._
val tpe = weakTypeOf[T]
val r = toTableRowInternal(c)(tpe)
debug(s"ConverterProvider.toTableRowImpl[$tpe]:")
debug(r)
debug(c)(s"ConverterProvider.toTableRowImpl[$tpe]:", r)
c.Expr[T => TableRow](r)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@
package com.spotify.scio.bigquery.types

import com.spotify.scio.bigquery.BigQuerySysProps
import org.slf4j.LoggerFactory

import scala.reflect.macros._
import scala.reflect.runtime.universe._

private[types] object MacroUtil {
private[this] val logger = LoggerFactory.getLogger(this.getClass)

// Case class helpers for runtime reflection

def isCaseClass(t: Type): Boolean =
Expand Down Expand Up @@ -68,9 +65,9 @@ private[types] object MacroUtil {

// Debugging

@inline def debug(msg: Any): Unit =
@inline def debug(c: blackbox.Context)(h: String, t: c.Tree): Unit =
if (BigQuerySysProps.Debug.value("false").toBoolean) {
logger.info(msg.toString)
c.echo(c.enclosingPosition, s"$h: $t")
}

// Namespace helpers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ private[types] object SchemaProvider {
case t if isCaseClass(t) => toFields(t)
case t => throw new RuntimeException(s"Unsupported type $t")
}
val r = new TableSchema().setFields(fields.toList.asJava)
debug(s"SchemaProvider.schemaOf[${typeOf[T]}]:")
debug(r)
r
new TableSchema().setFields(fields.toList.asJava)
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ private[types] object TypeProvider {

c.abort(c.enclosingPosition, error)
}
debug(s"TypeProvider.toTableImpl:")
debug(r)
debug(c)(s"TypeProvider.toTableImpl", r)

if (shouldDumpClassesForPlugin) {
dumpCodeForScalaPlugin(c)(Seq.empty, caseClassTree, name)
Expand Down Expand Up @@ -366,8 +365,7 @@ private[types] object TypeProvider {
)
case t => c.abort(c.enclosingPosition, s"Invalid annotation $t")
}
debug(s"TypeProvider.schemaToType[$schema]:")
debug(r)
debug(c)(s"TypeProvider.schemaToType[$schema]:", r)

if (shouldDumpClassesForPlugin) {
dumpCodeForScalaPlugin(c)(records, caseClassTree, name)
Expand Down

0 comments on commit 179431b

Please sign in to comment.