运行第一个Flink python代码时出现问题

cwtwac6a  于 2023-03-21  发布在  Apache
关注(0)|答案(1)|浏览(148)

我想运行我的第一个flink代码,所以我创建了一个虚拟环境,并使用以下命令运行它:pythontab.py我找到:What's wrong with my Pyflink setup that Python UDFs throw py4j exceptions?,但它不工作.

ki0zmccv

ki0zmccv1#

临时溶液:使用openjdk< 17

我找到的(临时)解决方案是强制安装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

这将允许您运行链接中提到的脚本。

OpenJDK的取消延迟问题〉= 17

否则(对于OpenJDK〉= 17),将存在关于以下错误的未决问题https://github.com/py4j/py4j/issues/515

# --- 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)

这个错误来自于Java的API中禁止访问私有属性的更改。
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

相关问题