-
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.
added operator to open stream, modified writers
- Loading branch information
Showing
13 changed files
with
226 additions
and
127 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,74 @@ | ||
/** | ||
* | ||
*/ | ||
package edu.washington.escience.myria; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.util.List; | ||
|
||
import org.apache.hadoop.fs.FSDataOutputStream; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import edu.washington.escience.myria.coordinator.MasterCatalog; | ||
import edu.washington.escience.myria.storage.ReadableTable; | ||
|
||
/** | ||
* | ||
*/ | ||
public class HdfsTupleWriter implements TupleWriter { | ||
|
||
/** Required for Java serialization. */ | ||
static final long serialVersionUID = 1L; | ||
|
||
/** The logger for this class. */ | ||
private static final Logger LOGGER = LoggerFactory.getLogger(MasterCatalog.class); | ||
|
||
private static FSDataOutputStream outStream; | ||
|
||
public HdfsTupleWriter() { | ||
|
||
} | ||
|
||
public HdfsTupleWriter(final OutputStream out) { | ||
outStream = (FSDataOutputStream) out; | ||
} | ||
|
||
@Override | ||
public void open(final OutputStream stream) { | ||
outStream = (FSDataOutputStream) stream; | ||
} | ||
|
||
@Override | ||
public void writeColumnHeaders(final List<String> columnNames) throws IOException { | ||
} | ||
|
||
@Override | ||
public void writeTuples(final ReadableTable tuples) throws IOException { | ||
|
||
outStream.writeChars("test"); | ||
|
||
/* | ||
* List<Type> columnTypes = tuples.getSchema().getColumnTypes(); for (int i = 0; i < tuples.numTuples(); ++i) { for | ||
* (int j = 0; j < tuples.numColumns(); ++j) { switch (columnTypes.get(j)) { case BOOLEAN_TYPE: | ||
* outStream.writeBoolean(tuples.getBoolean(j, i)); break; case DOUBLE_TYPE: | ||
* outStream.writeDouble(tuples.getDouble(j, i)); break; case FLOAT_TYPE: outStream.writeFloat(tuples.getFloat(j, | ||
* i)); break; case INT_TYPE: outStream.writeInt(tuples.getInt(j, i)); break; case LONG_TYPE: | ||
* LOGGER.error(String.valueOf(tuples.getLong(j, i))); outStream.writeLong(tuples.getLong(j, i)); break; case | ||
* DATETIME_TYPE: // outStream.writeUTF(tuples.getDateTime(j,i)); break; case STRING_TYPE: | ||
* outStream.writeChars(tuples.getString(j, i)); break; } } } | ||
*/ | ||
|
||
} | ||
|
||
@Override | ||
public void done() throws IOException { | ||
outStream.close(); | ||
} | ||
|
||
@Override | ||
public void error() throws IOException { | ||
} | ||
|
||
} |
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
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,31 @@ | ||
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.FileSystem; | ||
import org.apache.hadoop.fs.Path; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class HdfsDataSink implements DataSink { | ||
|
||
@JsonProperty | ||
private final URI uri; | ||
|
||
public HdfsDataSink(@JsonProperty(value = "uri", required = true) final String uri) { | ||
this.uri = URI.create(Objects.requireNonNull(uri, "Parameter uri cannot be null")); | ||
} | ||
|
||
@Override | ||
public OutputStream getOutputStream() throws IOException { | ||
Configuration conf = new Configuration(); | ||
FileSystem fs = FileSystem.get(uri, conf); | ||
Path rootPath = new Path(uri); | ||
|
||
return fs.create(rootPath); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
src/edu/washington/escience/myria/operator/DataOutputRoot.java
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,71 @@ | ||
package edu.washington.escience.myria.operator; | ||
|
||
import java.io.IOException; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
|
||
import edu.washington.escience.myria.DbException; | ||
import edu.washington.escience.myria.TupleWriter; | ||
import edu.washington.escience.myria.io.DataSink; | ||
import edu.washington.escience.myria.storage.TupleBatch; | ||
|
||
/** | ||
* RemoteDataOutput is ... | ||
*/ | ||
public final class DataOutputRoot extends RootOperator { | ||
|
||
/** Required for Java serialization. */ | ||
private static final long serialVersionUID = 1L; | ||
|
||
private final DataSink dataSink; | ||
private final TupleWriter tupleWriter; | ||
|
||
private boolean done = false; | ||
|
||
public DataOutputRoot(final Operator child, final TupleWriter tupleWriter, final DataSink dataSink) { | ||
super(child); | ||
this.dataSink = dataSink; | ||
this.tupleWriter = tupleWriter; | ||
} | ||
|
||
@Override | ||
protected void childEOI() throws DbException { | ||
/* Do nothing. */ | ||
} | ||
|
||
@Override | ||
protected void childEOS() throws DbException { | ||
try { | ||
tupleWriter.done(); | ||
} catch (IOException e) { | ||
throw new DbException(e); | ||
} | ||
done = true; | ||
} | ||
|
||
@Override | ||
protected void consumeTuples(final TupleBatch tuples) throws DbException { | ||
try { | ||
tupleWriter.writeTuples(tuples); | ||
} catch (IOException e) { | ||
throw new DbException(e); | ||
} | ||
} | ||
|
||
@Override | ||
protected void init(final ImmutableMap<String, Object> execEnvVars) throws DbException { | ||
try { | ||
tupleWriter.open(dataSink.getOutputStream()); | ||
tupleWriter.writeColumnHeaders(getChild().getSchema().getColumnNames()); | ||
} catch (IOException | SecurityException | IllegalArgumentException e) { | ||
throw new DbException(e); | ||
} | ||
} | ||
|
||
@Override | ||
protected void cleanup() throws IOException { | ||
if (!done) { | ||
tupleWriter.error(); | ||
} | ||
} | ||
} |
Oops, something went wrong.