Package org.apache.flink.core.fs

Examples of org.apache.flink.core.fs.Path


  public static <T, F extends FileOutputFormat<? extends T>> F openOutput(
      Class<F> outputFormatClass, String path, Configuration configuration)
    throws IOException
  {
    final F outputFormat = ReflectionUtil.newInstance(outputFormatClass);
    outputFormat.setOutputFilePath(new Path(path));
    outputFormat.setWriteMode(WriteMode.OVERWRITE);
 
    configuration = configuration == null ? new Configuration() : configuration;
   
    outputFormat.configure(configuration);
View Full Code Here


  private static Path normalizePath(Path path) {
    URI uri = path.toUri();
    if (uri.getScheme() == null) {
      try {
        uri = new URI("file", uri.getHost(), uri.getPath(), uri.getFragment());
        path = new Path(uri.toString());
      } catch (URISyntaxException e) {
        throw new IllegalArgumentException("path is invalid", e);
      }
    }
    return path;
View Full Code Here

      TaskConfig taskConfig = new TaskConfig(output.getConfiguration());
      taskConfig.addInputToGroup(0);
      taskConfig.setInputSerializer(serializer, 0);

      PointOutFormat outFormat = new PointOutFormat();
      outFormat.setOutputFilePath(new Path(resultPath));
     
      taskConfig.setStubWrapper(new UserCodeObjectWrapper<PointOutFormat>(outFormat));
    }

    return output;
View Full Code Here

 
  @Test
  public void testDeserialisation() throws IOException {
    Configuration parameters = new Configuration();
   
    AvroInputFormat<User> format = new AvroInputFormat<User>(new Path(testFile.getAbsolutePath()), User.class);
   
    format.configure(parameters);
    FileInputSplit[] splits = format.createInputSplits(1);
    assertEquals(splits.length, 1);
    format.open(splits[0]);
View Full Code Here

   
    DataOutputStream dos = new DataOutputStream(new FileOutputStream(tempFile));
    dos.writeBytes(content);
    dos.close();
     
    return new FileInputSplit(0, new Path(this.tempFile.toURI().toString()), 0, this.tempFile.length(), new String[] {"localhost"});
  }
View Full Code Here

 
  // --------------------------------------------------------------------------------------------

  @Before
  public void setup() {
    this.format.setFilePath(new Path("file:///some/file/that/will/not/be/read"));
    this.config = new Configuration();
  }
View Full Code Here

   
    OutputStreamWriter wrt = new OutputStreamWriter(new FileOutputStream(this.tempFile));
    wrt.write(contents);
    wrt.close();
   
    return new FileInputSplit(0, new Path(this.tempFile.toURI().toString()), 0, this.tempFile.length(), new String[] {"localhost"});
  }
View Full Code Here

public class AvroInputFormatTypeExtractionTest {

  @Test
  public void testTypeExtraction() {
    try {
      InputFormat<MyAvroType, ?> format = new AvroInputFormat<MyAvroType>(new Path("file:///ignore/this/file"), MyAvroType.class);

      TypeInformation<?> typeInfoDirect = TypeExtractor.getInputFormatTypes(format);

      ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
      DataSet<MyAvroType> input = env.createInput(format);
View Full Code Here

   
    String tmpFilePath = tmpOutPath.toURI().toString();

    // check fail if file exists
    DummyFileOutputFormat dfof = new DummyFileOutputFormat();
    dfof.setOutputFilePath(new Path(tmpFilePath));
    dfof.setWriteMode(WriteMode.NO_OVERWRITE);
    dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);

    dfof.configure(new Configuration());
   
    boolean exception = false;
    try {
      dfof.open(0, 1);
      dfof.close();
    } catch (Exception e) {
      exception = true;
    }
    Assert.assertTrue(exception);

    // check fail if directory exists
    tmpOutPath.delete();
    Assert.assertTrue("Directory could not be created.", tmpOutPath.mkdir());

    dfof = new DummyFileOutputFormat();
    dfof.setOutputFilePath(new Path(tmpFilePath));
    dfof.setWriteMode(WriteMode.NO_OVERWRITE);
    dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);

    dfof.configure(new Configuration());
   
    exception = false;
    try {
      dfof.open(0, 1);
      dfof.close();
    } catch (Exception e) {
      exception = true;
    }
    Assert.assertTrue(exception);
   
    // check success
    tmpOutPath.delete();
   
