@Override public PositionOutputStream create(long ignored) throws IOException { return stream(file.create()); }
@SuppressWarnings("unchecked") private static <D> DataFileWriter<D> newAvroWriter( Schema schema, OutputFile file, Function<Schema, DatumWriter<?>> createWriterFunc, CodecFactory codec, Map<String, String> metadata) throws IOException { DataFileWriter<D> writer = new DataFileWriter<>( (DatumWriter<D>) createWriterFunc.apply(schema)); writer.setCodec(codec); for (Map.Entry<String, String> entry : metadata.entrySet()) { writer.setMeta(entry.getKey(), entry.getValue()); } // TODO: support overwrite return writer.create(schema, file.create()); } }
public static void write(TableMetadata metadata, OutputFile outputFile) { try (OutputStreamWriter writer = new OutputStreamWriter( outputFile.location().endsWith(".gz") ? new GzipCompressorOutputStream(outputFile.create()) : outputFile.create())) { JsonGenerator generator = JsonUtil.factory().createGenerator(writer); generator.useDefaultPrettyPrinter(); toJson(metadata, generator); generator.flush(); } catch (IOException e) { throw new RuntimeIOException(e, "Failed to write json to file: %s", outputFile); } }