turboFei commented on code in PR #3848:
URL: https://github.com/apache/amoro/pull/3848#discussion_r2479877031


##########
amoro-format-mixed/amoro-mixed-spark/amoro-mixed-spark-3-common/src/test/java/org/apache/amoro/spark/test/utils/TestTableUtil.java:
##########
@@ -103,7 +105,28 @@ public static Row recordToRow(Record record, double 
sparkVersion) {
   public static InternalRow recordToInternalRow(Schema schema, Record record) {
     StructType structType = SparkSchemaUtil.convert(schema);
     Row row = recordToRow(record);
-    return RowEncoder.apply(structType).createSerializer().apply(row);
+    try {
+      // for spark-3.5
+      Method rowEncoderEncoderForMethod =
+          RowEncoder.class.getDeclaredMethod("encoderFor", StructType.class);
+      Method expressionEncoderApply =
+          ExpressionEncoder.class.getDeclaredMethod(
+              "apply", 
Class.forName("org.apache.spark.sql.catalyst.encoders.AgnosticEncoder"));
+      ExpressionEncoder encoder =
+          (ExpressionEncoder)
+              expressionEncoderApply.invoke(
+                  null, rowEncoderEncoderForMethod.invoke(null, structType));
+      return encoder.createSerializer().apply(row);
+    } catch (Exception ignore) {
+      try {
+        // for spark-3.3
+        Method rowApplyMethod = RowEncoder.class.getDeclaredMethod("apply", 
StructType.class);
+        ExpressionEncoder encoder = (ExpressionEncoder) 
rowApplyMethod.invoke(null, structType);
+        return encoder.createSerializer().apply(row);
+      } catch (Throwable e) {
+        throw new RuntimeException(e);

Review Comment:
   this is a temporary workaround to support different Spark versions



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to