Hi all, I'm working on a Pyflink application that ...
# troubleshooting
c
Hi all, I'm working on a Pyflink application that will operate in batch mode, taking files out of S3, doing some transformations, and pushing them back out to S3. I'm having trouble setting up a S3 FileSystem connector. I am able to get it working when deployed to AWS's Flink service, but locally it does not work. When I use
flink-s3-fs-hadoop
I get the error
Caused by: org.apache.hadoop.fs.UnsupportedFileSystemException: No FileSystem for scheme "file"
when sinking to S3 (source works fine). I have the hadoop package added to my pom.xml, & have the pyflink looking at my
pyflink-dependencies.jar
Copy code
table_env.get_config().get_configuration().set_string(
            "pipeline.jars",
            "file:///" + ROOT_DIR + "/target/pyflink-dependencies.jar",
        )
I've also tried the other plugin
flink-s3-fs-presto
which does give me an output, but it doesn't exit after the output and eventually (~1-2m later) gives me the error
unable to execute http request: read timed out
Any suggestions? I've even tried AWS's example repo which seems to have the same error https://github.com/aws-samples/amazon-managed-service-for-apache-flink-examples/tree/main/python/S3Sink Apache-flink 1.20.0
a
No FileSystem for scheme "file"
suggests your loading a file using the
file://
schema. You can try adding the
flink-connector-files
dependency (https://mvnrepository.com/artifact/org.apache.flink/flink-connector-files/1.20.0) to your pom The details are a bit fuzzy since it's been a while since we set up our project, so take my advice pinch of salt. The flink dist comes with many of the core dependencies bundled in the
/lib
. These are all present on the classpath then running flink binary form the cli. They are, however, not present on the classpath when running the
main()
from your IDE/maven. Add these missing dependencies with their scope set to provided.
There's also a note IntelliJ in the above docs:
To make the applications run within IntelliJ IDEA, it is necessary to tick the
Include dependencies with "Provided" scope
box in the run configuration. If this option is not available (possibly due to using an older IntelliJ IDEA version), then a workaround is to create a test that calls the application’s
main()
method.
c
Hey Andreas, thanks for responding. I added
flink-connector-files
to my pom but the error persists. I'll attach the stacktrace here, but it is weird, it looks like it's within the s3a connector code, before trying to create a local directory. I'm also not using any local files within the application, besides my
requirements.txt
and flink dependency setup, e.g,
Copy code
ROOT_DIR = str(pathlib.Path(__file__).parent.parent.parent)
    table_env.set_python_requirements(
        requirements_file_path="file:///" + ROOT_DIR + "/requirements.txt"
    )

    is_local = True if os.environ.get("IS_LOCAL") else False

    if is_local:
        table_env.get_config().get_configuration().set_string(
            "pipeline.jars",
            "file:///" + ROOT_DIR + "/target/pyflink-dependencies.jar",
        )
Untitled
Also, I am running the application via the CLI using
python main.py
within my virtual environment
Interestingly, If I change my sink to a local file path it works totally fine. So it has to be something with the S3 connector setup and it creating a local mirror filesystem before uploading to s3
Got it! You need to specify the hadoop config?
Copy code
table_env.get_config().get_configuration().set_string(
        "fs.hdfs.hadoopconf", "file:///" + ROOT_DIR + "/core-site.xml"
    )
core-site.xml:
Copy code
<configuration>
    <!-- Define the default filesystem scheme -->
    <property>
        <name>fs.defaultFS</name>
        <value>file:///</value>
    </property>

    <!-- Specify the local file system implementation class -->
    <property>
        <name>fs.file.impl</name>
        <value>org.apache.hadoop.fs.LocalFileSystem</value>
    </property>

    <!-- Define any local temporary directory if needed -->
    <property>
        <name>hadoop.tmp.dir</name>
        <value>/tmp/hadoop-temp</value>
    </property>
</configuration>
a
I've never used Python on Flink, so I'm not familiar with the project and dependency setup in this case. Apologies in advance if I'm asking a stupid question, but I noticed that the AWS example states you need to run
mvn package
in order to build the fat jar (
pyflink-dependencies.jar
) that contains the required dependencies. Did you do that already?
```# For local development (only): use the fat-jar containing all dependencies, generated by
mvn package
# located in the target/ subdirectory
"file:///" + CURRENT_DIR + "/target/pyflink-dependencies.jar"```
(https://github.com/aws-samples/amazon-managed-service-for-apache-flink-examples/bl[…]/c6efcc1e2e41fee0c6401022e6d21fcb0a665ba3/python/S3Sink/main.py)
Regarding the Hadoop FS config. I remember we have issues getting it to pick the configuration when running it locally - it worked when running it in "real" environment. This thread explains the issue: https://lists.apache.org/thread/95pssrz2y4rhjgwp4tgnvsp1qjzbpv6w In Java you can apply this workaround. Not sure if the Python API has the same capabilities:
Copy code
if("local".equals(StreamExecutionEnvironment.getExecutionEnvironment().getConfiguration().get(DeploymentOptions.TARGET))) {
  Configuration config = ...
  // When running Flink locally, the file systems are initialized with an empty Flink configuration. This occurs
  // because Flink's file system is designed to operate with cluster-level configuration and is initialized before
  // the pipeline. By the time main() is invoked, the file systems have already been initialized. To work around
  // this issue, we re-initialize the file system with our provided configuration. Credentials for the Hadoop S3
  // file system are affected by this.
  // Reference: https://lists.apache.org/thread/95pssrz2y4rhjgwp4tgnvsp1qjzbpv6w
  FileSystem.initialize(config, null);
}
@Christian Tooley I had a look at the flink hadoop dependency. The Jar itself contains the implementation for the
file://
, so I imagine that something funny is happening while maven is creating the fat dependency jar. Something similar to this old stackoverflow question: https://stackoverflow.com/questions/17265002/hadoop-no-filesystem-for-scheme-file