Search in sources :

Example 1 with MessageOrBuilder

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);
                    }
                }
            }
        }
    }
}
Also used : MessageOrBuilder(com.google.protobuf.MessageOrBuilder) MessageOrBuilder(com.google.protobuf.MessageOrBuilder)

Example 2 with MessageOrBuilder

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;
}
Also used : Path(org.apache.hadoop.fs.Path) MessageOrBuilder(com.google.protobuf.MessageOrBuilder)

Example 3 with MessageOrBuilder

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;
}
Also used : Path(org.apache.flink.core.fs.Path) Message(com.google.protobuf.Message) MessageOrBuilder(com.google.protobuf.MessageOrBuilder) Builder(com.google.protobuf.Message.Builder) ArrayList(java.util.ArrayList) MessageOrBuilder(com.google.protobuf.MessageOrBuilder)

Aggregations

MessageOrBuilder (com.google.protobuf.MessageOrBuilder)3 Message (com.google.protobuf.Message)1 Builder (com.google.protobuf.Message.Builder)1 ArrayList (java.util.ArrayList)1 Path (org.apache.flink.core.fs.Path)1 Path (org.apache.hadoop.fs.Path)1