You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@parquet.apache.org by bl...@apache.org on 2014/12/19 00:34:05 UTC
incubator-parquet-format git commit: PARQUET-23: Refactor
parquet-format to org.apache names.
Repository: incubator-parquet-format
Updated Branches:
refs/heads/master f7ab552f5 -> af1e5b833
PARQUET-23: Refactor parquet-format to org.apache names.
This updates parquet-format to use org.apache names. Still need to:
* Validate that parquet-mr works as expected when relying on these changes
Author: Ryan Blue <bl...@apache.org>
Closes #18 from rdblue/PARQUET-23-rename-to-org-apache and squashes the following commits:
ddcd50e [Ryan Blue] PARQUET-23: Update changelog for org.apache parquet-format 2.2.0.
5c339d4 [Ryan Blue] PARQUET-23: Update POM to use Apache maven release config.
ac982ca [Ryan Blue] PARQUET-23: Refactor parquet-format to org.apache names.
Project: http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/commit/af1e5b83
Tree: http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/tree/af1e5b83
Diff: http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/diff/af1e5b83
Branch: refs/heads/master
Commit: af1e5b8338465b4a010185837405c09ad895afb6
Parents: f7ab552
Author: Ryan Blue <bl...@apache.org>
Authored: Thu Dec 18 15:33:56 2014 -0800
Committer: Ryan Blue <bl...@apache.org>
Committed: Thu Dec 18 15:33:56 2014 -0800
----------------------------------------------------------------------
CHANGES.md | 7 +
pom.xml | 106 +--------
.../parquet/format/InterningProtocol.java | 234 +++++++++++++++++++
.../java/org/apache/parquet/format/Util.java | 227 ++++++++++++++++++
.../apache/parquet/format/event/Consumers.java | 199 ++++++++++++++++
.../format/event/EventBasedThriftReader.java | 129 ++++++++++
.../parquet/format/event/FieldConsumer.java | 43 ++++
.../parquet/format/event/TypedConsumer.java | 204 ++++++++++++++++
.../java/parquet/format/InterningProtocol.java | 234 -------------------
src/main/java/parquet/format/Util.java | 227 ------------------
.../java/parquet/format/event/Consumers.java | 199 ----------------
.../format/event/EventBasedThriftReader.java | 129 ----------
.../parquet/format/event/FieldConsumer.java | 43 ----
.../parquet/format/event/TypedConsumer.java | 204 ----------------
.../org/apache/parquet/format/TestUtil.java | 83 +++++++
src/test/java/parquet/format/TestUtil.java | 83 -------
src/thrift/parquet.thrift | 2 +-
17 files changed, 1131 insertions(+), 1222 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/blob/af1e5b83/CHANGES.md
----------------------------------------------------------------------
diff --git a/CHANGES.md b/CHANGES.md
index ac2348a..befe532 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -19,6 +19,13 @@
# Parquet #
+### Version 2.2.0 ###
+
+* [PARQUET-23](https://issues.apache.org/jira/browse/PARQUET-23): Rename packages and maven coordinates to org.apache
+* [PARQUET-119](https://issues.apache.org/jira/browse/PARQUET-119): Add encoding stats to ColumnMetaData
+* [PARQUET-79](https://issues.apache.org/jira/browse/PARQUET-79): Streaming thrift API
+* [PARQUET-12](https://issues.apache.org/jira/browse/PARQUET-12): New logical types
+
### Version 2.1.0 ###
* ISSUE [84](https://github.com/Parquet/parquet-format/pull/84): Add metadata in the schema for storing decimals.
* ISSUE [89](https://github.com/Parquet/parquet-format/pull/89): Added statistics to the data page header
http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/blob/af1e5b83/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 2096f2a..33f64b9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,12 +23,12 @@
<parent>
<groupId>org.apache</groupId>
<artifactId>apache</artifactId>
- <version>14</version>
+ <version>16</version>
</parent>
- <groupId>com.twitter</groupId>
+ <groupId>org.apache.parquet</groupId>
<artifactId>parquet-format</artifactId>
- <version>2.2.0-rc2-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Apache Parquet Format (Incubating)</name>
@@ -81,67 +81,18 @@
</developer>
</developers>
- <distributionManagement>
- <snapshotRepository>
- <id>sonatype-nexus-snapshots</id>
- <name>Sonatype OSS</name>
- <url>https://oss.sonatype.org/content/repositories/snapshots</url>
- </snapshotRepository>
- <repository>
- <id>sonatype-nexus-staging</id>
- <name>Nexus Release Repository</name>
- <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
- </repository>
- </distributionManagement>
-
- <repositories>
- <repository>
- <id>sonatype-nexus-snapshots</id>
- <url>https://oss.sonatype.org/content/repositories/snapshots</url>
- <releases>
- <enabled>false</enabled>
- </releases>
- <snapshots>
- <enabled>true</enabled>
- </snapshots>
- </repository>
- </repositories>
-
- <!-- this is needed for maven-thrift-plugin, would like to remove this.
- see: https://issues.apache.org/jira/browse/THRIFT-1536 -->
- <pluginRepositories>
- <pluginRepository>
- <id>Twitter public Maven repo</id>
- <url>http://maven.twttr.com</url>
- </pluginRepository>
- </pluginRepositories>
-
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<build>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-release-plugin</artifactId>
- <version>2.1</version>
- <configuration>
- <mavenExecutorId>forked-path</mavenExecutorId>
- <useReleaseProfile>false</useReleaseProfile>
- <arguments>-Psonatype-oss-release</arguments>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
<plugins>
<!-- thrift -->
<plugin>
<groupId>org.apache.thrift.tools</groupId>
<artifactId>maven-thrift-plugin</artifactId>
- <version>0.1.10</version>
+ <version>0.1.11</version>
<configuration>
<thriftSourceRoot>src/thrift</thriftSourceRoot>
</configuration>
@@ -262,53 +213,4 @@
<scope>test</scope>
</dependency>
</dependencies>
- <profiles>
- <profile>
- <id>sonatype-oss-release</id>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
- <version>2.1.2</version>
- <executions>
- <execution>
- <id>attach-sources</id>
- <goals>
- <goal>jar-no-fork</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <version>2.7</version>
- <executions>
- <execution>
- <id>attach-javadocs</id>
- <goals>
- <goal>jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-gpg-plugin</artifactId>
- <version>1.1</version>
- <executions>
- <execution>
- <id>sign-artifacts</id>
- <phase>verify</phase>
- <goals>
- <goal>sign</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/blob/af1e5b83/src/main/java/org/apache/parquet/format/InterningProtocol.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/parquet/format/InterningProtocol.java b/src/main/java/org/apache/parquet/format/InterningProtocol.java
new file mode 100644
index 0000000..6297f1c
--- /dev/null
+++ b/src/main/java/org/apache/parquet/format/InterningProtocol.java
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.parquet.format;
+
+import java.nio.ByteBuffer;
+
+import org.apache.thrift.TException;
+import org.apache.thrift.protocol.TField;
+import org.apache.thrift.protocol.TList;
+import org.apache.thrift.protocol.TMap;
+import org.apache.thrift.protocol.TMessage;
+import org.apache.thrift.protocol.TProtocol;
+import org.apache.thrift.protocol.TSet;
+import org.apache.thrift.protocol.TStruct;
+import org.apache.thrift.transport.TTransport;
+
+/**
+ * TProtocol that interns the strings.
+ *
+ * @author Julien Le Dem
+ *
+ */
+public class InterningProtocol extends TProtocol {
+
+ private final TProtocol delegate;
+
+ public InterningProtocol(TProtocol delegate) {
+ super(delegate.getTransport());
+ this.delegate = delegate;
+ }
+
+ public TTransport getTransport() {
+ return delegate.getTransport();
+ }
+
+ public void writeMessageBegin(TMessage message) throws TException {
+ delegate.writeMessageBegin(message);
+ }
+
+ public void writeMessageEnd() throws TException {
+ delegate.writeMessageEnd();
+ }
+
+ public int hashCode() {
+ return delegate.hashCode();
+ }
+
+ public void writeStructBegin(TStruct struct) throws TException {
+ delegate.writeStructBegin(struct);
+ }
+
+ public void writeStructEnd() throws TException {
+ delegate.writeStructEnd();
+ }
+
+ public void writeFieldBegin(TField field) throws TException {
+ delegate.writeFieldBegin(field);
+ }
+
+ public void writeFieldEnd() throws TException {
+ delegate.writeFieldEnd();
+ }
+
+ public void writeFieldStop() throws TException {
+ delegate.writeFieldStop();
+ }
+
+ public void writeMapBegin(TMap map) throws TException {
+ delegate.writeMapBegin(map);
+ }
+
+ public void writeMapEnd() throws TException {
+ delegate.writeMapEnd();
+ }
+
+ public void writeListBegin(TList list) throws TException {
+ delegate.writeListBegin(list);
+ }
+
+ public void writeListEnd() throws TException {
+ delegate.writeListEnd();
+ }
+
+ public void writeSetBegin(TSet set) throws TException {
+ delegate.writeSetBegin(set);
+ }
+
+ public void writeSetEnd() throws TException {
+ delegate.writeSetEnd();
+ }
+
+ public void writeBool(boolean b) throws TException {
+ delegate.writeBool(b);
+ }
+
+ public void writeByte(byte b) throws TException {
+ delegate.writeByte(b);
+ }
+
+ public void writeI16(short i16) throws TException {
+ delegate.writeI16(i16);
+ }
+
+ public void writeI32(int i32) throws TException {
+ delegate.writeI32(i32);
+ }
+
+ public void writeI64(long i64) throws TException {
+ delegate.writeI64(i64);
+ }
+
+ public void writeDouble(double dub) throws TException {
+ delegate.writeDouble(dub);
+ }
+
+ public void writeString(String str) throws TException {
+ delegate.writeString(str);
+ }
+
+ public void writeBinary(ByteBuffer buf) throws TException {
+ delegate.writeBinary(buf);
+ }
+
+ public TMessage readMessageBegin() throws TException {
+ return delegate.readMessageBegin();
+ }
+
+ public void readMessageEnd() throws TException {
+ delegate.readMessageEnd();
+ }
+
+ public TStruct readStructBegin() throws TException {
+ return delegate.readStructBegin();
+ }
+
+ public void readStructEnd() throws TException {
+ delegate.readStructEnd();
+ }
+
+ public TField readFieldBegin() throws TException {
+ return delegate.readFieldBegin();
+ }
+
+ public void readFieldEnd() throws TException {
+ delegate.readFieldEnd();
+ }
+
+ public TMap readMapBegin() throws TException {
+ return delegate.readMapBegin();
+ }
+
+ public void readMapEnd() throws TException {
+ delegate.readMapEnd();
+ }
+
+ public TList readListBegin() throws TException {
+ return delegate.readListBegin();
+ }
+
+ public void readListEnd() throws TException {
+ delegate.readListEnd();
+ }
+
+ public TSet readSetBegin() throws TException {
+ return delegate.readSetBegin();
+ }
+
+ public void readSetEnd() throws TException {
+ delegate.readSetEnd();
+ }
+
+ public boolean equals(Object obj) {
+ return delegate.equals(obj);
+ }
+
+ public boolean readBool() throws TException {
+ return delegate.readBool();
+ }
+
+ public byte readByte() throws TException {
+ return delegate.readByte();
+ }
+
+ public short readI16() throws TException {
+ return delegate.readI16();
+ }
+
+ public int readI32() throws TException {
+ return delegate.readI32();
+ }
+
+ public long readI64() throws TException {
+ return delegate.readI64();
+ }
+
+ public double readDouble() throws TException {
+ return delegate.readDouble();
+ }
+
+ public String readString() throws TException {
+ // this is where we intern the strings
+ return delegate.readString().intern();
+ }
+
+ public ByteBuffer readBinary() throws TException {
+ return delegate.readBinary();
+ }
+
+ public void reset() {
+ delegate.reset();
+ }
+
+ public String toString() {
+ return delegate.toString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/blob/af1e5b83/src/main/java/org/apache/parquet/format/Util.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/parquet/format/Util.java b/src/main/java/org/apache/parquet/format/Util.java
new file mode 100644
index 0000000..09cae2b
--- /dev/null
+++ b/src/main/java/org/apache/parquet/format/Util.java
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.parquet.format;
+
+import static org.apache.parquet.format.FileMetaData._Fields.CREATED_BY;
+import static org.apache.parquet.format.FileMetaData._Fields.KEY_VALUE_METADATA;
+import static org.apache.parquet.format.FileMetaData._Fields.NUM_ROWS;
+import static org.apache.parquet.format.FileMetaData._Fields.ROW_GROUPS;
+import static org.apache.parquet.format.FileMetaData._Fields.SCHEMA;
+import static org.apache.parquet.format.FileMetaData._Fields.VERSION;
+import static org.apache.parquet.format.event.Consumers.fieldConsumer;
+import static org.apache.parquet.format.event.Consumers.listElementsOf;
+import static org.apache.parquet.format.event.Consumers.listOf;
+import static org.apache.parquet.format.event.Consumers.struct;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+
+import org.apache.thrift.TBase;
+import org.apache.thrift.TException;
+import org.apache.thrift.protocol.TCompactProtocol;
+import org.apache.thrift.protocol.TProtocol;
+import org.apache.thrift.transport.TIOStreamTransport;
+
+import org.apache.parquet.format.event.Consumers.Consumer;
+import org.apache.parquet.format.event.Consumers.DelegatingFieldConsumer;
+import org.apache.parquet.format.event.EventBasedThriftReader;
+import org.apache.parquet.format.event.TypedConsumer.I32Consumer;
+import org.apache.parquet.format.event.TypedConsumer.I64Consumer;
+import org.apache.parquet.format.event.TypedConsumer.StringConsumer;
+
+/**
+ * Utility to read/write metadata
+ * We use the TCompactProtocol to serialize metadata
+ *
+ * @author Julien Le Dem
+ *
+ */
+public class Util {
+
+ public static void writePageHeader(PageHeader pageHeader, OutputStream to) throws IOException {
+ write(pageHeader, to);
+ }
+
+ public static PageHeader readPageHeader(InputStream from) throws IOException {
+ return read(from, new PageHeader());
+ }
+
+ public static void writeFileMetaData(org.apache.parquet.format.FileMetaData fileMetadata, OutputStream to) throws IOException {
+ write(fileMetadata, to);
+ }
+
+ public static FileMetaData readFileMetaData(InputStream from) throws IOException {
+ return read(from, new FileMetaData());
+ }
+ /**
+ * reads the meta data from the stream
+ * @param from the stream to read the metadata from
+ * @param skipRowGroups whether row groups should be skipped
+ * @return the resulting metadata
+ * @throws IOException
+ */
+ public static FileMetaData readFileMetaData(InputStream from, boolean skipRowGroups) throws IOException {
+ FileMetaData md = new FileMetaData();
+ if (skipRowGroups) {
+ readFileMetaData(from, new DefaultFileMetaDataConsumer(md), skipRowGroups);
+ } else {
+ read(from, md);
+ }
+ return md;
+ }
+
+ /**
+ * To read metadata in a streaming fashion.
+ *
+ * @author Julien Le Dem
+ *
+ */
+ public static abstract class FileMetaDataConsumer {
+ abstract public void setVersion(int version);
+ abstract public void setSchema(List<SchemaElement> schema);
+ abstract public void setNumRows(long numRows);
+ abstract public void addRowGroup(RowGroup rowGroup);
+ abstract public void addKeyValueMetaData(KeyValue kv);
+ abstract public void setCreatedBy(String createdBy);
+ }
+
+ /**
+ * Simple default consumer that sets the fields
+ *
+ * @author Julien Le Dem
+ *
+ */
+ public static final class DefaultFileMetaDataConsumer extends FileMetaDataConsumer {
+ private final FileMetaData md;
+
+ public DefaultFileMetaDataConsumer(FileMetaData md) {
+ this.md = md;
+ }
+
+ @Override
+ public void setVersion(int version) {
+ md.setVersion(version);
+ }
+
+ @Override
+ public void setSchema(List<SchemaElement> schema) {
+ md.setSchema(schema);
+ }
+
+ @Override
+ public void setNumRows(long numRows) {
+ md.setNum_rows(numRows);
+ }
+
+ @Override
+ public void setCreatedBy(String createdBy) {
+ md.setCreated_by(createdBy);
+ }
+
+ @Override
+ public void addRowGroup(RowGroup rowGroup) {
+ md.addToRow_groups(rowGroup);
+ }
+
+ @Override
+ public void addKeyValueMetaData(KeyValue kv) {
+ md.addToKey_value_metadata(kv);
+ }
+ }
+
+ public static void readFileMetaData(InputStream from, FileMetaDataConsumer consumer) throws IOException {
+ readFileMetaData(from, consumer, false);
+ }
+
+ public static void readFileMetaData(InputStream from, final FileMetaDataConsumer consumer, boolean skipRowGroups) throws IOException {
+ try {
+ DelegatingFieldConsumer eventConsumer = fieldConsumer()
+ .onField(VERSION, new I32Consumer() {
+ @Override
+ public void consume(int value) {
+ consumer.setVersion(value);
+ }
+ }).onField(SCHEMA, listOf(SchemaElement.class, new Consumer<List<SchemaElement>>() {
+ @Override
+ public void consume(List<SchemaElement> schema) {
+ consumer.setSchema(schema);
+ }
+ })).onField(NUM_ROWS, new I64Consumer() {
+ @Override
+ public void consume(long value) {
+ consumer.setNumRows(value);
+ }
+ }).onField(KEY_VALUE_METADATA, listElementsOf(struct(KeyValue.class, new Consumer<KeyValue>() {
+ @Override
+ public void consume(KeyValue kv) {
+ consumer.addKeyValueMetaData(kv);
+ }
+ }))).onField(CREATED_BY, new StringConsumer() {
+ @Override
+ public void consume(String value) {
+ consumer.setCreatedBy(value);
+ }
+ });
+ if (!skipRowGroups) {
+ eventConsumer = eventConsumer.onField(ROW_GROUPS, listElementsOf(struct(RowGroup.class, new Consumer<RowGroup>() {
+ @Override
+ public void consume(RowGroup rowGroup) {
+ consumer.addRowGroup(rowGroup);
+ }
+ })));
+ }
+ new EventBasedThriftReader(protocol(from)).readStruct(eventConsumer);
+
+ } catch (TException e) {
+ throw new IOException("can not read FileMetaData: " + e.getMessage(), e);
+ }
+ }
+
+ private static TProtocol protocol(OutputStream to) {
+ return protocol(new TIOStreamTransport(to));
+ }
+
+ private static TProtocol protocol(InputStream from) {
+ return protocol(new TIOStreamTransport(from));
+ }
+
+ private static InterningProtocol protocol(TIOStreamTransport t) {
+ return new InterningProtocol(new TCompactProtocol(t));
+ }
+
+ private static <T extends TBase<?,?>> T read(InputStream from, T tbase) throws IOException {
+ try {
+ tbase.read(protocol(from));
+ return tbase;
+ } catch (TException e) {
+ throw new IOException("can not read " + tbase.getClass() + ": " + e.getMessage(), e);
+ }
+ }
+
+ private static void write(TBase<?, ?> tbase, OutputStream to) throws IOException {
+ try {
+ tbase.write(protocol(to));
+ } catch (TException e) {
+ throw new IOException("can not write " + tbase, e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/blob/af1e5b83/src/main/java/org/apache/parquet/format/event/Consumers.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/parquet/format/event/Consumers.java b/src/main/java/org/apache/parquet/format/event/Consumers.java
new file mode 100644
index 0000000..ea61d63
--- /dev/null
+++ b/src/main/java/org/apache/parquet/format/event/Consumers.java
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.parquet.format.event;
+
+import static java.util.Collections.unmodifiableMap;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.thrift.TBase;
+import org.apache.thrift.TException;
+import org.apache.thrift.TFieldIdEnum;
+import org.apache.thrift.protocol.TList;
+import org.apache.thrift.protocol.TProtocol;
+import org.apache.thrift.protocol.TProtocolUtil;
+
+import org.apache.parquet.format.event.Consumers.Consumer;
+import org.apache.parquet.format.event.TypedConsumer.BoolConsumer;
+import org.apache.parquet.format.event.TypedConsumer.ListConsumer;
+import org.apache.parquet.format.event.TypedConsumer.StructConsumer;
+
+/**
+ * Entry point for reading thrift in a streaming fashion
+ *
+ * @author Julien Le Dem
+ *
+ */
+public class Consumers {
+
+ /**
+ * To consume objects coming from a DelegatingFieldConsumer
+ * @author Julien Le Dem
+ *
+ * @param <T> the type of consumed objects
+ */
+ public static interface Consumer<T> {
+ void consume(T t);
+ }
+
+ /**
+ * Delegates reading the field to TypedConsumers.
+ * There is one TypedConsumer per thrift type.
+ * use {@link DelegatingFieldConsumer#onField(TFieldIdEnum, BoolConsumer)} et al. to consume specific thrift fields.
+ * @see Consumers#fieldConsumer()
+ * @author Julien Le Dem
+ *
+ */
+ public static class DelegatingFieldConsumer implements FieldConsumer {
+
+ private final Map<Short, TypedConsumer> contexts;
+ private final FieldConsumer defaultFieldEventConsumer;
+
+ private DelegatingFieldConsumer(FieldConsumer defaultFieldEventConsumer, Map<Short, TypedConsumer> contexts) {
+ this.defaultFieldEventConsumer = defaultFieldEventConsumer;
+ this.contexts = unmodifiableMap(contexts);
+ }
+
+ private DelegatingFieldConsumer() {
+ this(new SkippingFieldConsumer());
+ }
+
+ private DelegatingFieldConsumer(FieldConsumer defaultFieldEventConsumer) {
+ this(defaultFieldEventConsumer, Collections.<Short, TypedConsumer>emptyMap());
+ }
+
+ public DelegatingFieldConsumer onField(TFieldIdEnum e, TypedConsumer typedConsumer) {
+ Map<Short, TypedConsumer> newContexts = new HashMap<Short, TypedConsumer>(contexts);
+ newContexts.put(e.getThriftFieldId(), typedConsumer);
+ return new DelegatingFieldConsumer(defaultFieldEventConsumer, newContexts);
+ }
+
+ @Override
+ public void consumeField(
+ TProtocol protocol, EventBasedThriftReader reader,
+ short id, byte type) throws TException {
+ TypedConsumer delegate = contexts.get(id);
+ if (delegate != null) {
+ delegate.read(protocol, reader, type);
+ } else {
+ defaultFieldEventConsumer.consumeField(protocol, reader, id, type);
+ }
+ }
+ }
+
+ /**
+ * call onField on the resulting DelegatingFieldConsumer to handle individual fields
+ * @return a new DelegatingFieldConsumer
+ */
+ public static DelegatingFieldConsumer fieldConsumer() {
+ return new DelegatingFieldConsumer();
+ }
+
+ /**
+ * To consume a list of elements
+ * @param c the type of the list content
+ * @param consumer the consumer that will receive the list
+ * @return a ListConsumer that can be passed to the DelegatingFieldConsumer
+ */
+ public static <T extends TBase<T,? extends TFieldIdEnum>> ListConsumer listOf(Class<T> c, final Consumer<List<T>> consumer) {
+ class ListConsumer implements Consumer<T> {
+ List<T> list;
+ @Override
+ public void consume(T t) {
+ list.add(t);
+ }
+ }
+ final ListConsumer co = new ListConsumer();
+ return new DelegatingListElementsConsumer(struct(c, co)) {
+ @Override
+ public void consumeList(TProtocol protocol,
+ EventBasedThriftReader reader, TList tList) throws TException {
+ co.list = new ArrayList<T>();
+ super.consumeList(protocol, reader, tList);
+ consumer.consume(co.list);
+ }
+ };
+ }
+
+ /**
+ * To consume list elements one by one
+ * @param consumer the consumer that will read the elements
+ * @return a ListConsumer that can be passed to the DelegatingFieldConsumer
+ */
+ public static ListConsumer listElementsOf(TypedConsumer consumer) {
+ return new DelegatingListElementsConsumer(consumer);
+ }
+
+ public static <T extends TBase<T,? extends TFieldIdEnum>> StructConsumer struct(final Class<T> c, final Consumer<T> consumer) {
+ return new TBaseStructConsumer<T>(c, consumer);
+ }
+}
+
+class SkippingFieldConsumer implements FieldConsumer {
+ @Override
+ public void consumeField(TProtocol protocol, EventBasedThriftReader reader, short id, byte type) throws TException {
+ TProtocolUtil.skip(protocol, type);
+ }
+}
+
+class DelegatingListElementsConsumer extends ListConsumer {
+
+ private TypedConsumer elementConsumer;
+
+ protected DelegatingListElementsConsumer(TypedConsumer consumer) {
+ this.elementConsumer = consumer;
+ }
+
+ @Override
+ public void consumeElement(TProtocol protocol, EventBasedThriftReader reader, byte elemType) throws TException {
+ elementConsumer.read(protocol, reader, elemType);
+ }
+}
+class TBaseStructConsumer<T extends TBase<T, ? extends TFieldIdEnum>> extends StructConsumer {
+
+ private final Class<T> c;
+ private Consumer<T> consumer;
+
+ public TBaseStructConsumer(Class<T> c, Consumer<T> consumer) {
+ this.c = c;
+ this.consumer = consumer;
+ }
+
+ @Override
+ public void consumeStruct(TProtocol protocol, EventBasedThriftReader reader) throws TException {
+ T o = newObject();
+ o.read(protocol);
+ consumer.consume(o);
+ }
+
+ protected T newObject() {
+ try {
+ return c.newInstance();
+ } catch (InstantiationException e) {
+ throw new RuntimeException(c.getName(), e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(c.getName(), e);
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/blob/af1e5b83/src/main/java/org/apache/parquet/format/event/EventBasedThriftReader.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/parquet/format/event/EventBasedThriftReader.java b/src/main/java/org/apache/parquet/format/event/EventBasedThriftReader.java
new file mode 100644
index 0000000..e88432f
--- /dev/null
+++ b/src/main/java/org/apache/parquet/format/event/EventBasedThriftReader.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.parquet.format.event;
+
+import org.apache.thrift.TException;
+import org.apache.thrift.protocol.TField;
+import org.apache.thrift.protocol.TList;
+import org.apache.thrift.protocol.TMap;
+import org.apache.thrift.protocol.TProtocol;
+import org.apache.thrift.protocol.TSet;
+import org.apache.thrift.protocol.TType;
+
+import org.apache.parquet.format.event.TypedConsumer.ListConsumer;
+import org.apache.parquet.format.event.TypedConsumer.MapConsumer;
+import org.apache.parquet.format.event.TypedConsumer.SetConsumer;
+
+/**
+ * Event based reader for Thrift
+ *
+ * @author Julien Le Dem
+ *
+ */
+public final class EventBasedThriftReader {
+
+ private final TProtocol protocol;
+
+ /**
+ * @param protocol the protocol to read from
+ */
+ public EventBasedThriftReader(TProtocol protocol) {
+ this.protocol = protocol;
+ }
+
+ /**
+ * reads a Struct from the underlying protocol and passes the field events to the FieldConsumer
+ * @param c the field consumer
+ * @throws TException
+ */
+ public void readStruct(FieldConsumer c) throws TException {
+ protocol.readStructBegin();
+ readStructContent(c);
+ protocol.readStructEnd();
+ }
+
+ /**
+ * reads the content of a struct (fields) from the underlying protocol and passes the events to c
+ * @param c the field consumer
+ * @throws TException
+ */
+ public void readStructContent(FieldConsumer c) throws TException {
+ TField field;
+ while (true) {
+ field = protocol.readFieldBegin();
+ if (field.type == TType.STOP) {
+ break;
+ }
+ c.consumeField(protocol, this, field.id, field.type);
+ }
+ }
+
+ /**
+ * reads the set content (elements) from the underlying protocol and passes the events to the set event consumer
+ * @param eventConsumer the consumer
+ * @param tSet the set descriptor
+ * @throws TException
+ */
+ public void readSetContent(SetConsumer eventConsumer, TSet tSet)
+ throws TException {
+ for (int i = 0; i < tSet.size; i++) {
+ eventConsumer.consumeElement(protocol, this, tSet.elemType);
+ }
+ }
+
+ /**
+ * reads the map content (key values) from the underlying protocol and passes the events to the map event consumer
+ * @param eventConsumer the consumer
+ * @param tMap the map descriptor
+ * @throws TException
+ */
+ public void readMapContent(MapConsumer eventConsumer, TMap tMap)
+ throws TException {
+ for (int i = 0; i < tMap.size; i++) {
+ eventConsumer.consumeEntry(protocol, this, tMap.keyType, tMap.valueType);
+ }
+ }
+
+ /**
+ * reads a key-value pair
+ * @param keyType the type of the key
+ * @param keyConsumer the consumer for the key
+ * @param valueType the type of the value
+ * @param valueConsumer the consumer for the value
+ * @throws TException
+ */
+ public void readMapEntry(byte keyType, TypedConsumer keyConsumer, byte valueType, TypedConsumer valueConsumer)
+ throws TException {
+ keyConsumer.read(protocol, this, keyType);
+ valueConsumer.read(protocol, this, valueType);
+ }
+
+ /**
+ * reads the list content (elements) from the underlying protocol and passes the events to the list event consumer
+ * @param eventConsumer the consumer
+ * @param tList the list descriptor
+ * @throws TException
+ */
+ public void readListContent(ListConsumer eventConsumer, TList tList)
+ throws TException {
+ for (int i = 0; i < tList.size; i++) {
+ eventConsumer.consumeElement(protocol, this, tList.elemType);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/blob/af1e5b83/src/main/java/org/apache/parquet/format/event/FieldConsumer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/parquet/format/event/FieldConsumer.java b/src/main/java/org/apache/parquet/format/event/FieldConsumer.java
new file mode 100644
index 0000000..2be4d6e
--- /dev/null
+++ b/src/main/java/org/apache/parquet/format/event/FieldConsumer.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.parquet.format.event;
+
+import org.apache.thrift.TException;
+import org.apache.thrift.protocol.TProtocol;
+
+/**
+ * To receive Thrift field events
+ *
+ * @author Julien Le Dem
+ *
+ */
+public interface FieldConsumer {
+
+ /**
+ * called by the EventBasedThriftReader when reading a field from a Struct
+ * @param protocol the underlying protocol
+ * @param eventBasedThriftReader the reader to delegate to further calls.
+ * @param id the id of the field
+ * @param type the type of the field
+ * @return the typed consumer to pass the value to
+ * @throws TException
+ */
+ public void consumeField(TProtocol protocol, EventBasedThriftReader eventBasedThriftReader, short id, byte type) throws TException;
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/blob/af1e5b83/src/main/java/org/apache/parquet/format/event/TypedConsumer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/parquet/format/event/TypedConsumer.java b/src/main/java/org/apache/parquet/format/event/TypedConsumer.java
new file mode 100644
index 0000000..1d10ad6
--- /dev/null
+++ b/src/main/java/org/apache/parquet/format/event/TypedConsumer.java
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.parquet.format.event;
+
+import static org.apache.thrift.protocol.TType.BOOL;
+import static org.apache.thrift.protocol.TType.BYTE;
+import static org.apache.thrift.protocol.TType.DOUBLE;
+import static org.apache.thrift.protocol.TType.I16;
+import static org.apache.thrift.protocol.TType.I32;
+import static org.apache.thrift.protocol.TType.I64;
+import static org.apache.thrift.protocol.TType.LIST;
+import static org.apache.thrift.protocol.TType.MAP;
+import static org.apache.thrift.protocol.TType.SET;
+import static org.apache.thrift.protocol.TType.STRING;
+import static org.apache.thrift.protocol.TType.STRUCT;
+
+import org.apache.thrift.TException;
+import org.apache.thrift.protocol.TList;
+import org.apache.thrift.protocol.TMap;
+import org.apache.thrift.protocol.TProtocol;
+import org.apache.thrift.protocol.TSet;
+
+/**
+ * receive thrift events of a given type
+ *
+ * @author Julien Le Dem
+ *
+ */
+abstract public class TypedConsumer {
+
+ abstract public static class DoubleConsumer extends TypedConsumer {
+ protected DoubleConsumer() { super(DOUBLE); }
+ @Override
+ final void read(TProtocol protocol, EventBasedThriftReader reader) throws TException {
+ this.consume(protocol.readDouble());
+ }
+ abstract public void consume(double value);
+ }
+
+ abstract public static class ByteConsumer extends TypedConsumer {
+ protected ByteConsumer() { super(BYTE); }
+ @Override
+ final void read(TProtocol protocol, EventBasedThriftReader reader) throws TException {
+ this.consume(protocol.readByte());
+ }
+ abstract public void consume(byte value);
+ }
+
+ abstract public static class BoolConsumer extends TypedConsumer {
+ protected BoolConsumer() { super(BOOL); }
+ @Override
+ final void read(TProtocol protocol, EventBasedThriftReader reader) throws TException {
+ this.consume(protocol.readBool());
+ }
+ abstract public void consume(boolean value);
+ }
+
+ abstract public static class I32Consumer extends TypedConsumer {
+ protected I32Consumer() { super(I32); }
+ @Override
+ final void read(TProtocol protocol, EventBasedThriftReader reader) throws TException {
+ this.consume(protocol.readI32());
+ }
+ abstract public void consume(int value);
+ }
+
+ abstract public static class I64Consumer extends TypedConsumer {
+ protected I64Consumer() { super(I64); }
+ final void read(TProtocol protocol, EventBasedThriftReader reader) throws TException {
+ this.consume(protocol.readI64());
+ }
+ abstract public void consume(long value);
+ }
+
+ abstract public static class I16Consumer extends TypedConsumer {
+ protected I16Consumer() { super(I16); }
+ @Override
+ final void read(TProtocol protocol, EventBasedThriftReader reader) throws TException {
+ this.consume(protocol.readI16());
+ }
+ abstract public void consume(short value);
+ }
+
+ abstract public static class StringConsumer extends TypedConsumer {
+ protected StringConsumer() { super(STRING); }
+ @Override
+ final void read(TProtocol protocol, EventBasedThriftReader reader) throws TException {
+ this.consume(protocol.readString());
+ }
+ abstract public void consume(String value);
+ }
+
+ abstract public static class StructConsumer extends TypedConsumer {
+ protected StructConsumer() { super(STRUCT); }
+ @Override
+ final void read(TProtocol protocol, EventBasedThriftReader reader) throws TException {
+ this.consumeStruct(protocol, reader);
+ }
+ /**
+ * can either delegate to the reader or read the struct from the protocol
+ * reader.readStruct(fieldConsumer);
+ * @param protocol the underlying protocol
+ * @param reader the reader to delegate to
+ * @throws TException
+ */
+ abstract public void consumeStruct(TProtocol protocol, EventBasedThriftReader reader) throws TException;
+ }
+
+ abstract public static class ListConsumer extends TypedConsumer {
+ protected ListConsumer() { super(LIST); }
+ @Override
+ final void read(TProtocol protocol, EventBasedThriftReader reader) throws TException {
+ this.consumeList(protocol, reader, protocol.readListBegin());
+ protocol.readListEnd();
+ }
+ public void consumeList(TProtocol protocol, EventBasedThriftReader reader, TList tList) throws TException {
+ reader.readListContent(this, tList);
+ }
+ /**
+ * can either delegate to the reader or read the element from the protocol
+ * @param protocol the underlying protocol
+ * @param reader the reader to delegate to
+ * @throws TException
+ */
+ abstract public void consumeElement(TProtocol protocol, EventBasedThriftReader reader, byte elemType) throws TException;
+ }
+
+ abstract public static class SetConsumer extends TypedConsumer {
+ protected SetConsumer() { super(SET); }
+ @Override
+ final void read(TProtocol protocol, EventBasedThriftReader reader) throws TException {
+ this.consumeSet(protocol, reader, protocol.readSetBegin());
+ protocol.readSetEnd();
+ }
+ public void consumeSet(TProtocol protocol, EventBasedThriftReader reader, TSet tSet) throws TException {
+ reader.readSetContent(this, tSet);
+ }
+ /**
+ * can either delegate to the reader or read the set from the protocol
+ * @param protocol the underlying protocol
+ * @param reader the reader to delegate to
+ * @throws TException
+ */
+ abstract public void consumeElement(
+ TProtocol protocol, EventBasedThriftReader reader,
+ byte elemType) throws TException;
+ }
+
+ abstract public static class MapConsumer extends TypedConsumer {
+ protected MapConsumer() { super(MAP); }
+ @Override
+ final void read(TProtocol protocol, EventBasedThriftReader reader)
+ throws TException {
+ this.consumeMap(protocol, reader , protocol.readMapBegin());
+ protocol.readMapEnd();
+ }
+ public void consumeMap(TProtocol protocol, EventBasedThriftReader reader, TMap tMap) throws TException {
+ reader.readMapContent(this, tMap);
+ }
+ /**
+ * can either delegate to the reader or read the map entry from the protocol
+ * @param protocol the underlying protocol
+ * @param reader the reader to delegate to
+ * @throws TException
+ */
+ abstract public void consumeEntry(
+ TProtocol protocol, EventBasedThriftReader reader,
+ byte keyType, byte valueType) throws TException;
+ }
+
+ public final byte type;
+
+ private TypedConsumer(byte type) {
+ this.type = type;
+ }
+
+ final public void read(TProtocol protocol, EventBasedThriftReader reader, byte type) throws TException {
+ if (this.type != type) {
+ throw new TException(
+ "Incorrect type in stream. "
+ + "Expected " + this.type
+ + " but got " + type);
+ }
+ this.read(protocol, reader);
+ }
+
+ abstract void read(TProtocol protocol, EventBasedThriftReader reader) throws TException;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/blob/af1e5b83/src/main/java/parquet/format/InterningProtocol.java
----------------------------------------------------------------------
diff --git a/src/main/java/parquet/format/InterningProtocol.java b/src/main/java/parquet/format/InterningProtocol.java
deleted file mode 100644
index 9803c72..0000000
--- a/src/main/java/parquet/format/InterningProtocol.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package parquet.format;
-
-import java.nio.ByteBuffer;
-
-import org.apache.thrift.TException;
-import org.apache.thrift.protocol.TField;
-import org.apache.thrift.protocol.TList;
-import org.apache.thrift.protocol.TMap;
-import org.apache.thrift.protocol.TMessage;
-import org.apache.thrift.protocol.TProtocol;
-import org.apache.thrift.protocol.TSet;
-import org.apache.thrift.protocol.TStruct;
-import org.apache.thrift.transport.TTransport;
-
-/**
- * TProtocol that interns the strings.
- *
- * @author Julien Le Dem
- *
- */
-public class InterningProtocol extends TProtocol {
-
- private final TProtocol delegate;
-
- public InterningProtocol(TProtocol delegate) {
- super(delegate.getTransport());
- this.delegate = delegate;
- }
-
- public TTransport getTransport() {
- return delegate.getTransport();
- }
-
- public void writeMessageBegin(TMessage message) throws TException {
- delegate.writeMessageBegin(message);
- }
-
- public void writeMessageEnd() throws TException {
- delegate.writeMessageEnd();
- }
-
- public int hashCode() {
- return delegate.hashCode();
- }
-
- public void writeStructBegin(TStruct struct) throws TException {
- delegate.writeStructBegin(struct);
- }
-
- public void writeStructEnd() throws TException {
- delegate.writeStructEnd();
- }
-
- public void writeFieldBegin(TField field) throws TException {
- delegate.writeFieldBegin(field);
- }
-
- public void writeFieldEnd() throws TException {
- delegate.writeFieldEnd();
- }
-
- public void writeFieldStop() throws TException {
- delegate.writeFieldStop();
- }
-
- public void writeMapBegin(TMap map) throws TException {
- delegate.writeMapBegin(map);
- }
-
- public void writeMapEnd() throws TException {
- delegate.writeMapEnd();
- }
-
- public void writeListBegin(TList list) throws TException {
- delegate.writeListBegin(list);
- }
-
- public void writeListEnd() throws TException {
- delegate.writeListEnd();
- }
-
- public void writeSetBegin(TSet set) throws TException {
- delegate.writeSetBegin(set);
- }
-
- public void writeSetEnd() throws TException {
- delegate.writeSetEnd();
- }
-
- public void writeBool(boolean b) throws TException {
- delegate.writeBool(b);
- }
-
- public void writeByte(byte b) throws TException {
- delegate.writeByte(b);
- }
-
- public void writeI16(short i16) throws TException {
- delegate.writeI16(i16);
- }
-
- public void writeI32(int i32) throws TException {
- delegate.writeI32(i32);
- }
-
- public void writeI64(long i64) throws TException {
- delegate.writeI64(i64);
- }
-
- public void writeDouble(double dub) throws TException {
- delegate.writeDouble(dub);
- }
-
- public void writeString(String str) throws TException {
- delegate.writeString(str);
- }
-
- public void writeBinary(ByteBuffer buf) throws TException {
- delegate.writeBinary(buf);
- }
-
- public TMessage readMessageBegin() throws TException {
- return delegate.readMessageBegin();
- }
-
- public void readMessageEnd() throws TException {
- delegate.readMessageEnd();
- }
-
- public TStruct readStructBegin() throws TException {
- return delegate.readStructBegin();
- }
-
- public void readStructEnd() throws TException {
- delegate.readStructEnd();
- }
-
- public TField readFieldBegin() throws TException {
- return delegate.readFieldBegin();
- }
-
- public void readFieldEnd() throws TException {
- delegate.readFieldEnd();
- }
-
- public TMap readMapBegin() throws TException {
- return delegate.readMapBegin();
- }
-
- public void readMapEnd() throws TException {
- delegate.readMapEnd();
- }
-
- public TList readListBegin() throws TException {
- return delegate.readListBegin();
- }
-
- public void readListEnd() throws TException {
- delegate.readListEnd();
- }
-
- public TSet readSetBegin() throws TException {
- return delegate.readSetBegin();
- }
-
- public void readSetEnd() throws TException {
- delegate.readSetEnd();
- }
-
- public boolean equals(Object obj) {
- return delegate.equals(obj);
- }
-
- public boolean readBool() throws TException {
- return delegate.readBool();
- }
-
- public byte readByte() throws TException {
- return delegate.readByte();
- }
-
- public short readI16() throws TException {
- return delegate.readI16();
- }
-
- public int readI32() throws TException {
- return delegate.readI32();
- }
-
- public long readI64() throws TException {
- return delegate.readI64();
- }
-
- public double readDouble() throws TException {
- return delegate.readDouble();
- }
-
- public String readString() throws TException {
- // this is where we intern the strings
- return delegate.readString().intern();
- }
-
- public ByteBuffer readBinary() throws TException {
- return delegate.readBinary();
- }
-
- public void reset() {
- delegate.reset();
- }
-
- public String toString() {
- return delegate.toString();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/blob/af1e5b83/src/main/java/parquet/format/Util.java
----------------------------------------------------------------------
diff --git a/src/main/java/parquet/format/Util.java b/src/main/java/parquet/format/Util.java
deleted file mode 100644
index bad90ab..0000000
--- a/src/main/java/parquet/format/Util.java
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package parquet.format;
-
-import static parquet.format.FileMetaData._Fields.CREATED_BY;
-import static parquet.format.FileMetaData._Fields.KEY_VALUE_METADATA;
-import static parquet.format.FileMetaData._Fields.NUM_ROWS;
-import static parquet.format.FileMetaData._Fields.ROW_GROUPS;
-import static parquet.format.FileMetaData._Fields.SCHEMA;
-import static parquet.format.FileMetaData._Fields.VERSION;
-import static parquet.format.event.Consumers.fieldConsumer;
-import static parquet.format.event.Consumers.listElementsOf;
-import static parquet.format.event.Consumers.listOf;
-import static parquet.format.event.Consumers.struct;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.List;
-
-import org.apache.thrift.TBase;
-import org.apache.thrift.TException;
-import org.apache.thrift.protocol.TCompactProtocol;
-import org.apache.thrift.protocol.TProtocol;
-import org.apache.thrift.transport.TIOStreamTransport;
-
-import parquet.format.event.Consumers.Consumer;
-import parquet.format.event.Consumers.DelegatingFieldConsumer;
-import parquet.format.event.EventBasedThriftReader;
-import parquet.format.event.TypedConsumer.I32Consumer;
-import parquet.format.event.TypedConsumer.I64Consumer;
-import parquet.format.event.TypedConsumer.StringConsumer;
-
-/**
- * Utility to read/write metadata
- * We use the TCompactProtocol to serialize metadata
- *
- * @author Julien Le Dem
- *
- */
-public class Util {
-
- public static void writePageHeader(PageHeader pageHeader, OutputStream to) throws IOException {
- write(pageHeader, to);
- }
-
- public static PageHeader readPageHeader(InputStream from) throws IOException {
- return read(from, new PageHeader());
- }
-
- public static void writeFileMetaData(parquet.format.FileMetaData fileMetadata, OutputStream to) throws IOException {
- write(fileMetadata, to);
- }
-
- public static FileMetaData readFileMetaData(InputStream from) throws IOException {
- return read(from, new FileMetaData());
- }
- /**
- * reads the meta data from the stream
- * @param from the stream to read the metadata from
- * @param skipRowGroups whether row groups should be skipped
- * @return the resulting metadata
- * @throws IOException
- */
- public static FileMetaData readFileMetaData(InputStream from, boolean skipRowGroups) throws IOException {
- FileMetaData md = new FileMetaData();
- if (skipRowGroups) {
- readFileMetaData(from, new DefaultFileMetaDataConsumer(md), skipRowGroups);
- } else {
- read(from, md);
- }
- return md;
- }
-
- /**
- * To read metadata in a streaming fashion.
- *
- * @author Julien Le Dem
- *
- */
- public static abstract class FileMetaDataConsumer {
- abstract public void setVersion(int version);
- abstract public void setSchema(List<SchemaElement> schema);
- abstract public void setNumRows(long numRows);
- abstract public void addRowGroup(RowGroup rowGroup);
- abstract public void addKeyValueMetaData(KeyValue kv);
- abstract public void setCreatedBy(String createdBy);
- }
-
- /**
- * Simple default consumer that sets the fields
- *
- * @author Julien Le Dem
- *
- */
- public static final class DefaultFileMetaDataConsumer extends FileMetaDataConsumer {
- private final FileMetaData md;
-
- public DefaultFileMetaDataConsumer(FileMetaData md) {
- this.md = md;
- }
-
- @Override
- public void setVersion(int version) {
- md.setVersion(version);
- }
-
- @Override
- public void setSchema(List<SchemaElement> schema) {
- md.setSchema(schema);
- }
-
- @Override
- public void setNumRows(long numRows) {
- md.setNum_rows(numRows);
- }
-
- @Override
- public void setCreatedBy(String createdBy) {
- md.setCreated_by(createdBy);
- }
-
- @Override
- public void addRowGroup(RowGroup rowGroup) {
- md.addToRow_groups(rowGroup);
- }
-
- @Override
- public void addKeyValueMetaData(KeyValue kv) {
- md.addToKey_value_metadata(kv);
- }
- }
-
- public static void readFileMetaData(InputStream from, FileMetaDataConsumer consumer) throws IOException {
- readFileMetaData(from, consumer, false);
- }
-
- public static void readFileMetaData(InputStream from, final FileMetaDataConsumer consumer, boolean skipRowGroups) throws IOException {
- try {
- DelegatingFieldConsumer eventConsumer = fieldConsumer()
- .onField(VERSION, new I32Consumer() {
- @Override
- public void consume(int value) {
- consumer.setVersion(value);
- }
- }).onField(SCHEMA, listOf(SchemaElement.class, new Consumer<List<SchemaElement>>() {
- @Override
- public void consume(List<SchemaElement> schema) {
- consumer.setSchema(schema);
- }
- })).onField(NUM_ROWS, new I64Consumer() {
- @Override
- public void consume(long value) {
- consumer.setNumRows(value);
- }
- }).onField(KEY_VALUE_METADATA, listElementsOf(struct(KeyValue.class, new Consumer<KeyValue>() {
- @Override
- public void consume(KeyValue kv) {
- consumer.addKeyValueMetaData(kv);
- }
- }))).onField(CREATED_BY, new StringConsumer() {
- @Override
- public void consume(String value) {
- consumer.setCreatedBy(value);
- }
- });
- if (!skipRowGroups) {
- eventConsumer = eventConsumer.onField(ROW_GROUPS, listElementsOf(struct(RowGroup.class, new Consumer<RowGroup>() {
- @Override
- public void consume(RowGroup rowGroup) {
- consumer.addRowGroup(rowGroup);
- }
- })));
- }
- new EventBasedThriftReader(protocol(from)).readStruct(eventConsumer);
-
- } catch (TException e) {
- throw new IOException("can not read FileMetaData: " + e.getMessage(), e);
- }
- }
-
- private static TProtocol protocol(OutputStream to) {
- return protocol(new TIOStreamTransport(to));
- }
-
- private static TProtocol protocol(InputStream from) {
- return protocol(new TIOStreamTransport(from));
- }
-
- private static InterningProtocol protocol(TIOStreamTransport t) {
- return new InterningProtocol(new TCompactProtocol(t));
- }
-
- private static <T extends TBase<?,?>> T read(InputStream from, T tbase) throws IOException {
- try {
- tbase.read(protocol(from));
- return tbase;
- } catch (TException e) {
- throw new IOException("can not read " + tbase.getClass() + ": " + e.getMessage(), e);
- }
- }
-
- private static void write(TBase<?, ?> tbase, OutputStream to) throws IOException {
- try {
- tbase.write(protocol(to));
- } catch (TException e) {
- throw new IOException("can not write " + tbase, e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/blob/af1e5b83/src/main/java/parquet/format/event/Consumers.java
----------------------------------------------------------------------
diff --git a/src/main/java/parquet/format/event/Consumers.java b/src/main/java/parquet/format/event/Consumers.java
deleted file mode 100644
index 5ee54fe..0000000
--- a/src/main/java/parquet/format/event/Consumers.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package parquet.format.event;
-
-import static java.util.Collections.unmodifiableMap;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.thrift.TBase;
-import org.apache.thrift.TException;
-import org.apache.thrift.TFieldIdEnum;
-import org.apache.thrift.protocol.TList;
-import org.apache.thrift.protocol.TProtocol;
-import org.apache.thrift.protocol.TProtocolUtil;
-
-import parquet.format.event.Consumers.Consumer;
-import parquet.format.event.TypedConsumer.BoolConsumer;
-import parquet.format.event.TypedConsumer.ListConsumer;
-import parquet.format.event.TypedConsumer.StructConsumer;
-
-/**
- * Entry point for reading thrift in a streaming fashion
- *
- * @author Julien Le Dem
- *
- */
-public class Consumers {
-
- /**
- * To consume objects coming from a DelegatingFieldConsumer
- * @author Julien Le Dem
- *
- * @param <T> the type of consumed objects
- */
- public static interface Consumer<T> {
- void consume(T t);
- }
-
- /**
- * Delegates reading the field to TypedConsumers.
- * There is one TypedConsumer per thrift type.
- * use {@link DelegatingFieldConsumer#onField(TFieldIdEnum, BoolConsumer)} et al. to consume specific thrift fields.
- * @see Consumers#fieldConsumer()
- * @author Julien Le Dem
- *
- */
- public static class DelegatingFieldConsumer implements FieldConsumer {
-
- private final Map<Short, TypedConsumer> contexts;
- private final FieldConsumer defaultFieldEventConsumer;
-
- private DelegatingFieldConsumer(FieldConsumer defaultFieldEventConsumer, Map<Short, TypedConsumer> contexts) {
- this.defaultFieldEventConsumer = defaultFieldEventConsumer;
- this.contexts = unmodifiableMap(contexts);
- }
-
- private DelegatingFieldConsumer() {
- this(new SkippingFieldConsumer());
- }
-
- private DelegatingFieldConsumer(FieldConsumer defaultFieldEventConsumer) {
- this(defaultFieldEventConsumer, Collections.<Short, TypedConsumer>emptyMap());
- }
-
- public DelegatingFieldConsumer onField(TFieldIdEnum e, TypedConsumer typedConsumer) {
- Map<Short, TypedConsumer> newContexts = new HashMap<Short, TypedConsumer>(contexts);
- newContexts.put(e.getThriftFieldId(), typedConsumer);
- return new DelegatingFieldConsumer(defaultFieldEventConsumer, newContexts);
- }
-
- @Override
- public void consumeField(
- TProtocol protocol, EventBasedThriftReader reader,
- short id, byte type) throws TException {
- TypedConsumer delegate = contexts.get(id);
- if (delegate != null) {
- delegate.read(protocol, reader, type);
- } else {
- defaultFieldEventConsumer.consumeField(protocol, reader, id, type);
- }
- }
- }
-
- /**
- * call onField on the resulting DelegatingFieldConsumer to handle individual fields
- * @return a new DelegatingFieldConsumer
- */
- public static DelegatingFieldConsumer fieldConsumer() {
- return new DelegatingFieldConsumer();
- }
-
- /**
- * To consume a list of elements
- * @param c the type of the list content
- * @param consumer the consumer that will receive the list
- * @return a ListConsumer that can be passed to the DelegatingFieldConsumer
- */
- public static <T extends TBase<T,? extends TFieldIdEnum>> ListConsumer listOf(Class<T> c, final Consumer<List<T>> consumer) {
- class ListConsumer implements Consumer<T> {
- List<T> list;
- @Override
- public void consume(T t) {
- list.add(t);
- }
- }
- final ListConsumer co = new ListConsumer();
- return new DelegatingListElementsConsumer(struct(c, co)) {
- @Override
- public void consumeList(TProtocol protocol,
- EventBasedThriftReader reader, TList tList) throws TException {
- co.list = new ArrayList<T>();
- super.consumeList(protocol, reader, tList);
- consumer.consume(co.list);
- }
- };
- }
-
- /**
- * To consume list elements one by one
- * @param consumer the consumer that will read the elements
- * @return a ListConsumer that can be passed to the DelegatingFieldConsumer
- */
- public static ListConsumer listElementsOf(TypedConsumer consumer) {
- return new DelegatingListElementsConsumer(consumer);
- }
-
- public static <T extends TBase<T,? extends TFieldIdEnum>> StructConsumer struct(final Class<T> c, final Consumer<T> consumer) {
- return new TBaseStructConsumer<T>(c, consumer);
- }
-}
-
-class SkippingFieldConsumer implements FieldConsumer {
- @Override
- public void consumeField(TProtocol protocol, EventBasedThriftReader reader, short id, byte type) throws TException {
- TProtocolUtil.skip(protocol, type);
- }
-}
-
-class DelegatingListElementsConsumer extends ListConsumer {
-
- private TypedConsumer elementConsumer;
-
- protected DelegatingListElementsConsumer(TypedConsumer consumer) {
- this.elementConsumer = consumer;
- }
-
- @Override
- public void consumeElement(TProtocol protocol, EventBasedThriftReader reader, byte elemType) throws TException {
- elementConsumer.read(protocol, reader, elemType);
- }
-}
-class TBaseStructConsumer<T extends TBase<T, ? extends TFieldIdEnum>> extends StructConsumer {
-
- private final Class<T> c;
- private Consumer<T> consumer;
-
- public TBaseStructConsumer(Class<T> c, Consumer<T> consumer) {
- this.c = c;
- this.consumer = consumer;
- }
-
- @Override
- public void consumeStruct(TProtocol protocol, EventBasedThriftReader reader) throws TException {
- T o = newObject();
- o.read(protocol);
- consumer.consume(o);
- }
-
- protected T newObject() {
- try {
- return c.newInstance();
- } catch (InstantiationException e) {
- throw new RuntimeException(c.getName(), e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(c.getName(), e);
- }
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/blob/af1e5b83/src/main/java/parquet/format/event/EventBasedThriftReader.java
----------------------------------------------------------------------
diff --git a/src/main/java/parquet/format/event/EventBasedThriftReader.java b/src/main/java/parquet/format/event/EventBasedThriftReader.java
deleted file mode 100644
index 9dc8158..0000000
--- a/src/main/java/parquet/format/event/EventBasedThriftReader.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package parquet.format.event;
-
-import org.apache.thrift.TException;
-import org.apache.thrift.protocol.TField;
-import org.apache.thrift.protocol.TList;
-import org.apache.thrift.protocol.TMap;
-import org.apache.thrift.protocol.TProtocol;
-import org.apache.thrift.protocol.TSet;
-import org.apache.thrift.protocol.TType;
-
-import parquet.format.event.TypedConsumer.ListConsumer;
-import parquet.format.event.TypedConsumer.MapConsumer;
-import parquet.format.event.TypedConsumer.SetConsumer;
-
-/**
- * Event based reader for Thrift
- *
- * @author Julien Le Dem
- *
- */
-public final class EventBasedThriftReader {
-
- private final TProtocol protocol;
-
- /**
- * @param protocol the protocol to read from
- */
- public EventBasedThriftReader(TProtocol protocol) {
- this.protocol = protocol;
- }
-
- /**
- * reads a Struct from the underlying protocol and passes the field events to the FieldConsumer
- * @param c the field consumer
- * @throws TException
- */
- public void readStruct(FieldConsumer c) throws TException {
- protocol.readStructBegin();
- readStructContent(c);
- protocol.readStructEnd();
- }
-
- /**
- * reads the content of a struct (fields) from the underlying protocol and passes the events to c
- * @param c the field consumer
- * @throws TException
- */
- public void readStructContent(FieldConsumer c) throws TException {
- TField field;
- while (true) {
- field = protocol.readFieldBegin();
- if (field.type == TType.STOP) {
- break;
- }
- c.consumeField(protocol, this, field.id, field.type);
- }
- }
-
- /**
- * reads the set content (elements) from the underlying protocol and passes the events to the set event consumer
- * @param eventConsumer the consumer
- * @param tSet the set descriptor
- * @throws TException
- */
- public void readSetContent(SetConsumer eventConsumer, TSet tSet)
- throws TException {
- for (int i = 0; i < tSet.size; i++) {
- eventConsumer.consumeElement(protocol, this, tSet.elemType);
- }
- }
-
- /**
- * reads the map content (key values) from the underlying protocol and passes the events to the map event consumer
- * @param eventConsumer the consumer
- * @param tMap the map descriptor
- * @throws TException
- */
- public void readMapContent(MapConsumer eventConsumer, TMap tMap)
- throws TException {
- for (int i = 0; i < tMap.size; i++) {
- eventConsumer.consumeEntry(protocol, this, tMap.keyType, tMap.valueType);
- }
- }
-
- /**
- * reads a key-value pair
- * @param keyType the type of the key
- * @param keyConsumer the consumer for the key
- * @param valueType the type of the value
- * @param valueConsumer the consumer for the value
- * @throws TException
- */
- public void readMapEntry(byte keyType, TypedConsumer keyConsumer, byte valueType, TypedConsumer valueConsumer)
- throws TException {
- keyConsumer.read(protocol, this, keyType);
- valueConsumer.read(protocol, this, valueType);
- }
-
- /**
- * reads the list content (elements) from the underlying protocol and passes the events to the list event consumer
- * @param eventConsumer the consumer
- * @param tList the list descriptor
- * @throws TException
- */
- public void readListContent(ListConsumer eventConsumer, TList tList)
- throws TException {
- for (int i = 0; i < tList.size; i++) {
- eventConsumer.consumeElement(protocol, this, tList.elemType);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/blob/af1e5b83/src/main/java/parquet/format/event/FieldConsumer.java
----------------------------------------------------------------------
diff --git a/src/main/java/parquet/format/event/FieldConsumer.java b/src/main/java/parquet/format/event/FieldConsumer.java
deleted file mode 100644
index 8cdd51b..0000000
--- a/src/main/java/parquet/format/event/FieldConsumer.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package parquet.format.event;
-
-import org.apache.thrift.TException;
-import org.apache.thrift.protocol.TProtocol;
-
-/**
- * To receive Thrift field events
- *
- * @author Julien Le Dem
- *
- */
-public interface FieldConsumer {
-
- /**
- * called by the EventBasedThriftReader when reading a field from a Struct
- * @param protocol the underlying protocol
- * @param eventBasedThriftReader the reader to delegate to further calls.
- * @param id the id of the field
- * @param type the type of the field
- * @return the typed consumer to pass the value to
- * @throws TException
- */
- public void consumeField(TProtocol protocol, EventBasedThriftReader eventBasedThriftReader, short id, byte type) throws TException;
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/blob/af1e5b83/src/main/java/parquet/format/event/TypedConsumer.java
----------------------------------------------------------------------
diff --git a/src/main/java/parquet/format/event/TypedConsumer.java b/src/main/java/parquet/format/event/TypedConsumer.java
deleted file mode 100644
index 61198c2..0000000
--- a/src/main/java/parquet/format/event/TypedConsumer.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package parquet.format.event;
-
-import static org.apache.thrift.protocol.TType.BOOL;
-import static org.apache.thrift.protocol.TType.BYTE;
-import static org.apache.thrift.protocol.TType.DOUBLE;
-import static org.apache.thrift.protocol.TType.I16;
-import static org.apache.thrift.protocol.TType.I32;
-import static org.apache.thrift.protocol.TType.I64;
-import static org.apache.thrift.protocol.TType.LIST;
-import static org.apache.thrift.protocol.TType.MAP;
-import static org.apache.thrift.protocol.TType.SET;
-import static org.apache.thrift.protocol.TType.STRING;
-import static org.apache.thrift.protocol.TType.STRUCT;
-
-import org.apache.thrift.TException;
-import org.apache.thrift.protocol.TList;
-import org.apache.thrift.protocol.TMap;
-import org.apache.thrift.protocol.TProtocol;
-import org.apache.thrift.protocol.TSet;
-
-/**
- * receive thrift events of a given type
- *
- * @author Julien Le Dem
- *
- */
-abstract public class TypedConsumer {
-
- abstract public static class DoubleConsumer extends TypedConsumer {
- protected DoubleConsumer() { super(DOUBLE); }
- @Override
- final void read(TProtocol protocol, EventBasedThriftReader reader) throws TException {
- this.consume(protocol.readDouble());
- }
- abstract public void consume(double value);
- }
-
- abstract public static class ByteConsumer extends TypedConsumer {
- protected ByteConsumer() { super(BYTE); }
- @Override
- final void read(TProtocol protocol, EventBasedThriftReader reader) throws TException {
- this.consume(protocol.readByte());
- }
- abstract public void consume(byte value);
- }
-
- abstract public static class BoolConsumer extends TypedConsumer {
- protected BoolConsumer() { super(BOOL); }
- @Override
- final void read(TProtocol protocol, EventBasedThriftReader reader) throws TException {
- this.consume(protocol.readBool());
- }
- abstract public void consume(boolean value);
- }
-
- abstract public static class I32Consumer extends TypedConsumer {
- protected I32Consumer() { super(I32); }
- @Override
- final void read(TProtocol protocol, EventBasedThriftReader reader) throws TException {
- this.consume(protocol.readI32());
- }
- abstract public void consume(int value);
- }
-
- abstract public static class I64Consumer extends TypedConsumer {
- protected I64Consumer() { super(I64); }
- final void read(TProtocol protocol, EventBasedThriftReader reader) throws TException {
- this.consume(protocol.readI64());
- }
- abstract public void consume(long value);
- }
-
- abstract public static class I16Consumer extends TypedConsumer {
- protected I16Consumer() { super(I16); }
- @Override
- final void read(TProtocol protocol, EventBasedThriftReader reader) throws TException {
- this.consume(protocol.readI16());
- }
- abstract public void consume(short value);
- }
-
- abstract public static class StringConsumer extends TypedConsumer {
- protected StringConsumer() { super(STRING); }
- @Override
- final void read(TProtocol protocol, EventBasedThriftReader reader) throws TException {
- this.consume(protocol.readString());
- }
- abstract public void consume(String value);
- }
-
- abstract public static class StructConsumer extends TypedConsumer {
- protected StructConsumer() { super(STRUCT); }
- @Override
- final void read(TProtocol protocol, EventBasedThriftReader reader) throws TException {
- this.consumeStruct(protocol, reader);
- }
- /**
- * can either delegate to the reader or read the struct from the protocol
- * reader.readStruct(fieldConsumer);
- * @param protocol the underlying protocol
- * @param reader the reader to delegate to
- * @throws TException
- */
- abstract public void consumeStruct(TProtocol protocol, EventBasedThriftReader reader) throws TException;
- }
-
- abstract public static class ListConsumer extends TypedConsumer {
- protected ListConsumer() { super(LIST); }
- @Override
- final void read(TProtocol protocol, EventBasedThriftReader reader) throws TException {
- this.consumeList(protocol, reader, protocol.readListBegin());
- protocol.readListEnd();
- }
- public void consumeList(TProtocol protocol, EventBasedThriftReader reader, TList tList) throws TException {
- reader.readListContent(this, tList);
- }
- /**
- * can either delegate to the reader or read the element from the protocol
- * @param protocol the underlying protocol
- * @param reader the reader to delegate to
- * @throws TException
- */
- abstract public void consumeElement(TProtocol protocol, EventBasedThriftReader reader, byte elemType) throws TException;
- }
-
- abstract public static class SetConsumer extends TypedConsumer {
- protected SetConsumer() { super(SET); }
- @Override
- final void read(TProtocol protocol, EventBasedThriftReader reader) throws TException {
- this.consumeSet(protocol, reader, protocol.readSetBegin());
- protocol.readSetEnd();
- }
- public void consumeSet(TProtocol protocol, EventBasedThriftReader reader, TSet tSet) throws TException {
- reader.readSetContent(this, tSet);
- }
- /**
- * can either delegate to the reader or read the set from the protocol
- * @param protocol the underlying protocol
- * @param reader the reader to delegate to
- * @throws TException
- */
- abstract public void consumeElement(
- TProtocol protocol, EventBasedThriftReader reader,
- byte elemType) throws TException;
- }
-
- abstract public static class MapConsumer extends TypedConsumer {
- protected MapConsumer() { super(MAP); }
- @Override
- final void read(TProtocol protocol, EventBasedThriftReader reader)
- throws TException {
- this.consumeMap(protocol, reader , protocol.readMapBegin());
- protocol.readMapEnd();
- }
- public void consumeMap(TProtocol protocol, EventBasedThriftReader reader, TMap tMap) throws TException {
- reader.readMapContent(this, tMap);
- }
- /**
- * can either delegate to the reader or read the map entry from the protocol
- * @param protocol the underlying protocol
- * @param reader the reader to delegate to
- * @throws TException
- */
- abstract public void consumeEntry(
- TProtocol protocol, EventBasedThriftReader reader,
- byte keyType, byte valueType) throws TException;
- }
-
- public final byte type;
-
- private TypedConsumer(byte type) {
- this.type = type;
- }
-
- final public void read(TProtocol protocol, EventBasedThriftReader reader, byte type) throws TException {
- if (this.type != type) {
- throw new TException(
- "Incorrect type in stream. "
- + "Expected " + this.type
- + " but got " + type);
- }
- this.read(protocol, reader);
- }
-
- abstract void read(TProtocol protocol, EventBasedThriftReader reader) throws TException;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/blob/af1e5b83/src/test/java/org/apache/parquet/format/TestUtil.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/parquet/format/TestUtil.java b/src/test/java/org/apache/parquet/format/TestUtil.java
new file mode 100644
index 0000000..1adf099
--- /dev/null
+++ b/src/test/java/org/apache/parquet/format/TestUtil.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.parquet.format;
+
+import static java.util.Arrays.asList;
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNull;
+import static org.apache.parquet.format.Util.readFileMetaData;
+import static org.apache.parquet.format.Util.writeFileMetaData;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import org.junit.Test;
+
+import org.apache.parquet.format.Util.DefaultFileMetaDataConsumer;
+public class TestUtil {
+
+ @Test
+ public void testReadFileMetadata() throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ FileMetaData md = new FileMetaData(
+ 1,
+ asList(new SchemaElement("foo")),
+ 10,
+ asList(
+ new RowGroup(
+ asList(
+ new ColumnChunk(0),
+ new ColumnChunk(1)
+ ),
+ 10,
+ 5),
+ new RowGroup(
+ asList(
+ new ColumnChunk(2),
+ new ColumnChunk(3)
+ ),
+ 11,
+ 5)
+ )
+ );
+ writeFileMetaData(md , baos);
+ FileMetaData md2 = readFileMetaData(in(baos));
+ FileMetaData md3 = new FileMetaData();
+ readFileMetaData(in(baos), new DefaultFileMetaDataConsumer(md3));
+ FileMetaData md4 = new FileMetaData();
+ readFileMetaData(in(baos), new DefaultFileMetaDataConsumer(md4), true);
+ FileMetaData md5 = readFileMetaData(in(baos), true);
+ FileMetaData md6 = readFileMetaData(in(baos), false);
+ assertEquals(md, md2);
+ assertEquals(md, md3);
+ assertNull(md4.getRow_groups());
+ assertNull(md5.getRow_groups());
+ assertEquals(md4, md5);
+ md4.setRow_groups(md.getRow_groups());
+ md5.setRow_groups(md.getRow_groups());
+ assertEquals(md, md4);
+ assertEquals(md, md5);
+ assertEquals(md4, md5);
+ assertEquals(md, md6);
+ }
+
+ private ByteArrayInputStream in(ByteArrayOutputStream baos) {
+ return new ByteArrayInputStream(baos.toByteArray());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/blob/af1e5b83/src/test/java/parquet/format/TestUtil.java
----------------------------------------------------------------------
diff --git a/src/test/java/parquet/format/TestUtil.java b/src/test/java/parquet/format/TestUtil.java
deleted file mode 100644
index 6ebcff8..0000000
--- a/src/test/java/parquet/format/TestUtil.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package parquet.format;
-
-import static java.util.Arrays.asList;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNull;
-import static parquet.format.Util.readFileMetaData;
-import static parquet.format.Util.writeFileMetaData;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
-import org.junit.Test;
-
-import parquet.format.Util.DefaultFileMetaDataConsumer;
-public class TestUtil {
-
- @Test
- public void testReadFileMetadata() throws Exception {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- FileMetaData md = new FileMetaData(
- 1,
- asList(new SchemaElement("foo")),
- 10,
- asList(
- new RowGroup(
- asList(
- new ColumnChunk(0),
- new ColumnChunk(1)
- ),
- 10,
- 5),
- new RowGroup(
- asList(
- new ColumnChunk(2),
- new ColumnChunk(3)
- ),
- 11,
- 5)
- )
- );
- writeFileMetaData(md , baos);
- FileMetaData md2 = readFileMetaData(in(baos));
- FileMetaData md3 = new FileMetaData();
- readFileMetaData(in(baos), new DefaultFileMetaDataConsumer(md3));
- FileMetaData md4 = new FileMetaData();
- readFileMetaData(in(baos), new DefaultFileMetaDataConsumer(md4), true);
- FileMetaData md5 = readFileMetaData(in(baos), true);
- FileMetaData md6 = readFileMetaData(in(baos), false);
- assertEquals(md, md2);
- assertEquals(md, md3);
- assertNull(md4.getRow_groups());
- assertNull(md5.getRow_groups());
- assertEquals(md4, md5);
- md4.setRow_groups(md.getRow_groups());
- md5.setRow_groups(md.getRow_groups());
- assertEquals(md, md4);
- assertEquals(md, md5);
- assertEquals(md4, md5);
- assertEquals(md, md6);
- }
-
- private ByteArrayInputStream in(ByteArrayOutputStream baos) {
- return new ByteArrayInputStream(baos.toByteArray());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-parquet-format/blob/af1e5b83/src/thrift/parquet.thrift
----------------------------------------------------------------------
diff --git a/src/thrift/parquet.thrift b/src/thrift/parquet.thrift
index 7544cf3..a5feaa2 100644
--- a/src/thrift/parquet.thrift
+++ b/src/thrift/parquet.thrift
@@ -21,7 +21,7 @@
* File format description for the parquet file format
*/
namespace cpp parquet
-namespace java parquet.format
+namespace java org.apache.parquet.format
/**
* Types supported by Parquet. These types are intended to be used in combination