### Question:
LazyHCatRecord extends HCatRecord { @Override public Object get(int fieldNum) { try { StructField fref = soi.getAllStructFieldRefs().get(fieldNum); return HCatRecordSerDe.serializeField( soi.getStructFieldData(wrappedObject, fref), fref.getFieldObjectInspector()); } catch (SerDeException e) { throw new IllegalStateException("SerDe Exception deserializing",e); } } LazyHCatRecord(Object wrappedObject, ObjectInspector oi); @Override Object get(int fieldNum); @Override List<Object> getAll(); @Override void set(int fieldNum, Object value); @Override int size(); @Override void readFields(DataInput in); @Override void write(DataOutput out); @Override Object get(String fieldName, HCatSchema recordSchema); @Override void set(String fieldName, HCatSchema recordSchema, Object value); @Override void remove(int idx); @Override void copy(HCatRecord r); @Override String toString(); HCatRecord getWritable(); static final Logger LOG; }### Answer:
@Test public void testGet() throws Exception { HCatRecord r = new LazyHCatRecord(getHCatRecord(), getObjectInspector()); Assert.assertEquals(INT_CONST, ((Integer) r.get(0)).intValue()); Assert.assertEquals(LONG_CONST, ((Long) r.get(1)).longValue()); Assert.assertEquals(DOUBLE_CONST, ((Double) r.get(2)).doubleValue(), 0); Assert.assertEquals(STRING_CONST, (String) r.get(3)); }
@Test public void testGetWithName() throws Exception { TypeInfo ti = getTypeInfo(); HCatRecord r = new LazyHCatRecord(getHCatRecord(), getObjectInspector(ti)); HCatSchema schema = HCatSchemaUtils.getHCatSchema(ti) .get(0).getStructSubSchema(); Assert.assertEquals(INT_CONST, ((Integer) r.get("an_int", schema)).intValue()); Assert.assertEquals(LONG_CONST, ((Long) r.get("a_long", schema)).longValue()); Assert.assertEquals(DOUBLE_CONST, ((Double) r.get("a_double", schema)).doubleValue(), 0); Assert.assertEquals(STRING_CONST, (String) r.get("a_string", schema)); }
@Test public void testGet() throws Exception { HCatRecord r = new LazyHCatRecord(getHCatRecord(), getObjectInspector()); Assert.assertEquals(INT_CONST, ((Integer) r.get(0)).intValue()); Assert.assertEquals(LONG_CONST, ((Long) r.get(1)).longValue()); Assert.assertEquals(DOUBLE_CONST, ((Double) r.get(2)).doubleValue(), 0); Assert.assertEquals(STRING_CONST, r.get(3)); }
@Test public void testGetWithName() throws Exception { TypeInfo ti = getTypeInfo(); HCatRecord r = new LazyHCatRecord(getHCatRecord(), getObjectInspector(ti)); HCatSchema schema = HCatSchemaUtils.getHCatSchema(ti) .get(0).getStructSubSchema(); Assert.assertEquals(INT_CONST, ((Integer) r.get("an_int", schema)).intValue()); Assert.assertEquals(LONG_CONST, ((Long) r.get("a_long", schema)).longValue()); Assert.assertEquals(DOUBLE_CONST, ((Double) r.get("a_double", schema)).doubleValue(), 0); Assert.assertEquals(STRING_CONST, r.get("a_string", schema)); }