Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make macro print debug logs if bigquery.types.debug enabled #5033

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Comment on lines -50 to -51
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this now covered elsewhere?

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