    dfof = new DummyFileOutputFormat();
    dfof.setOutputFilePath(new Path(tmpFilePath));
    dfof.setWriteMode(WriteMode.NO_OVERWRITE);
    dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);

    dfof.configure(new Configuration());
   
    exception = false;
    try {
      dfof.open(0, 1);
      dfof.close();
    } catch (Exception e) {
      exception = true;
    }
    Assert.assertTrue(!exception);
    Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isFile());
   
    // ----------- test again with always directory mode
   
    // check fail if file exists
    dfof = new DummyFileOutputFormat();
    dfof.setOutputFilePath(new Path(tmpFilePath));
    dfof.setWriteMode(WriteMode.NO_OVERWRITE);
    dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);

    dfof.configure(new Configuration());
   
    exception = false;
    try {
      dfof.open(0, 1);
      dfof.close();
    } catch (Exception e) {
      exception = true;
    }
    Assert.assertTrue(exception);

    // check success if directory exists
    tmpOutPath.delete();
    Assert.assertTrue("Directory could not be created.", tmpOutPath.mkdir());

    dfof = new DummyFileOutputFormat();
    dfof.setOutputFilePath(new Path(tmpFilePath));
    dfof.setWriteMode(WriteMode.NO_OVERWRITE);
    dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);

    dfof.configure(new Configuration());
   
    exception = false;
    try {
      dfof.open(0, 1);
      dfof.close();
    } catch (Exception e) {
      exception = true;
    }
    Assert.assertTrue(!exception);
    Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
    Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
   
    // check fail if file in directory exists
    dfof = new DummyFileOutputFormat();
    dfof.setOutputFilePath(new Path(tmpFilePath));
    dfof.setWriteMode(WriteMode.NO_OVERWRITE);
    dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);

    dfof.configure(new Configuration());
   
    exception = false;
    try {
      dfof.open(0, 1);
      dfof.close();
    } catch (Exception e) {
      exception = true;
    }
    Assert.assertTrue(exception);
   
    // check success if no file exists
    // delete existing files
    (new File(tmpOutPath.getAbsoluteFile()+"/1")).delete();
    tmpOutPath.delete();
   
    dfof = new DummyFileOutputFormat();
    dfof.setOutputFilePath(new Path(tmpFilePath));
    dfof.setWriteMode(WriteMode.NO_OVERWRITE);
    dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);

    dfof.configure(new Configuration());
   
View Full Code Here

   
    String tmpFilePath = tmpOutPath.toURI().toString();

    // check fail if file exists
    DummyFileOutputFormat dfof = new DummyFileOutputFormat();
    dfof.setOutputFilePath(new Path(tmpFilePath));
    dfof.setWriteMode(WriteMode.NO_OVERWRITE);
    dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);

    dfof.configure(new Configuration());
   
    boolean exception = false;
    try {
      dfof.open(0, 2);
      dfof.close();
    } catch (Exception e) {
      exception = true;
    }
    Assert.assertTrue(exception);

    // check success if directory exists
    tmpOutPath.delete();
    Assert.assertTrue("Directory could not be created.", tmpOutPath.mkdir());

    dfof = new DummyFileOutputFormat();
    dfof.setOutputFilePath(new Path(tmpFilePath));
    dfof.setWriteMode(WriteMode.NO_OVERWRITE);
    dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);

    dfof.configure(new Configuration());
   
    exception = false;
    try {
      dfof.open(0, 2);
      dfof.close();
    } catch (Exception e) {
      exception = true;
    }
    Assert.assertTrue(!exception);
    Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
    Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
   
    // check fail if file in directory exists
    dfof = new DummyFileOutputFormat();
    dfof.setOutputFilePath(new Path(tmpFilePath));
    dfof.setWriteMode(WriteMode.NO_OVERWRITE);
    dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);

    dfof.configure(new Configuration());
   
    exception = false;
    try {
      dfof.open(0, 2);
      dfof.close();
    } catch (Exception e) {
      exception = true;
    }
    Assert.assertTrue(exception);
   
    // check success if no file exists
    // delete existing files
    tmpOutFile.delete();
    tmpOutPath.delete();
   
    dfof = new DummyFileOutputFormat();
    dfof.setOutputFilePath(new Path(tmpFilePath));
    dfof.setWriteMode(WriteMode.NO_OVERWRITE);
    dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);

    dfof.configure(new Configuration());
   
View Full Code Here

TOP

Related Classes of org.apache.flink.core.fs.Path

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.