private static void write2frame ( GenericRecord gr , String [ ] columnNames , Schema . Field [ ] inSchema , byte [ ] columnTypes , ParseWriter dout ) { assert inSchema . length == columnTypes . length : "AVRO field flatenized schema has to match to parser setup" ; BufferedString bs = new BufferedString ( ) ; for ( int cIdx = 0 ; cIdx < columnNames . length ; cIdx ++ ) { int inputFieldIdx = inSchema [ cIdx ] . pos ( ) ; Schema . Type inputType = toPrimitiveType ( inSchema [ cIdx ] . schema ( ) ) ; byte targetType = columnTypes [ cIdx ] ; // FIXME: support target conversions Object value = gr . get ( inputFieldIdx ) ; if ( value == null ) { dout . addInvalidCol ( cIdx ) ; } else { switch ( inputType ) { case BOOLEAN : dout . addNumCol ( cIdx , ( ( Boolean ) value ) ? 1 : 0 ) ; break ; case INT : dout . addNumCol ( cIdx , ( ( Integer ) value ) , 0 ) ; break ; case LONG : dout . addNumCol ( cIdx , ( ( Long ) value ) , 0 ) ; break ; case FLOAT : dout . addNumCol ( cIdx , ( Float ) value ) ; break ; case DOUBLE : dout . addNumCol ( cIdx , ( Double ) value ) ; break ; case ENUM : // Note: this code expects ordering of categoricals provided by Avro remain same // as in H2O!!! GenericData . EnumSymbol es = ( GenericData . EnumSymbol ) value ; dout . addNumCol ( cIdx , es . getSchema ( ) . getEnumOrdinal ( es . toString ( ) ) ) ; break ; case BYTES : dout . addStrCol ( cIdx , bs . set ( ( ( ByteBuffer ) value ) . array ( ) ) ) ; break ; case STRING : dout . addStrCol ( cIdx , bs . set ( ( ( Utf8 ) value ) . getBytes ( ) ) ) ; break ; case NULL : dout . addInvalidCol ( cIdx ) ; break ; } } } }
The main method transforming Avro record into a row in H2O frame .