@Override public void copyAsField(String name, MapWriter writer) { if (writer.ok()) { SingleMapWriter impl = (SingleMapWriter) writer.map(name); impl.inform(impl.container.copyFromSafe(idx(), impl.idx(), vector)); } }
// This function assumes that the fields in the schema parameter are in the same order as the // fields in the columns parameter. The // columns parameter may have fields that are not present in the schema, though. public DrillParquetGroupConverter( OutputMutator mutator, MapWriter mapWriter, GroupType schema, Collection<SchemaPath> columns, OptionManager options) { this.mapWriter = mapWriter; this.mutator = mutator; converters = Lists.newArrayList(); this.options = options; Iterator<SchemaPath> colIterator = columns.iterator(); for (Type type : schema.getFields()) { Repetition rep = type.getRepetition(); boolean isPrimitive = type.isPrimitive(); // Match the name of the field in the schema definition to the name of the field in the query. String name = null; SchemaPath col = null; PathSegment colPath = null; PathSegment colNextChild = null; while (colIterator.hasNext()) { col = colIterator.next(); colPath = col.getRootSegment(); colNextChild = colPath.getChild(); if (colPath != null && colPath.isNamed() && (!colPath.getNameSegment().getPath().equals("*"))) { name = colPath.getNameSegment().getPath(); // We may have a field that does not exist in the schema if (!name.equalsIgnoreCase(type.getName())) { continue; } } break; } if (name == null) { name = type.getName(); } if (!isPrimitive) { Collection<SchemaPath> c = new ArrayList<SchemaPath>(); while (colNextChild != null) { if (colNextChild.isNamed()) { break; } colNextChild = colNextChild.getChild(); } if (colNextChild != null) { SchemaPath s = new SchemaPath(colNextChild.getNameSegment()); c.add(s); } if (rep != Repetition.REPEATED) { DrillParquetGroupConverter converter = new DrillParquetGroupConverter( mutator, mapWriter.map(name), type.asGroupType(), c, options); converters.add(converter); } else { DrillParquetGroupConverter converter = new DrillParquetGroupConverter( mutator, mapWriter.list(name).map(), type.asGroupType(), c, options); converters.add(converter); } } else { PrimitiveConverter converter = getConverterForType(name, type.asPrimitiveType()); converters.add(converter); } } }