-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
173 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* | ||
*/ | ||
package edu.washington.escience.myria; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.util.List; | ||
|
||
import org.apache.hadoop.fs.FSDataOutputStream; | ||
|
||
import edu.washington.escience.myria.storage.ReadableTable; | ||
|
||
/** | ||
* | ||
*/ | ||
public class HdfsWriter implements TupleWriter { | ||
|
||
/** Required for Java serialization. */ | ||
static final long serialVersionUID = 1L; | ||
|
||
FSDataOutputStream outStream; | ||
|
||
public HdfsWriter(final OutputStream out) { | ||
outStream = (FSDataOutputStream) out; | ||
} | ||
|
||
@Override | ||
public void writeColumnHeaders(final List<String> columnNames) throws IOException { | ||
} | ||
|
||
@Override | ||
public void writeTuples(final ReadableTable tuples) throws IOException { | ||
for (int i = 0; i < tuples.numTuples(); ++i) { | ||
// not sure | ||
outStream.writeBytes(tuples.toString()); | ||
} | ||
} | ||
|
||
@Override | ||
public void done() throws IOException { | ||
outStream.close(); | ||
} | ||
|
||
@Override | ||
public void error() throws IOException { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* | ||
*/ | ||
package edu.washington.escience.myria.io; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonSubTypes.Type; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
|
||
/** | ||
* An interface for any sink of bits. This interface should be the principal parameter to any operator that produces | ||
* tuples for a destination (HDFS, S3, files, etc) | ||
*/ | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "dataType") | ||
@JsonSubTypes({ | ||
@Type(name = "Bytes", value = ByteArraySource.class), @Type(name = "File", value = FileSource.class), | ||
@Type(name = "URI", value = UriSource.class), @Type(name = "Empty", value = EmptySource.class) }) | ||
public interface DataSink { | ||
/** | ||
* Returns an {@link OutputStream} providing write access to the bits in the specified data destination. | ||
* | ||
* @return an {@link OutputStream} providing read access to the bits in the specified data destination. | ||
* @throws IOException if there is an error producing the input stream. | ||
*/ | ||
OutputStream getOutputStream() throws IOException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* | ||
*/ | ||
package edu.washington.escience.myria.io; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.net.URI; | ||
import java.util.Objects; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FSDataOutputStream; | ||
import org.apache.hadoop.fs.FileSystem; | ||
import org.apache.hadoop.fs.Path; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** | ||
* | ||
* Similar to UriSource | ||
*/ | ||
public class UriSink implements DataSink { | ||
|
||
/** The Uniform Resource Indicator (URI) of the data source. */ | ||
@JsonProperty | ||
private final String uri; | ||
|
||
/** The logger for debug, trace, etc. messages in this class. */ | ||
private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(UriSink.class); | ||
|
||
public UriSink(@JsonProperty(value = "uri", required = true) final String uri) { | ||
this.uri = Objects.requireNonNull(uri, "Parameter uri to UriSource may not be null"); | ||
} | ||
|
||
@Override | ||
public OutputStream getOutputStream() throws IOException { | ||
URI parsedUri = URI.create(uri); | ||
|
||
return (parsedUri.getScheme().equals("http") || parsedUri.getScheme().equals("https")) ? parsedUri.toURL() | ||
.openConnection().getOutputStream() : getHadoopFileSystemOutputStream(parsedUri); | ||
} | ||
|
||
private static OutputStream getHadoopFileSystemOutputStream(final URI uri) throws IOException { | ||
Configuration conf = new Configuration(); | ||
|
||
FileSystem fs = FileSystem.get(uri, conf); | ||
Path rootPath = new Path(uri); | ||
|
||
FSDataOutputStream out = fs.create(rootPath); | ||
|
||
return out; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters