Skip to content

Commit

Permalink
change to 9 parameters constructor (#823)
Browse files Browse the repository at this point in the history
* change to 9 parameters constructor

* add 7|8|9 parameters separately to be compatible with different version

* update

* change to 9 parameters constructor

* change to match parameter type length
  • Loading branch information
XavierZYXue authored Sep 3, 2024
1 parent a6f63b1 commit fd58cd0
Showing 1 changed file with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ class BigQueryPlugin(spark: SparkSession)

def bigQueryConfig = {
SparkBigQueryConfig.from(
ImmutableMap.copyOf(cmd.options.asJava),
cmd.options.asJava,
ImmutableMap.copyOf(spark.conf.getAll.asJava),
spark.sparkContext.hadoopConfiguration,
ImmutableMap.of,
0,
spark.sessionState.conf,
spark.version,
Optional.empty()
Optional.empty(),
true
)
}

Expand Down Expand Up @@ -145,9 +147,10 @@ object BigQueryPlugin {
.find(
m => m.getName == "from"
&& isStatic(m.getModifiers)
&& m.getParameterTypes.length == 7
&& (m.getParameterTypes.length == 7 || m.getParameterTypes.length == 8 || m.getParameterTypes.length == 9)
&& m.getReturnType.getSimpleName == "SparkBigQueryConfig"
).getOrElse(sys.error(s"Cannot find method `public static SparkBigQueryConfig from(... {7 args} ...)` in the class `$clazz`"))
)
.getOrElse(sys.error(s"Cannot find method `public static SparkBigQueryConfig from(... {7|8|9 args} ...)` in the class `$clazz`"))

object ImmutableMap {
type ImmutableMap = AnyRef
Expand All @@ -157,12 +160,22 @@ object BigQueryPlugin {
.getMethod("copyOf", classOf[java.util.Map[_, _]])
.invoke(imClass, _)
.asInstanceOf[ImmutableMap]
val of: ImmutableMap =
imClass
.getMethod("of")
.invoke(imClass)
.asInstanceOf[ImmutableMap]
}

val from: (ImmutableMap.ImmutableMap, ImmutableMap.ImmutableMap, Configuration, Integer, SQLConf, String, Optional[StructType]) => SparkBigQueryConfig =
methodFrom
.invoke(clazz, _, _, _, _, _, _, _)
.asInstanceOf[SparkBigQueryConfig]
val from: (java.util.Map[_, _], ImmutableMap.ImmutableMap, Configuration, ImmutableMap.ImmutableMap, Integer, SQLConf, String, Optional[StructType], java.lang.Boolean) => SparkBigQueryConfig = {
case (a, b, c, d, e, f, g, h, i) => {
methodFrom.getParameterTypes.length match {
case 7 => methodFrom.invoke(clazz, a, b, c, e, f, g, h).asInstanceOf[SparkBigQueryConfig]
case 8 => methodFrom.invoke(clazz, a, b, c, e, f, g, h, i).asInstanceOf[SparkBigQueryConfig]
case 9 => methodFrom.invoke(clazz, a, b, c, d, e, f, g, h, i).asInstanceOf[SparkBigQueryConfig]
}
}
}
}

private object `_: DirectBigQueryRelation` extends SafeTypeMatchingExtractor[AnyRef]("com.google.cloud.spark.bigquery.direct.DirectBigQueryRelation")
Expand Down

0 comments on commit fd58cd0

Please sign in to comment.