WritableRecord implements Record { @Override public byte[] getBytes(int idx) { if (enableColumnAccessStat) { columnAccessMark(idx); } Text o = (Text) values[idx]; if (o == null) { return null; } return Arrays.copyOfRange(o.getBytes(), 0, o.getLength()); } WritableRecord(Column[] columns); @Override int getColumnCount(); @Override Column[] getColumns(); @Override void set(int idx, Object value); @Override Object get(int idx); @Override void set(String columnName, Object value); @Override Object get(String columnName); @Override void setBigint(int idx, Long value); @Override Long getBigint(int idx); @Override void setBigint(String columnName, Long value); @Override Long getBigint(String columnName); @Override void setDouble(int idx, Double value); @Override Double getDouble(int idx); @Override void setDouble(String columnName, Double value); @Override Double getDouble(String columnName); @Override void setBoolean(int idx, Boolean value); @Override Boolean getBoolean(int idx); @Override void setBoolean(String columnName, Boolean value); @Override Boolean getBoolean(String columnName); @Override void setDatetime(int idx, Date value); @Override Date getDatetime(int idx); @Override void setDatetime(String columnName, Date value); @Override Date getDatetime(String columnName); @Override void setString(int idx, String value); @Override String getString(int idx); @Override void setString(String columnName, String value); @Override String getString(String columnName); @Override void setString(int idx, byte[] value); @Override void setString(String columnName, byte[] value); @Override byte[] getBytes(int idx); @Override byte[] getBytes(String columnName); @Override void set(Object[] values); @Override Object[] toArray(); Writable[] toWritableArray(); @Override void setDecimal(int idx, BigDecimal value); @Override BigDecimal getDecimal(int idx); @Override void setDecimal(String columnName, BigDecimal value); @Override BigDecimal getDecimal(String columnName); void setChar(int idx, Char value); void setChar(String columnName, Char value); Char getChar(int idx); Char getChar(String columnName); void setVarchar(int idx, Varchar value); void setVarchar(String columnName, Varchar value); Varchar getVarchar(int idx); Varchar getVarchar(String columnName); void setDate(int idx, java.sql.Date value); java.sql.Date getDate(int idx); void setDate(String columnName, java.sql.Date value); java.sql.Date getDate(String columnName); void setTimestamp(int idx, Timestamp value); Timestamp getTimestamp(int idx); void setTimestamp(String columnName, Timestamp value); Timestamp getTimestamp(String columnName); void setFloat(int idx, Float value); void setFloat(String columnName, Float value); Float getFloat(int idx); Float getFloat(String columnName); void setInt(int idx, Integer value); void setInt(String columnName, Integer value); Integer getInt(int idx); Integer getInt(String columnName); void setTinyint(int idx, Byte value); void setTinyint(String columnName, Byte value); Byte getTinyint(int idx); Byte getTinyint(String columnName); void setSmallint(int idx, Short value); void setSmallint(String columnName, Short value); Short getSmallint(int idx); Short getSmallint(String columnName); void setBinary(int idx, Binary value); void setBinary(String columnName, Binary value); Binary getBinary(int idx); Binary getBinary(String columnName); IntervalYearMonth getIntervalYearMonth(int idx); IntervalYearMonth getIntervalYearMonth(String columnName); void setIntervalYearMonth(int idx, IntervalYearMonth value); void setIntervalYearMonth(String columnName, IntervalYearMonth value); IntervalDayTime getIntervalDayTime(int idx); IntervalDayTime getIntervalDayTime(String columnName); void setIntervalDayTime(int idx, IntervalDayTime value); void setIntervalDayTime(String columnName, IntervalDayTime value); void setArray(String columnName, Writable value); void setArray(int idx, Writable value); void setMap(int idx, Writable value); void setMap(String columnName, Writable value); void setStruct(int idx, Writable value); void setStruct(String columnName, Writable value); ArrayWritable getArray(String columnName); ArrayWritable getArray(int idx); MapWritable getMap(String columnName); MapWritable getMap(int idx); StructWritable getStruct(int idx); StructWritable getStruct(String columnName); @Override boolean isNull(int idx); @Override boolean isNull(String columnName); @Override Record clone();  }
@Test public void testGetBytes() throws ArrayComparisonFailure, UnsupportedEncodingException { Column col1 = new Column("col1", OdpsType.STRING); Column col2 = new Column("col2", OdpsType.STRING); Column[] columns = new Column[] {col1, col2}; WritableRecord record = new WritableRecord(columns); record.set("col1", "val1"); record.set(1, "val2"); byte[] b1 = record.getBytes(0); byte[] b2 = record.getBytes(1); Assert.assertEquals(4, b1.length); Assert.assertArrayEquals("Byte not equal", b1, "val1".getBytes()); Assert.assertEquals(4, b2.length); Assert.assertArrayEquals("Byte not equal", b2, "val2".getBytes()); record.set(0, "中文测试1"); record.set("col2", "中文测试2"); b1 = record.getBytes(0); b2 = record.getBytes(1); Assert.assertEquals(13, b1.length); Assert.assertArrayEquals("Byte not equal", b1, "中文测试1".getBytes(STRING_CHARSET)); Assert.assertEquals(13, b2.length); Assert.assertArrayEquals("Byte not equal", b2, "中文测试2".getBytes(STRING_CHARSET)); record.set(0, ""); record.set("col2", null); b1 = record.getBytes(0); b2 = record.getBytes(1); Assert.assertEquals(0, b1.length); Assert.assertArrayEquals("Byte not equal", b1, "".getBytes()); Assert.assertNull(b2); }