Skip to content

Commit

Permalink
try to fix the java incompatibility issue with pyspark
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaoPang committed Jan 16, 2025
1 parent 7d4ae0b commit 4b94b70
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ jobs:
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Set up Java 11
uses: actions/setup-java@v3
with:
java-version: "11" # specify the Java version here
distribution: "temurin" # or use 'adopt' or 'zulu', depending on your preference
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
10 changes: 10 additions & 0 deletions tests/pyspark_test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@ def setUpClass(cls):
def setUp(self):
from pyspark.sql import SparkSession

# The error InaccessibleObjectException: Unable to make private java.nio.DirectByteBuffer(long,int) accessible
# occurs because the PySpark code is trying to make a private constructor accessible, which is prohibited by
# the Java module system for security reasons.
# Starting from Java 9, JPMS enforces strong encapsulation of Java modules unless explicitly opened up.
# This means that unless the java.base module explicitly opens the java.nio package to your application,
# reflection on its classes and members will be blocked.
# Add JVM Options: If you must use a newer version of Java, you can try adding JVM options to open up the
# necessary modules. This is done by adding arguments to the spark.driver.extraJavaOptions and
# spark.executor.extraJavaOptions in your Spark configuration:
self.spark = SparkSession.builder.master("local").appName("test").getOrCreate()

# Get the root folder of the project
root_folder = Path(os.path.abspath(__file__)).parent.parent
self.data_folder = os.path.join(root_folder, "sample_data", "omop_sample")
Expand Down

0 comments on commit 4b94b70

Please sign in to comment.