public AvroColumnWriter(Schema s, ColumnFileMetaData meta, GenericData model) throws IOException { this.schema = s; AvroColumnator columnator = new AvroColumnator(s); meta.set(SCHEMA_KEY, s.toString()); // save schema in file this.writer = new ColumnFileWriter(meta, columnator.getColumns()); this.arrayWidths = columnator.getArrayWidths(); this.model = model; }
void initialize() throws IOException { // compute a mapping from column name to number for file Map<String,Integer> fileColumnNumbers = new HashMap<>(); int i = 0; for (ColumnMetaData c : new AvroColumnator(fileSchema).getColumns()) fileColumnNumbers.put(c.getName(), i++); // create iterator for each column in readSchema AvroColumnator readColumnator = new AvroColumnator(readSchema); this.arrayWidths = readColumnator.getArrayWidths(); ColumnMetaData[] readColumns = readColumnator.getColumns(); this.values = new ColumnValues[readColumns.length]; int j = 0; for (ColumnMetaData c : readColumns) { Integer n = fileColumnNumbers.get(c.getName()); if (n != null) values[j++] = reader.getValues(n); } findDefaults(readSchema, fileSchema); }
private void check(Schema s, ColumnMetaData... expected) throws Exception { ColumnMetaData[] shredded = new AvroColumnator(s).getColumns(); assertEquals(expected.length, shredded.length); for (int i = 0; i < expected.length; i++) assertEquals(expected[i].toString(), shredded[i].toString()); checkWrite(s); checkRead(s); }
public AvroColumnWriter(Schema s, ColumnFileMetaData meta, GenericData model) throws IOException { this.schema = s; AvroColumnator columnator = new AvroColumnator(s); meta.set(SCHEMA_KEY, s.toString()); // save schema in file this.writer = new ColumnFileWriter(meta, columnator.getColumns()); this.arrayWidths = columnator.getArrayWidths(); this.model = model; }
void initialize() throws IOException { // compute a mapping from column name to number for file Map<String,Integer> fileColumnNumbers = new HashMap<String,Integer>(); int i = 0; for (ColumnMetaData c : new AvroColumnator(fileSchema).getColumns()) fileColumnNumbers.put(c.getName(), i++); // create iterator for each column in readSchema AvroColumnator readColumnator = new AvroColumnator(readSchema); this.arrayWidths = readColumnator.getArrayWidths(); ColumnMetaData[] readColumns = readColumnator.getColumns(); this.values = new ColumnValues[readColumns.length]; int j = 0; for (ColumnMetaData c : readColumns) { Integer n = fileColumnNumbers.get(c.getName()); if (n == null) throw new TrevniRuntimeException("No column named: "+c.getName()); values[j++] = reader.getValues(n); } }
private void check(Schema s, ColumnMetaData... expected) throws Exception { ColumnMetaData[] shredded = new AvroColumnator(s).getColumns(); assertEquals(expected.length, shredded.length); for (int i = 0; i < expected.length; i++) assertEquals(expected[i].toString(), shredded[i].toString()); checkWrite(s); checkRead(s); }