Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: address failure caused by method signature change in SPARK-48791 #693

Merged
merged 4 commits into from
Jul 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion common/src/main/java/org/apache/comet/parquet/BatchReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import java.io.Closeable;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
Expand All @@ -33,6 +35,8 @@
import java.util.concurrent.LinkedBlockingQueue;

import scala.Option;
import scala.collection.Seq;
import scala.collection.mutable.Buffer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -57,6 +61,7 @@
import org.apache.parquet.schema.Type;
import org.apache.spark.TaskContext;
import org.apache.spark.TaskContext$;
import org.apache.spark.executor.TaskMetrics;
import org.apache.spark.sql.catalyst.InternalRow;
import org.apache.spark.sql.comet.parquet.CometParquetReadSupport;
import org.apache.spark.sql.execution.datasources.PartitionedFile;
Expand Down Expand Up @@ -345,7 +350,7 @@ public void init() throws URISyntaxException, IOException {
// Note that this tries to get thread local TaskContext object, if this is called at other
// thread, it won't update the accumulator.
if (taskContext != null) {
Option<AccumulatorV2<?, ?>> accu = taskContext.taskMetrics().externalAccums().lastOption();
Option<AccumulatorV2<?, ?>> accu = getTaskAccumulator(taskContext.taskMetrics());
if (accu.isDefined() && accu.get().getClass().getSimpleName().equals("NumRowGroupsAcc")) {
@SuppressWarnings("unchecked")
AccumulatorV2<Integer, Integer> intAccum = (AccumulatorV2<Integer, Integer>) accu.get();
Expand Down Expand Up @@ -632,4 +637,27 @@ public Option<Throwable> call() throws Exception {
}
}
}

// Signature of externalAccums changed from returning a Buffer to returning a Seq. If comet is
// expecting a Buffer but the Spark version returns a Seq or vice versa, we get a
// method not found exception.
@SuppressWarnings("unchecked")
private Option<AccumulatorV2<?, ?>> getTaskAccumulator(TaskMetrics taskMetrics) {
Method externalAccumsMethod;
try {
externalAccumsMethod = TaskMetrics.class.getDeclaredMethod("externalAccums");
externalAccumsMethod.setAccessible(true);
String returnType = externalAccumsMethod.getReturnType().getName();
if (returnType.equals("scala.collection.mutable.Buffer")) {
return ((Buffer<AccumulatorV2<?, ?>>) externalAccumsMethod.invoke(taskMetrics))
.lastOption();
} else if (returnType.equals("scala.collection.Seq")) {
return ((Seq<AccumulatorV2<?, ?>>) externalAccumsMethod.invoke(taskMetrics)).lastOption();
} else {
return Option.apply(null); // None
}
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
return Option.apply(null); // None
}
}
}
Loading