private void init(final GroupType selectedGroupType, final ConverterParent parent, final int index, final GroupType containingGroupType, TypeInfo hiveTypeInfo) { if (parent != null) { setMetadata(parent.getMetadata()); } final int selectedFieldCount = selectedGroupType.getFieldCount(); converters = new Converter[selectedFieldCount]; this.repeatedConverters = new ArrayList<Repeated>(); if (hiveTypeInfo != null && hiveTypeInfo.getCategory().equals(ObjectInspector.Category.STRUCT)) { this.hiveFieldNames = ((StructTypeInfo) hiveTypeInfo).getAllStructFieldNames(); this.hiveFieldTypeInfos = ((StructTypeInfo) hiveTypeInfo).getAllStructFieldTypeInfos(); } List<Type> selectedFields = selectedGroupType.getFields(); for (int i = 0; i < selectedFieldCount; i++) { Type subtype = selectedFields.get(i); if (isSubType(containingGroupType, subtype)) { int fieldIndex = containingGroupType.getFieldIndex(subtype.getName()); TypeInfo _hiveTypeInfo = getFieldTypeIgnoreCase(hiveTypeInfo, subtype.getName(), fieldIndex); converters[i] = getFieldConverter(subtype, fieldIndex, _hiveTypeInfo); } else { throw new IllegalStateException("Group type [" + containingGroupType + "] does not contain requested field: " + subtype); } } }
final int fieldIndex = g.getType().getFieldIndex(fieldName);
/** * @param fieldName string name of a field * @return the type of this field by name */ public Type getType(String fieldName) { return getType(getFieldIndex(fieldName)); }
/** * @param fieldName string name of a field * @return the type of this field by name */ public Type getType(String fieldName) { return getType(getFieldIndex(fieldName)); }
public void add(String field, double value) { add(getType().getFieldIndex(field), value); }
public int getFieldRepetitionCount(String field) { return getFieldRepetitionCount(getType().getFieldIndex(field)); }
public long getLong(String field, int index) { return getLong(getType().getFieldIndex(field), index); }
public boolean getBoolean(String field, int index) { return getBoolean(getType().getFieldIndex(field), index); }
public void add(String field, float value) { add(getType().getFieldIndex(field), value); }
public void add(String field, Binary value) { add(getType().getFieldIndex(field), value); }
public void add(String field, Group value) { add(getType().getFieldIndex(field), value); }
public GroupValueSource getGroup(String field, int index) { return getGroup(getType().getFieldIndex(field), index); }
public Binary getBinary(String field, int index) { return getBinary(getType().getFieldIndex(field), index); }
public Binary getInt96(String field, int index) { return getInt96(getType().getFieldIndex(field), index); }
public void add(String field, float value) { add(getType().getFieldIndex(field), value); }
public Group addGroup(String field) { if (LOG.isDebugEnabled()) { LOG.debug("add group {} to {}", field, getType().getName()); } return addGroup(getType().getFieldIndex(field)); }
public Group addGroup(String field) { if (LOG.isDebugEnabled()) { LOG.debug("add group {} to {}", field, getType().getName()); } return addGroup(getType().getFieldIndex(field)); }
/** validates mapping between protobuffer fields and parquet fields.*/ private void validatedMapping(Descriptors.Descriptor descriptor, GroupType parquetSchema) { List<Descriptors.FieldDescriptor> allFields = descriptor.getFields(); for (Descriptors.FieldDescriptor fieldDescriptor: allFields) { String fieldName = fieldDescriptor.getName(); int fieldIndex = fieldDescriptor.getIndex(); int parquetIndex = parquetSchema.getFieldIndex(fieldName); if (fieldIndex != parquetIndex) { String message = "FieldIndex mismatch name=" + fieldName + ": " + fieldIndex + " != " + parquetIndex; throw new IncompatibleSchemaModificationException(message); } } }
private PrimitiveConverter getPrimitiveConverter(ColumnDescriptor path) { Type currentType = schema; Converter currentConverter = recordConverter; for (String fieldName : path.getPath()) { final GroupType groupType = currentType.asGroupType(); int fieldIndex = groupType.getFieldIndex(fieldName); currentType = groupType.getType(fieldName); currentConverter = currentConverter.asGroupConverter().getConverter(fieldIndex); } PrimitiveConverter converter = currentConverter.asPrimitiveConverter(); return converter; }
private PrimitiveConverter getPrimitiveConverter(ColumnDescriptor path) { Type currentType = schema; Converter currentConverter = recordConverter; for (String fieldName : path.getPath()) { final GroupType groupType = currentType.asGroupType(); int fieldIndex = groupType.getFieldIndex(fieldName); currentType = groupType.getType(fieldName); currentConverter = currentConverter.asGroupConverter().getConverter(fieldIndex); } PrimitiveConverter converter = currentConverter.asPrimitiveConverter(); return converter; }