16
16
17
17
package za .co .absa .spline .harvester .plugin .embedded
18
18
19
- import java .lang .reflect .Method
20
- import java .lang .reflect .Modifier .isStatic
21
- import java .util .Optional
22
-
23
19
import io .github .classgraph .ClassGraph
24
- import javax .annotation .Priority
25
20
import org .apache .hadoop .conf .Configuration
26
21
import org .apache .spark .sql .SparkSession
27
22
import org .apache .spark .sql .execution .datasources .{LogicalRelation , SaveIntoDataSourceCommand }
@@ -36,6 +31,10 @@ import za.co.absa.spline.harvester.plugin.embedded.BigQueryPlugin.SparkBigQueryC
36
31
import za .co .absa .spline .harvester .plugin .embedded .BigQueryPlugin ._
37
32
import za .co .absa .spline .harvester .plugin .{BaseRelationProcessing , Plugin , RelationProviderProcessing }
38
33
34
+ import java .lang .reflect .Method
35
+ import java .lang .reflect .Modifier .isStatic
36
+ import java .util .Optional
37
+ import javax .annotation .Priority
39
38
import scala .collection .JavaConverters ._
40
39
import scala .language .reflectiveCalls
41
40
@@ -143,33 +142,14 @@ object BigQueryPlugin {
143
142
def getParentProjectId : String
144
143
}
145
144
private val clazz = findPossiblyShadedClass(" com.google.cloud" , " com.google.cloud.spark.bigquery.SparkBigQueryConfig" )
146
- private val methodFrom7 : Option [Method ] = clazz
147
- .getMethods
148
- .find(
149
- m => m.getName == " from"
150
- && isStatic(m.getModifiers)
151
- && m.getParameterTypes.length == 7
152
- && m.getReturnType.getSimpleName == " SparkBigQueryConfig"
153
- )
154
- private val methodFrom8 : Option [Method ] = clazz
145
+ private val methodFrom : Method = clazz
155
146
.getMethods
156
147
.find(
157
148
m => m.getName == " from"
158
149
&& isStatic(m.getModifiers)
159
- && m.getParameterTypes.length == 8
150
+ && ( m.getParameterTypes.length == 7 || m.getParameterTypes.length == 8 || m.getParameterTypes.length == 9 )
160
151
&& m.getReturnType.getSimpleName == " SparkBigQueryConfig"
161
152
)
162
- private val methodFrom9 : Option [Method ] = clazz
163
- .getMethods
164
- .find(
165
- m => m.getName == " from"
166
- && isStatic(m.getModifiers)
167
- && m.getParameterTypes.length == 9
168
- && m.getReturnType.getSimpleName == " SparkBigQueryConfig"
169
- )
170
- private val methodFrom : Method = methodFrom7
171
- .orElse(methodFrom8)
172
- .orElse(methodFrom9)
173
153
.getOrElse(sys.error(s " Cannot find method `public static SparkBigQueryConfig from(... {7|8|9 args} ...)` in the class ` $clazz` " ))
174
154
175
155
object ImmutableMap {
@@ -188,13 +168,13 @@ object BigQueryPlugin {
188
168
}
189
169
190
170
val from : (java.util.Map [_, _], ImmutableMap .ImmutableMap , Configuration , ImmutableMap .ImmutableMap , Integer , SQLConf , String , Optional [StructType ], java.lang.Boolean ) => SparkBigQueryConfig = {
191
- case (a, b, c, d, e, f, g, h, i) =>
192
- if (methodFrom7.isDefined)
193
- methodFrom7.get .invoke(clazz, a, b, c, e, f, g, h).asInstanceOf [SparkBigQueryConfig ]
194
- else if (methodFrom8.isDefined)
195
- methodFrom8.get. invoke(clazz, a, b, c, e, f, g, h, i).asInstanceOf [SparkBigQueryConfig ]
196
- else
197
- methodFrom9.get.invoke(clazz, a, b, c, d, e, f, g, h, i). asInstanceOf [ SparkBigQueryConfig ]
171
+ case (a, b, c, d, e, f, g, h, i) => {
172
+ methodFrom.getParameterTypes.length match {
173
+ case 7 => methodFrom .invoke(clazz, a, b, c, e, f, g, h).asInstanceOf [SparkBigQueryConfig ]
174
+ case 8 => methodFrom.invoke(clazz, a, b, c, e, f, g, h, i). asInstanceOf [ SparkBigQueryConfig ]
175
+ case 9 => methodFrom. invoke(clazz, a, b, c, d , e, f, g, h, i).asInstanceOf [SparkBigQueryConfig ]
176
+ }
177
+ }
198
178
}
199
179
}
200
180
0 commit comments