Skip to content

Commit

Permalink
change to 9 parameters constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierZYXue committed Aug 13, 2024
1 parent faaba59 commit e1d7aee
Showing 1 changed file with 6 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@

package za.co.absa.spline.harvester.plugin.embedded

import java.lang.reflect.Method
import java.lang.reflect.Modifier.isStatic
import java.util.Optional

import io.github.classgraph.ClassGraph
import javax.annotation.Priority
import org.apache.hadoop.conf.Configuration
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.execution.datasources.{LogicalRelation, SaveIntoDataSourceCommand}
Expand All @@ -36,6 +31,10 @@ import za.co.absa.spline.harvester.plugin.embedded.BigQueryPlugin.SparkBigQueryC
import za.co.absa.spline.harvester.plugin.embedded.BigQueryPlugin._
import za.co.absa.spline.harvester.plugin.{BaseRelationProcessing, Plugin, RelationProviderProcessing}

import java.lang.reflect.Method
import java.lang.reflect.Modifier.isStatic
import java.util.Optional
import javax.annotation.Priority
import scala.collection.JavaConverters._
import scala.language.reflectiveCalls

Expand Down Expand Up @@ -143,33 +142,14 @@ object BigQueryPlugin {
def getParentProjectId: String
}
private val clazz = findPossiblyShadedClass("com.google.cloud", "com.google.cloud.spark.bigquery.SparkBigQueryConfig")
private val methodFrom7: Option[Method] = clazz
.getMethods
.find(
m => m.getName == "from"
&& isStatic(m.getModifiers)
&& m.getParameterTypes.length == 7
&& m.getReturnType.getSimpleName == "SparkBigQueryConfig"
)
private val methodFrom8: Option[Method] = clazz
.getMethods
.find(
m => m.getName == "from"
&& isStatic(m.getModifiers)
&& m.getParameterTypes.length == 8
&& m.getReturnType.getSimpleName == "SparkBigQueryConfig"
)
private val methodFrom9: Option[Method] = clazz
private val methodFrom: Method = clazz
.getMethods
.find(
m => m.getName == "from"
&& isStatic(m.getModifiers)
&& m.getParameterTypes.length == 9
&& (m.getParameterTypes.length == 7 || m.getParameterTypes.length == 8 || m.getParameterTypes.length == 9)
&& m.getReturnType.getSimpleName == "SparkBigQueryConfig"
)
private val methodFrom: Method = methodFrom7
.orElse(methodFrom8)
.orElse(methodFrom9)
.getOrElse(sys.error(s"Cannot find method `public static SparkBigQueryConfig from(... {7|8|9 args} ...)` in the class `$clazz`"))

object ImmutableMap {
Expand Down

0 comments on commit e1d7aee

Please sign in to comment.