@Override protected OrcUnion createUnionObject(List<TypeInfo> childrenTypes, Object previous) { return (previous instanceof OrcUnion) ? (OrcUnion)previous : new OrcUnion(); }
@Override protected void setUnion(OrcUnion unionObj, byte tag, Object object) { unionObj.set(tag, object); }
@Override protected Object getUnionField(OrcUnion unionObj) { return unionObj.getObject(); }
.blockPadding(false)); OrcStruct row = new OrcStruct(3); OrcUnion union = new OrcUnion(); row.setFieldValue(1, union); row.setFieldValue(0, new TimestampWritableV2(Timestamp.valueOf("2000-03-12 15:00:00"))); HiveDecimal value = HiveDecimal.create("12345678.6547456"); row.setFieldValue(2, new HiveDecimalWritable(value)); union.set((byte) 0, new IntWritable(42)); writer.addRow(row); row.setFieldValue(0, new TimestampWritableV2(Timestamp.valueOf("2000-03-20 12:00:00.123456789"))); union.set((byte) 1, new Text("hello")); value = HiveDecimal.create("-5643.234"); row.setFieldValue(2, new HiveDecimalWritable(value)); writer.addRow(row); row.setFieldValue(1, union); union.set((byte) 0, null); writer.addRow(row); union.set((byte) 1, null); writer.addRow(row); union.set((byte) 0, new IntWritable(200000)); row.setFieldValue(0, new TimestampWritableV2 (Timestamp.valueOf("1970-01-01 00:00:00"))); "-05-05 12:34:56." + i))); if ((i & 1) == 0) { union.set((byte) 0, new IntWritable(i*i)); } else { union.set((byte) 1, new Text(Integer.toString(i * i)));
static OrcUnion nextUnion(ColumnVector vector, int row, TypeDescription schema, Object previous) { if (vector.isRepeating) { row = 0; } if (vector.noNulls || !vector.isNull[row]) { OrcUnion result; List<TypeDescription> childrenTypes = schema.getChildren(); if (previous == null || previous.getClass() != OrcUnion.class) { result = new OrcUnion(); } else { result = (OrcUnion) previous; } UnionColumnVector union = (UnionColumnVector) vector; byte tag = (byte) union.tags[row]; result.set(tag, nextValue(union.fields[tag], row, childrenTypes.get(tag), result.getObject())); return result; } else { return null; } }
@Test public void testUnion() throws Exception { OrcUnion un1 = new OrcUnion(); OrcUnion un2 = new OrcUnion(); un1.set((byte) 0, "hi"); un2.set((byte) 0, "hi"); assertEquals(un1, un2); assertEquals(un1.hashCode(), un2.hashCode()); un2.set((byte) 0, null); assertEquals(false, un1.equals(un2)); assertEquals(false, un2.equals(un1)); un1.set((byte) 0, null); assertEquals(un1, un2); un2.set((byte) 0, "hi"); un1.set((byte) 1, "hi"); assertEquals(false, un1.equals(un2)); assertEquals(false, un1.hashCode() == un2.hashCode()); un2.set((byte) 1, "byte"); assertEquals(false, un1.equals(un2)); assertEquals("union(1, hi)", un1.toString()); assertEquals(false, un1.equals(null)); } }
public static Object convertToORCObject(TypeInfo typeInfo, Object o) { if (o != null) { if (typeInfo instanceof UnionTypeInfo) { OrcUnion union = new OrcUnion(); union.set((byte) index, convertToORCObject(objectTypeInfo, o)); } else { throw new IllegalArgumentException("Object Type for class " + o.getClass().getName() + " not in Union declaration");
@Override Object next(Object previous) throws IOException { super.next(previous); OrcUnion result = null; if (valuePresent) { if (previous == null) { result = new OrcUnion(); } else { result = (OrcUnion) previous; } byte tag = tags.next(); Object previousVal = result.getObject(); result.set(tag, fields[tag].next(tag == result.getTag() ? previousVal : null)); } return result; }
static OrcUnion nextUnion(ColumnVector vector, int row, TypeDescription schema, Object previous) { if (vector.isRepeating) { row = 0; } if (vector.noNulls || !vector.isNull[row]) { OrcUnion result; List<TypeDescription> childrenTypes = schema.getChildren(); if (previous == null || previous.getClass() != OrcUnion.class) { result = new OrcUnion(); } else { result = (OrcUnion) previous; } UnionColumnVector union = (UnionColumnVector) vector; byte tag = (byte) union.tags[row]; result.set(tag, nextValue(union.fields[tag], row, childrenTypes.get(tag), result.getObject())); return result; } else { return null; } }
public static Object convertToORCObject(TypeInfo typeInfo, Object o, final boolean hiveFieldNames) { if (o != null) { if (typeInfo instanceof UnionTypeInfo) { OrcUnion union = new OrcUnion(); union.set((byte) index, convertToORCObject(objectTypeInfo, o, hiveFieldNames)); } else { throw new IllegalArgumentException("Object Type for class " + o.getClass().getName() + " not in Union declaration");
public static Object convertToORCObject(TypeInfo typeInfo, Object o) { if (o != null) { if (typeInfo instanceof UnionTypeInfo) { OrcUnion union = new OrcUnion(); union.set((byte) index, convertToORCObject(objectTypeInfo, o)); } else { throw new IllegalArgumentException("Object Type for class " + o.getClass().getName() + " not in Union declaration");
@Override protected OrcUnion createUnionObject(List<TypeInfo> childrenTypes, Object previous) { return (previous instanceof OrcUnion) ? (OrcUnion)previous : new OrcUnion(); }
@Override protected void setUnion(OrcUnion unionObj, byte tag, Object object) { unionObj.set(tag, object); } }
@Override protected Object getUnionField(OrcUnion unionObj) { return unionObj.getObject(); }