Search in sources :

Example 6 with Path

use of org.apache.flink.core.fs.Path in project flink by apache.

the class TaskTestBase method registerFileOutputTask.

public void registerFileOutputTask(AbstractInvokable outTask, FileOutputFormat<Record> outputFormat, String outPath) {
    TaskConfig dsConfig = new TaskConfig(this.mockEnv.getTaskConfiguration());
    outputFormat.setOutputFilePath(new Path(outPath));
    outputFormat.setWriteMode(WriteMode.OVERWRITE);
    dsConfig.setStubWrapper(new UserCodeObjectWrapper<>(outputFormat));
    outTask.setEnvironment(this.mockEnv);
}
Also used : Path(org.apache.flink.core.fs.Path) TaskConfig(org.apache.flink.runtime.operators.util.TaskConfig)

Example 7 with Path

use of org.apache.flink.core.fs.Path in project flink by apache.

the class PythonPlanBinderTest method findTestFiles.

private static List<String> findTestFiles() throws Exception {
    List<String> files = new ArrayList<>();
    FileSystem fs = FileSystem.getLocalFileSystem();
    FileStatus[] status = fs.listStatus(new Path(fs.getWorkingDirectory().toString() + "/src/test/python/org/apache/flink/python/api"));
    for (FileStatus f : status) {
        String file = f.getPath().toString();
        if (file.endsWith(".py")) {
            files.add(file);
        }
    }
    return files;
}
Also used : Path(org.apache.flink.core.fs.Path) FileStatus(org.apache.flink.core.fs.FileStatus) FileSystem(org.apache.flink.core.fs.FileSystem) ArrayList(java.util.ArrayList)

Example 8 with Path

use of org.apache.flink.core.fs.Path in project flink by apache.

the class PythonPlanBinder method close.

private void close() {
    try {
        //prevent throwing exception so that previous exceptions aren't hidden.
        FileSystem hdfs = FileSystem.get(new URI(FLINK_HDFS_PATH));
        hdfs.delete(new Path(FLINK_HDFS_PATH), true);
        FileSystem local = FileSystem.getLocalFileSystem();
        local.delete(new Path(FLINK_PYTHON_FILE_PATH), true);
        local.delete(new Path(FLINK_TMP_DATA_DIR), true);
        streamer.close();
    } catch (NullPointerException npe) {
    } catch (IOException ioe) {
        LOG.error("PythonAPI file cleanup failed. " + ioe.getMessage());
    } catch (URISyntaxException use) {
    // can't occur
    }
}
Also used : Path(org.apache.flink.core.fs.Path) FileSystem(org.apache.flink.core.fs.FileSystem) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 9 with Path

use of org.apache.flink.core.fs.Path in project flink by apache.

the class PythonPlanBinder method createCsvSource.

@SuppressWarnings("unchecked")
private void createCsvSource(PythonOperationInfo info) throws IOException {
    if (!(info.types instanceof TupleTypeInfo)) {
        throw new RuntimeException("The output type of a csv source has to be a tuple. The derived type is " + info);
    }
    Path path = new Path(info.path);
    String lineD = info.lineDelimiter;
    String fieldD = info.fieldDelimiter;
    TupleTypeInfo<?> types = (TupleTypeInfo) info.types;
    sets.put(info.setID, env.createInput(new TupleCsvInputFormat(path, lineD, fieldD, types), info.types).setParallelism(getParallelism(info)).name("CsvSource").map(new SerializerMap<>()).setParallelism(getParallelism(info)).name("CsvSourcePostStep"));
}
Also used : Path(org.apache.flink.core.fs.Path) TupleCsvInputFormat(org.apache.flink.api.java.io.TupleCsvInputFormat) SerializerMap(org.apache.flink.python.api.functions.util.SerializerMap) TupleTypeInfo(org.apache.flink.api.java.typeutils.TupleTypeInfo)

Example 10 with Path

use of org.apache.flink.core.fs.Path in project flink by apache.

the class PythonPlanBinder method copyFile.

private static void copyFile(String path, String target, String name) throws IOException, URISyntaxException {
    if (path.endsWith("/")) {
        path = path.substring(0, path.length() - 1);
    }
    String identifier = name == null ? path.substring(path.lastIndexOf("/")) : name;
    String tmpFilePath = target + "/" + identifier;
    clearPath(tmpFilePath);
    Path p = new Path(path);
    FileCache.copy(p.makeQualified(FileSystem.get(p.toUri())), new Path(tmpFilePath), true);
}
Also used : Path(org.apache.flink.core.fs.Path)

Aggregations

Path (org.apache.flink.core.fs.Path)590 Test (org.junit.Test)320 File (java.io.File)178 Configuration (org.apache.flink.configuration.Configuration)101 IOException (java.io.IOException)91 FileSystem (org.apache.flink.core.fs.FileSystem)87 FileInputSplit (org.apache.flink.core.fs.FileInputSplit)72 ArrayList (java.util.ArrayList)64 HashMap (java.util.HashMap)40 FileOutputStream (java.io.FileOutputStream)38 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)36 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)35 List (java.util.List)33 Map (java.util.Map)29 JobID (org.apache.flink.api.common.JobID)29 OutputStreamWriter (java.io.OutputStreamWriter)27 FSDataOutputStream (org.apache.flink.core.fs.FSDataOutputStream)27 FileStatus (org.apache.flink.core.fs.FileStatus)26 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)25 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)21