I want to run my first flink code, so I created a virtual environement and I run it with: python tab.py I find : What's wrong with my Pyflink setup that Python UDFs throw py4j exceptions? but it doesn't work.
Asked
Active
Viewed 258 times
1 Answers
1
Temporary solution: use openjdk
< 17
The (temporary) solution I have found was to enforce install of openjdk
< 17
:
# Installation with mamba (conda):
mamba create -n flink "python<3.10" "openjdk<17" cython -c conda-forge
conda activate flink
pip install apache-flink --no-cache
This should allow you to run the script mentioned in your link.
Undelying problem for OpenJDK >= 17
Otherwise (for OpenJDK >= 17), there is an open issue https://github.com/py4j/py4j/issues/515 regarding the following error:
# --- Error triggered with OpenJDK >= 17 ---
java.lang.reflect.InaccessibleObjectException: Unable to make field private final byte[] java.lang.String.value accessible: module java.base does not "opens java.lang" to unnamed module
# --- Full traceback (trying to run PyFlink) ---
File "/Users/test_flink.py", line 28, in <module>
tutorial()
File "/Users/test_flink.py", line 20, in tutorial
ds.print()
File "/opt/homebrew/Caskroom/miniconda/base/envs/flink/lib/python3.9/site-packages/pyflink/datastream/data_stream.py", line 883, in print
j_data_stream_sink = self._align_output_type()._j_data_stream.print()
File "/opt/homebrew/Caskroom/miniconda/base/envs/flink/lib/python3.9/site-packages/py4j/java_gateway.py", line 1321, in __call__
return_value = get_return_value(
File "/opt/homebrew/Caskroom/miniconda/base/envs/flink/lib/python3.9/site-packages/pyflink/util/exceptions.py", line 146, in deco
return f(*a, **kw)
File "/opt/homebrew/Caskroom/miniconda/base/envs/flink/lib/python3.9/site-packages/py4j/protocol.py", line 326, in get_return_value
raise Py4JJavaError(
py4j.protocol.Py4JJavaError: An error occurred while calling o82.print.
: java.lang.reflect.InaccessibleObjectException: Unable to make field private final byte[] java.lang.String.value accessible: module java.base does not "opens java.lang" to unnamed module @a803f94
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
at org.apache.flink.api.java.ClosureCleaner.clean(ClosureCleaner.java:106)
at org.apache.flink.api.java.ClosureCleaner.clean(ClosureCleaner.java:132)
at org.apache.flink.api.java.ClosureCleaner.clean(ClosureCleaner.java:132)
at org.apache.flink.api.java.ClosureCleaner.clean(ClosureCleaner.java:69)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.clean(StreamExecutionEnvironment.java:2308)
at org.apache.flink.streaming.api.datastream.DataStream.clean(DataStream.java:202)
at org.apache.flink.streaming.api.datastream.DataStream.addSink(DataStream.java:1242)
at org.apache.flink.streaming.api.datastream.DataStream.print(DataStream.java:936)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.apache.flink.api.python.shaded.py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at org.apache.flink.api.python.shaded.py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at org.apache.flink.api.python.shaded.py4j.Gateway.invoke(Gateway.java:282)
at org.apache.flink.api.python.shaded.py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at org.apache.flink.api.python.shaded.py4j.commands.CallCommand.execute(CallCommand.java:79)
at org.apache.flink.api.python.shaded.py4j.GatewayConnection.run(GatewayConnection.java:238)
at java.base/java.lang.Thread.run(Thread.java:833)
The error comes form a change in Java's API that forbids access to private attributes.
Note the warning when running above-mentioned script under openjdk==11
:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.flink.api.java.ClosureCleaner (file:/opt/homebrew/Caskroom/miniconda/base/envs/flink/lib/python3.9/site-packages/pyflink/lib/flink-dist-1.16.1.jar) to field java.lang.String.value
WARNING: Please consider reporting this to the maintainers of org.apache.flink.api.java.ClosureCleaner
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

Jean Monet
- 2,075
- 15
- 25