[parquet-mr] branch master updated: [PARQUET-1500] Replace Closeables with try-with-resources (#597)

2019-01-25 Thread gabor
This is an automated email from the ASF dual-hosted git repository.

gabor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/parquet-mr.git


The following commit(s) were added to refs/heads/master by this push:
 new f36dd08  [PARQUET-1500] Replace Closeables with try-with-resources 
(#597)
f36dd08 is described below

commit f36dd08505b5dc799d2e4e92328901796f7b3cb8
Author: Fokko Driesprong 
AuthorDate: Fri Jan 25 09:07:48 2019 +0100

[PARQUET-1500] Replace Closeables with try-with-resources (#597)
---
 .../main/java/org/apache/parquet/Closeables.java   |  8 ++--
 .../parquet/hadoop/util/SerializationUtil.java | 46 +++---
 2 files changed, 19 insertions(+), 35 deletions(-)

diff --git a/parquet-common/src/main/java/org/apache/parquet/Closeables.java 
b/parquet-common/src/main/java/org/apache/parquet/Closeables.java
index 086f6cc..2f312aa 100644
--- a/parquet-common/src/main/java/org/apache/parquet/Closeables.java
+++ b/parquet-common/src/main/java/org/apache/parquet/Closeables.java
@@ -1,4 +1,4 @@
-/* 
+/*
  * 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
@@ -6,9 +6,9 @@
  * 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
@@ -26,7 +26,9 @@ import org.slf4j.LoggerFactory;
 
 /**
  * Utility for working with {@link java.io.Closeable}ss
+ * @deprecated will be removed in 2.0.0. Use Java try-with-resource instead.
  */
+@Deprecated
 public final class Closeables {
   private Closeables() { }
 
diff --git 
a/parquet-hadoop/src/main/java/org/apache/parquet/hadoop/util/SerializationUtil.java
 
b/parquet-hadoop/src/main/java/org/apache/parquet/hadoop/util/SerializationUtil.java
index 529115b..06d5fea 100644
--- 
a/parquet-hadoop/src/main/java/org/apache/parquet/hadoop/util/SerializationUtil.java
+++ 
b/parquet-hadoop/src/main/java/org/apache/parquet/hadoop/util/SerializationUtil.java
@@ -1,4 +1,4 @@
-/* 
+/*
  * 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
@@ -6,9 +6,9 @@
  * 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
@@ -23,13 +23,13 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.zip.GZIPInputStream;
 import java.util.zip.GZIPOutputStream;
 
 import org.apache.commons.codec.binary.Base64;
 import org.apache.hadoop.conf.Configuration;
 
-import org.apache.parquet.Closeables;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -53,22 +53,13 @@ public final class SerializationUtil {
* @throws IOException if there is an error while writing
*/
   public static void writeObjectToConfAsBase64(String key, Object obj, 
Configuration conf) throws IOException {
-ByteArrayOutputStream baos = null;
-GZIPOutputStream gos = null;
-ObjectOutputStream oos = null;
-
-try {
-  baos = new ByteArrayOutputStream();
-  gos = new GZIPOutputStream(baos);
-  oos = new ObjectOutputStream(gos);
-  oos.writeObject(obj);
-} finally {
-  Closeables.close(oos);
-  Closeables.close(gos);
-  Closeables.close(baos);
+try(ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+  try(GZIPOutputStream gos = new GZIPOutputStream(baos);
+ObjectOutputStream oos = new ObjectOutputStream(gos)) {
+oos.writeObject(obj);
+  }
+  conf.set(key, new String(Base64.encodeBase64(baos.toByteArray()), 
StandardCharsets.UTF_8));
 }
-
-conf.set(key, new String(Base64.encodeBase64(baos.toByteArray()), 
"UTF-8"));
   }
 
   /**
@@ -88,25 +79,16 @@ public final class SerializationUtil {
   return null;
 }
 
-byte[] bytes = Base64.decodeBase64(b64.getBytes("UTF-8"));
-
-ByteArrayInputStream bais = null;
-GZIPInputStream gis = null;
-ObjectInputStream ois = null;
+byte[] bytes = Base64.decodeBase64(b64.getBytes(StandardCharsets.UTF_8));
 
-try {
-  bais = new ByteArrayInputStream(bytes);
-   

[parquet-mr] branch master updated: PARQUET-1503: Remove Ints Utility Class (#598)

2019-01-25 Thread gabor
This is an automated email from the ASF dual-hosted git repository.

gabor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/parquet-mr.git


The following commit(s) were added to refs/heads/master by this push:
 new 1e62e2e  PARQUET-1503: Remove Ints Utility Class (#598)
1e62e2e is described below

commit 1e62e2e2ca903d4109480bc87ceec1dc954b6c92
Author: BELUGABEHR 
AuthorDate: Fri Jan 25 03:21:15 2019 -0500

PARQUET-1503: Remove Ints Utility Class (#598)
---
 .../main/java/org/apache/parquet/column/impl/ColumnWriterV2.java | 3 +--
 .../src/main/java/org/apache/parquet/column/page/DataPageV1.java | 5 ++---
 .../src/main/java/org/apache/parquet/column/page/DataPageV2.java | 9 -
 .../main/java/org/apache/parquet/column/page/DictionaryPage.java | 3 +--
 .../column/values/rle/RunLengthBitPackingHybridValuesWriter.java | 3 +--
 parquet-common/src/main/java/org/apache/parquet/Ints.java| 2 ++
 .../java/org/apache/parquet/hadoop/ColumnChunkPageReadStore.java | 7 ++-
 7 files changed, 13 insertions(+), 19 deletions(-)

diff --git 
a/parquet-column/src/main/java/org/apache/parquet/column/impl/ColumnWriterV2.java
 
b/parquet-column/src/main/java/org/apache/parquet/column/impl/ColumnWriterV2.java
index 04076c9..e4e8563 100644
--- 
a/parquet-column/src/main/java/org/apache/parquet/column/impl/ColumnWriterV2.java
+++ 
b/parquet-column/src/main/java/org/apache/parquet/column/impl/ColumnWriterV2.java
@@ -20,7 +20,6 @@ package org.apache.parquet.column.impl;
 
 import java.io.IOException;
 
-import org.apache.parquet.Ints;
 import org.apache.parquet.bytes.BytesInput;
 import org.apache.parquet.column.ColumnDescriptor;
 import org.apache.parquet.column.Encoding;
@@ -78,7 +77,7 @@ final class ColumnWriterV2 extends ColumnWriterBase {
 Encoding encoding = values.getEncoding();
 pageWriter.writePageV2(
 rowCount,
-Ints.checkedCast(statistics.getNumNulls()),
+Math.toIntExact(statistics.getNumNulls()),
 valueCount,
 repetitionLevels.getBytes(),
 definitionLevels.getBytes(),
diff --git 
a/parquet-column/src/main/java/org/apache/parquet/column/page/DataPageV1.java 
b/parquet-column/src/main/java/org/apache/parquet/column/page/DataPageV1.java
index b1f68ae..f03ffc0 100755
--- 
a/parquet-column/src/main/java/org/apache/parquet/column/page/DataPageV1.java
+++ 
b/parquet-column/src/main/java/org/apache/parquet/column/page/DataPageV1.java
@@ -20,7 +20,6 @@ package org.apache.parquet.column.page;
 
 import java.util.Optional;
 
-import org.apache.parquet.Ints;
 import org.apache.parquet.bytes.BytesInput;
 import org.apache.parquet.column.Encoding;
 import org.apache.parquet.column.statistics.Statistics;
@@ -44,7 +43,7 @@ public class DataPageV1 extends DataPage {
* @param valuesEncoding the values encoding for this page
*/
   public DataPageV1(BytesInput bytes, int valueCount, int uncompressedSize, 
Statistics statistics, Encoding rlEncoding, Encoding dlEncoding, Encoding 
valuesEncoding) {
-super(Ints.checkedCast(bytes.size()), uncompressedSize, valueCount);
+super(Math.toIntExact(bytes.size()), uncompressedSize, valueCount);
 this.bytes = bytes;
 this.statistics = statistics;
 this.rlEncoding = rlEncoding;
@@ -66,7 +65,7 @@ public class DataPageV1 extends DataPage {
*/
   public DataPageV1(BytesInput bytes, int valueCount, int uncompressedSize, 
long firstRowIndex, int rowCount,
   Statistics statistics, Encoding rlEncoding, Encoding dlEncoding, 
Encoding valuesEncoding) {
-super(Ints.checkedCast(bytes.size()), uncompressedSize, valueCount, 
firstRowIndex);
+super(Math.toIntExact(bytes.size()), uncompressedSize, valueCount, 
firstRowIndex);
 this.bytes = bytes;
 this.statistics = statistics;
 this.rlEncoding = rlEncoding;
diff --git 
a/parquet-column/src/main/java/org/apache/parquet/column/page/DataPageV2.java 
b/parquet-column/src/main/java/org/apache/parquet/column/page/DataPageV2.java
index a1700ae..706b699 100644
--- 
a/parquet-column/src/main/java/org/apache/parquet/column/page/DataPageV2.java
+++ 
b/parquet-column/src/main/java/org/apache/parquet/column/page/DataPageV2.java
@@ -20,7 +20,6 @@ package org.apache.parquet.column.page;
 
 import java.util.Optional;
 
-import org.apache.parquet.Ints;
 import org.apache.parquet.bytes.BytesInput;
 import org.apache.parquet.column.Encoding;
 import org.apache.parquet.column.statistics.Statistics;
@@ -47,7 +46,7 @@ public class DataPageV2 extends DataPage {
 rowCount, nullCount, valueCount,
 repetitionLevels, definitionLevels,
 dataEncoding, data,
-Ints.checkedCast(repetitionLevels.size() + definitionLevels.size() + 
data.size()),
+Math.toIntExact(repetitionLevels.size() + definitionLevels.size() + 
data.size()),
 statistics,
 false);
   }
@@ -73,7 +72,7 @@ public class DataPageV2 extends DataPage {
 rowCount, nullCount, valueCount, firstRowIndex,