public final class ExternalFrameWriterClient
extends java.lang.Object
This class is used to create and write data to H2O Frames from non-H2O environments, such as Spark Executors.
Example usage of this class:First we need to open the connection to H2O and initialize the writer:
// Prepare expected bytes from Java Classes.
// We don't specify vector types since they are deterministically inferred from the expected types
byte[] expectedBytes = ExternalFrameUtils.prepareExpectedTypes(new Class[]{Boolean.class, Integer.class});
ByteChannel channel = ExternalFrameUtils.getConnection("ip:port");
ExternalFrameWriter writer = new ExternalFrameWriter(channel);
writer.initFrame("frameName", columns)
writer.createChunk("frameName", expectedTypes, chunkIdx, numOfRowsToBeWritten);
Then we can write the data:
{@code
int rowsWritten = 0;
while(rowsWritten < totalNumOfRows){
writer.sendBool(true);
writer.sendInt(657);
rowsWritten++;
}
}
At last, finalize the frame
writer.finalizeFrame("frameName, rowsPerChunk, colTypes, domains);
| Constructor and Description |
|---|
ExternalFrameWriterClient(java.nio.channels.ByteChannel channel,
int timeout,
long blockSize)
Initialize the External frame writer
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
static ExternalFrameWriterClient |
create(java.lang.String ip,
int port,
short timestamp,
int timeout,
long blockSize) |
void |
createChunk(java.lang.String frameKey,
byte[] expectedTypes,
int chunkId,
int totalNumRows,
int[] maxVecSizes)
Create single chunk on the already existing empty frame.
|
void |
finalizeFrame(java.lang.String keyName,
long[] rowsPerChunk,
byte[] colTypes,
java.lang.String[][] domains) |
int |
getNumberOfWrittenRows() |
void |
initFrame(java.lang.String keyName,
java.lang.String[] names) |
void |
sendBoolean(boolean data) |
void |
sendByte(byte data) |
void |
sendChar(char data) |
void |
sendDenseVector(double[] values) |
void |
sendDouble(double data) |
void |
sendFloat(float data) |
void |
sendInt(int data) |
void |
sendLong(long data) |
void |
sendNA() |
void |
sendShort(short data) |
void |
sendSparseVector(int[] indices,
double[] values) |
void |
sendString(java.lang.String data) |
void |
sendTimestamp(java.sql.Timestamp timestamp) |
public ExternalFrameWriterClient(java.nio.channels.ByteChannel channel,
int timeout,
long blockSize)
This method expects expected types in order to ensure we send the data in optimal way.
channel - communication channel to h2o nodepublic static ExternalFrameWriterClient create(java.lang.String ip, int port, short timestamp, int timeout, long blockSize) throws java.io.IOException
java.io.IOExceptionpublic void initFrame(java.lang.String keyName,
java.lang.String[] names)
throws java.io.IOException,
ExternalFrameConfirmationException
java.io.IOExceptionExternalFrameConfirmationExceptionpublic void createChunk(java.lang.String frameKey,
byte[] expectedTypes,
int chunkId,
int totalNumRows,
int[] maxVecSizes)
throws java.io.IOException
frameKey - name of the frameexpectedTypes - expected typeschunkId - chunk indextotalNumRows - total number of rows which is about to be sentjava.io.IOExceptionpublic void finalizeFrame(java.lang.String keyName,
long[] rowsPerChunk,
byte[] colTypes,
java.lang.String[][] domains)
throws java.io.IOException,
ExternalFrameConfirmationException
java.io.IOExceptionExternalFrameConfirmationExceptionpublic void close()
throws java.io.IOException,
ExternalFrameConfirmationException
java.io.IOExceptionExternalFrameConfirmationExceptionpublic void sendBoolean(boolean data)
throws java.io.IOException
java.io.IOExceptionpublic void sendByte(byte data)
throws java.io.IOException
java.io.IOExceptionpublic void sendChar(char data)
throws java.io.IOException
java.io.IOExceptionpublic void sendShort(short data)
throws java.io.IOException
java.io.IOExceptionpublic void sendInt(int data)
throws java.io.IOException
java.io.IOExceptionpublic void sendLong(long data)
throws java.io.IOException
java.io.IOExceptionpublic void sendFloat(float data)
throws java.io.IOException
java.io.IOExceptionpublic void sendDouble(double data)
throws java.io.IOException
java.io.IOExceptionpublic void sendString(java.lang.String data)
throws java.io.IOException
java.io.IOExceptionpublic void sendTimestamp(java.sql.Timestamp timestamp)
throws java.io.IOException
java.io.IOExceptionpublic void sendNA()
throws java.io.IOException
java.io.IOExceptionpublic void sendSparseVector(int[] indices,
double[] values)
throws java.io.IOException
java.io.IOExceptionpublic void sendDenseVector(double[] values)
throws java.io.IOException
java.io.IOExceptionpublic int getNumberOfWrittenRows()