use of com.google.protobuf.MessageOrBuilder in project parquet-mr by apache.
the class TestUtils method checkSameBuilderInstance.
/**
* Fails if some instance of builder is two times in list.
*/
private static void checkSameBuilderInstance(MessageOrBuilder[] messages) {
for (int i = 0; i < messages.length; i++) {
MessageOrBuilder firstMessage = messages[i];
boolean isBuilder = firstMessage instanceof Message.Builder;
if (isBuilder) {
for (int j = 0; j < messages.length; j++) {
MessageOrBuilder secondMessage = messages[j];
if (i != j) {
boolean isSame = secondMessage == firstMessage;
if (isSame) {
fail("Data contains two references to same instance." + secondMessage);
}
}
}
}
}
}
use of com.google.protobuf.MessageOrBuilder in project parquet-mr by apache.
the class TestUtils method writeMessages.
public static Path writeMessages(Class<? extends Message> cls, MessageOrBuilder... records) throws IOException {
Path file = someTemporaryFilePath();
ProtoParquetWriter<MessageOrBuilder> writer = new ProtoParquetWriter<MessageOrBuilder>(file, cls);
for (MessageOrBuilder record : records) {
writer.write(record);
}
writer.close();
return file;
}
use of com.google.protobuf.MessageOrBuilder in project flink by apache.
the class ParquetProtoStreamingFileSinkITCase method readParquetFile.
private static List<Message> readParquetFile(File file) throws IOException {
org.apache.hadoop.fs.Path path = new org.apache.hadoop.fs.Path(file.getAbsolutePath());
ArrayList<Message> results = new ArrayList<>();
try (ParquetReader<MessageOrBuilder> reader = ProtoParquetReader.<MessageOrBuilder>builder(path).build()) {
MessageOrBuilder next;
while ((next = reader.read()) != null) {
if (next instanceof Builder) {
// Builder is mutable and we need to ensure the saved reference does not change
// after reading more records.
results.add(((Builder) next).build());
} else {
results.add((Message) next);
}
}
}
return results;
}