public final class ExternalFrameReaderClient
extends java.lang.Object
This class is used to read data from H2O Frames from non-H2O environments, such as Spark Executors. It is expected that the frame we want to read is already in the DKV. The check for the presence is up on the user of this class.
Example usage of this class: First we need to open the connection to H2O and initialize the reader:
// specify indexes of columns we want to read data from
int[] selectedColumnIndices = {0, 1};
// specify expected types for the selected columns
byte[] expectedTypes = {ExternalFrameHandler.EXPECTED_BOOL, ExternalFrameHandler.EXPECTED_INT};
ByteChannel channel = ExternalFrameUtils.getConnection("ip:port");
ExternalFrameReader reader = new ExternalFrameReader(channel, "frameName", 0, selectedColumnIndices);
In the next step we can read the data we expect, in our case boolean and integer:
int rowsRead = 0;
while(rowsRead < reader.getNumRows){
boolean b = reader.readBool();
if(reader.isLastNA{
// it is NA
}else{
// it is value
}
int i = reader.readInt()
if(reader.isLastNA{
// it is NA
}else{
// it is value
}
}
And at the end we need to make sure to force to code wait for all data to be read:
reader.waitUntilAllReceived();
Constructor and Description |
---|
ExternalFrameReaderClient(java.nio.channels.ByteChannel channel,
java.lang.String frameKey,
int chunkIdx,
int[] selectedColumnIndices,
byte[] expectedTypes) |
Modifier and Type | Method and Description |
---|---|
int |
getNumRows() |
boolean |
isLastNA()
This method is used to check if the last received value was marked as NA by H2O backend
|
boolean |
readBoolean() |
byte |
readByte() |
char |
readChar() |
double |
readDouble() |
float |
readFloat() |
int |
readInt() |
long |
readLong() |
short |
readShort() |
java.lang.String |
readString() |
java.sql.Timestamp |
readTimestamp() |
void |
waitUntilAllReceived(int timeout)
This method ensures the application waits for all bytes to be received before continuing in the
application's control flow.
|
public ExternalFrameReaderClient(java.nio.channels.ByteChannel channel, java.lang.String frameKey, int chunkIdx, int[] selectedColumnIndices, byte[] expectedTypes) throws java.io.IOException
channel
- channel to h2o nodeframeKey
- name of frame we want to read fromchunkIdx
- chunk index from we want to readselectedColumnIndices
- indices of columns we want to read fromexpectedTypes
- expected typesjava.io.IOException
public int getNumRows()
public boolean readBoolean()
public byte readByte()
public char readChar()
public short readShort()
public int readInt()
public long readLong()
public float readFloat()
public double readDouble()
public java.lang.String readString()
public java.sql.Timestamp readTimestamp()
public boolean isLastNA()
public void waitUntilAllReceived(int timeout) throws ExternalFrameConfirmationException
timeout
- timeout in secondsExternalFrameConfirmationException