Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
RustedBones committed Feb 26, 2024
1 parent 30cdf43 commit 9ecd001
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 32 deletions.
11 changes: 10 additions & 1 deletion src/main/scala/com/spotify/scio/AnnotationTypeInjector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package com.spotify.scio

import java.io.File
import java.nio.charset.Charset
import java.nio.file.{Paths, Files as JFiles}
import java.nio.file.{Files as JFiles, Paths}
import com.google.common.base.Charsets
import com.google.common.hash.Hashing
import com.google.common.io.Files
Expand All @@ -34,6 +34,15 @@ import scala.collection.mutable

object AnnotationTypeInjector {
private val Log = Logger.getInstance(classOf[AnnotationTypeInjector])

// case classes implement Product trait
val CaseClassSuper: String = "_root_.scala.Product"
val CaseClassFunctions: Seq[String] = Seq(
"def productArity: _root_.scala.Int = ???",
"def productElement(n: _root_.scala.Int): _root_.scala.Any = ???",
"def canEqual(x: _root_.scala.Any): _root_.scala.Boolean = ???"
)

private val CaseClassArgs = """case\s+class\s+[^(]+\((.*)\).*""".r
private val TypeArg = """[a-zA-Z0-9_$]+\s*:\s*[a-zA-Z0-9._$]+([\[(](.*?)[)\]]+)?""".r
private val AlertEveryMissedXInvocations = 5
Expand Down
22 changes: 8 additions & 14 deletions src/main/scala/com/spotify/scio/AvroTypeInjector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ object AvroTypeInjector {
s"$AvroTNamespace.fromPath",
s"$AvroTNamespace.toSchema"
)
private val CaseClassSuper =
"_root_.scala.Product"

private val HasAvroAnnotationSuper =
"_root_.com.spotify.scio.avro.types.AvroType.HasAvroAnnotation"

Expand All @@ -46,19 +45,14 @@ final class AvroTypeInjector extends AnnotationTypeInjector {
override def injectFunctions(source: ScTypeDefinition): Seq[String] =
source match {
case c: ScClass if avroAnnotation(c).isDefined =>
val result = for {
cc <- Option(c.containingClass)
qn <- Option(cc.getQualifiedName)
val fields = for {
cc <- Option(c.containingClass).toSeq
qn <- Option(cc.getQualifiedName).toSeq
parent = qn.init
defs <- {
generatedCaseClasses(parent, c)
.find(_.contains(HasAvroAnnotationSuper))
.map(getApplyPropsSignature)
.map(v => s"def $v = ???")
}
} yield defs

result.toSeq
cls <- generatedCaseClasses(parent, c).find(_.contains(HasAvroAnnotationSuper)).toSeq
v <- getApplyPropsSignature(cls)
} yield s"def $v = ???"
CaseClassFunctions ++ fields
case _ => Seq.empty
}

Expand Down
26 changes: 9 additions & 17 deletions src/main/scala/com/spotify/scio/BigQueryTypeInjector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ object BigQueryTypeInjector {
s"$BQTNamespace.toTable"
)

private val CaseClassSuper =
"_root_.scala.Product"
private val HasAnnotationSuper =
"_root_.com.spotify.scio.bigquery.types.BigQueryType.HasAnnotation"

Expand Down Expand Up @@ -78,14 +76,12 @@ object BigQueryTypeInjector {
annotation match {
case a if a.contains(FromQuery) =>
val simple = """
|def query: _root_.java.lang.String = ???
|def queryRaw: _root_.java.lang.String = ???
|""".stripMargin

bqQuerySignature(c)
.map { params =>
simple + s"""
|def query($params): _root_.java.lang.String = ???
|def queryAsSource($params): _root_.com.spotify.scio.bigquery.Query = ???
|""".stripMargin
}
Expand All @@ -112,20 +108,16 @@ final class BigQueryTypeInjector extends AnnotationTypeInjector {
override def injectFunctions(source: ScTypeDefinition): Seq[String] =
source match {
case c: ScClass if bqAnnotation(c).isDefined =>
val result = for {
cc <- Option(c.containingClass)
qn <- Option(cc.getQualifiedName)
val fields = for {
cc <- Option(c.containingClass).toSeq
qn <- Option(cc.getQualifiedName).toSeq
parent = qn.init
defs <- {
generatedCaseClasses(parent, c)
.find(_.contains(HasAnnotationSuper))
.map(getApplyPropsSignature)
.map(v => s"def $v = ???")
}
} yield defs

result.toSeq
case _ => Seq.empty
cls <- generatedCaseClasses(parent, c).find(_.contains(HasAnnotationSuper)).toSeq
v <- getApplyPropsSignature(cls)
} yield s"def $v = ???"
CaseClassFunctions ++ fields
case _ =>
Seq.empty
}

override def injectSupers(source: ScTypeDefinition): Seq[String] =
Expand Down

0 comments on commit 9ecd001

Please sign in to comment.