diff --git a/parquet-common/pom.xml b/parquet-common/pom.xml
index b6468f5509..eacf2ab2f3 100644
--- a/parquet-common/pom.xml
+++ b/parquet-common/pom.xml
@@ -47,6 +47,34 @@
org.apache.maven.plugins
maven-jar-plugin
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 1.2.1
+
+
+ org.apache.parquet
+ parquet-generator
+ ${project.version}
+
+
+
+
+ generate-sources
+
+ java
+
+
+
+
+ org.apache.parquet.version.Generator
+ true
+
+ ${basedir}/target/generated-src
+
+ ${basedir}/target/generated-src
+
+
diff --git a/parquet-common/src/main/java/org/apache/parquet/Version.java b/parquet-common/src/main/java/org/apache/parquet/Version.java
deleted file mode 100644
index 6580f333ab..0000000000
--- a/parquet-common/src/main/java/org/apache/parquet/Version.java
+++ /dev/null
@@ -1,103 +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 org.apache.parquet;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.Properties;
-import java.util.jar.Manifest;
-
-/**
- * The version of the library
- *
- * parquet-mr version 1.0.0-SNAPSHOT (build 6cf94d29b2b7115df4de2c06e2ab4326d721eb55)
- *
- * @author Julien Le Dem
- *
- */
-public class Version {
- private static final Log LOG = Log.getLog(Version.class);
-
- public static final String VERSION_NUMBER = readVersionNumber();
- public static final String FULL_VERSION = readFullVersion();
-
- private static String getJarPath() {
- final URL versionClassBaseUrl = Version.class.getResource("");
- if (versionClassBaseUrl.getProtocol().equals("jar")) {
- String path = versionClassBaseUrl.getPath();
- int jarEnd = path.indexOf("!");
- if (jarEnd != -1) {
- String jarPath = path.substring(0, jarEnd);
- return jarPath;
- }
- }
- return null;
- }
-
- private static URL getResourceFromJar(String jarPath, String path) throws IOException {
- Enumeration resources = Version.class.getClassLoader().getResources(path);
- while (resources.hasMoreElements()) {
- URL url = resources.nextElement();
- if (url.getProtocol().equals("jar") && url.getPath().startsWith(jarPath)) {
- return url;
- }
- }
- return null;
- }
-
- private static String readVersionNumber() {
- String version = null;
- try {
- String jarPath = getJarPath();
- if (jarPath != null) {
- URL pomPropertiesUrl = getResourceFromJar(jarPath, "META-INF/maven/com.twitter/parquet-column/pom.properties");
- if (pomPropertiesUrl != null) {
- Properties properties = new Properties();
- properties.load(pomPropertiesUrl.openStream());
- version = properties.getProperty("version");
- }
- }
- } catch (Exception e) {
- LOG.warn("can't read from META-INF", e);
- }
- return version;
- }
-
- private static String readFullVersion() {
- String sha = null;
- try {
- String jarPath = getJarPath();
- if (jarPath != null) {
- URL manifestUrl = getResourceFromJar(jarPath, "META-INF/MANIFEST.MF");
- if (manifestUrl != null) {
- Manifest manifest = new Manifest(manifestUrl.openStream());
- sha = manifest.getMainAttributes().getValue("git-SHA-1");
- }
- }
- } catch (Exception e) {
- LOG.warn("can't read from META-INF", e);
- }
- return "parquet-mr" + (VERSION_NUMBER != null ? " version " + VERSION_NUMBER : "") + (sha != null ? " (build " + sha + ")" : "");
- }
-
- public static void main(String[] args) {
- System.out.println(FULL_VERSION);
- }
-}
diff --git a/parquet-generator/pom.xml b/parquet-generator/pom.xml
index 5bc18d6556..f73a3d7004 100644
--- a/parquet-generator/pom.xml
+++ b/parquet-generator/pom.xml
@@ -36,14 +36,15 @@
-
- org.apache.parquet
- parquet-common
- ${project.version}
-
+
+
+ src/main/resources
+ true
+
+
maven-enforcer-plugin
diff --git a/parquet-generator/src/main/java/org/apache/parquet/encoding/bitpacking/ByteBasedBitPackingGenerator.java b/parquet-generator/src/main/java/org/apache/parquet/encoding/bitpacking/ByteBasedBitPackingGenerator.java
index 2249cbc638..9a7c5623ef 100644
--- a/parquet-generator/src/main/java/org/apache/parquet/encoding/bitpacking/ByteBasedBitPackingGenerator.java
+++ b/parquet-generator/src/main/java/org/apache/parquet/encoding/bitpacking/ByteBasedBitPackingGenerator.java
@@ -22,8 +22,6 @@
import java.io.FileWriter;
import java.io.IOException;
-import org.apache.parquet.bytes.BytesUtils;
-
/**
*
* This class generates bit packers that pack the most significant bit first.
@@ -214,7 +212,7 @@ private static void generateUnpack(FileWriter fw, int bitWidth, int batch, boole
fw.append(" out[" + align(valueIndex, 2) + " + outPos] =\n");
int startIndex = valueIndex * bitWidth / 8;
- int endIndex = BytesUtils.paddedByteCountFromBits((valueIndex + 1) * bitWidth);
+ int endIndex = paddedByteCountFromBits((valueIndex + 1) * bitWidth);
for (int byteIndex = startIndex; byteIndex < endIndex; byteIndex++) {
if (byteIndex == startIndex) {
@@ -256,4 +254,9 @@ private static String align(int value, int digits) {
result.append(valueString);
return result.toString();
}
+
+ // duplicated from BytesUtils to avoid a circular dependency between parquet-common and parquet-generator
+ private static int paddedByteCountFromBits(int bitLength) {
+ return (bitLength + 7) / 8;
+ }
}
diff --git a/parquet-generator/src/main/java/org/apache/parquet/version/Generator.java b/parquet-generator/src/main/java/org/apache/parquet/version/Generator.java
new file mode 100644
index 0000000000..57de327727
--- /dev/null
+++ b/parquet-generator/src/main/java/org/apache/parquet/version/Generator.java
@@ -0,0 +1,28 @@
+/*
+ * 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.version;
+
+/**
+ * main class for code generation hook in build for version generation
+ */
+public class Generator {
+ public static void main(String[] args) throws Exception {
+ VersionGenerator.main(args);
+ }
+}
diff --git a/parquet-generator/src/main/java/org/apache/parquet/version/VersionGenerator.java b/parquet-generator/src/main/java/org/apache/parquet/version/VersionGenerator.java
new file mode 100644
index 0000000000..e0c5e4dd35
--- /dev/null
+++ b/parquet-generator/src/main/java/org/apache/parquet/version/VersionGenerator.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.version;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+public class VersionGenerator {
+
+ public static void main(String[] args) throws IOException {
+ File srcFile = new File(args[0] + "/org/apache/parquet/Version.java");
+ srcFile = srcFile.getAbsoluteFile();
+ File parent = srcFile.getParentFile();
+ if (!parent.exists()) {
+ if (!parent.mkdirs()) {
+ throw new IOException("Couldn't mkdirs for " + parent);
+ }
+ }
+ new VersionGenerator(srcFile).run();
+ }
+
+ private final FileWriter writer;
+
+ public VersionGenerator(File file) throws IOException {
+ this.writer = new FileWriter(file);
+ }
+
+ public void run() throws IOException {
+ InputStream in = VersionGenerator.class.getResourceAsStream("/parquet-version.properties");
+ if (in == null) {
+ throw new IOException("/parquet-version.properties not found");
+ }
+ Properties props = new Properties();
+ props.load(in);
+
+ add("package org.apache.parquet;\n" +
+ "\n" +
+ "/**\n" +
+ " * This class is auto-generated by {@link org.apache.parquet.version.VersionGenerator}\n" +
+ " * Do not manually edit!\n" +
+ " */\n");
+
+ add("public class Version {\n");
+
+ add(" public static final String VERSION_NUMBER = \"");
+ add(props.getProperty("versionNumber"));
+ add("\";\n");
+
+ add(" public static final String FULL_VERSION = \"");
+ add(props.getProperty("fullVersion"));
+ add("\";\n\n");
+
+ add(" public static void main(String[] args) {\n");
+ add(" System.out.println(FULL_VERSION);\n");
+ add(" }\n");
+
+ add("}\n");
+ writer.close();
+ }
+
+ private void add(String s) throws IOException {
+ writer.write(s);
+ }
+}
diff --git a/parquet-generator/src/main/resources/parquet-version.properties b/parquet-generator/src/main/resources/parquet-version.properties
new file mode 100644
index 0000000000..5617e42ccb
--- /dev/null
+++ b/parquet-generator/src/main/resources/parquet-version.properties
@@ -0,0 +1,20 @@
+#
+# 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.
+
+versionNumber = ${project.version}
+fullVersion = parquet-mr version ${project.version} (build ${buildNumber})