gszadovszky commented on a change in pull request #923:
URL: https://github.com/apache/parquet-mr/pull/923#discussion_r716474012



##########
File path: parquet-column/src/main/java/org/apache/parquet/column/MinMax.java
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.column;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.parquet.io.api.Binary;
+import org.apache.parquet.schema.PrimitiveComparator;
+
+/**
+ * This class calculates the max and min values of a Set.
+ */
+public final class MinMax<T> {
+  private PrimitiveComparator comparator;
+  private Iterator<T> iterator;
+  private T min = null;
+  private T max = null;
+
+  public MinMax(PrimitiveComparator comparator, Iterator<T> iterator) {

Review comment:
       I would expect an `Iterable` instead of an `Iterator`. This way the Set 
can be passed directly.

##########
File path: parquet-column/src/main/java/org/apache/parquet/column/MinMax.java
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.column;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.parquet.io.api.Binary;
+import org.apache.parquet.schema.PrimitiveComparator;
+
+/**
+ * This class calculates the max and min values of a Set.
+ */
+public final class MinMax<T> {
+  private PrimitiveComparator comparator;
+  private Iterator<T> iterator;
+  private T min = null;
+  private T max = null;
+
+  public MinMax(PrimitiveComparator comparator, Iterator<T> iterator) {
+    this.comparator = comparator;
+    this.iterator = iterator;
+    getMinAndMax();
+  }
+
+  public T getMin() {
+    return min;
+  }
+
+  public T getMax() {
+    return max;
+  }
+
+  private void getMinAndMax() {
+    while(iterator.hasNext())  {
+      T element = iterator.next();
+      if (max == null) {
+        max = element;
+      } else if (max != null && element != null) {

Review comment:
       You are already in the else path so do not need to check for `max != 
null`. 

##########
File path: parquet-column/src/main/java/org/apache/parquet/column/MinMax.java
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.column;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.parquet.io.api.Binary;
+import org.apache.parquet.schema.PrimitiveComparator;
+
+/**
+ * This class calculates the max and min values of a Set.
+ */
+public final class MinMax<T> {
+  private PrimitiveComparator comparator;
+  private Iterator<T> iterator;
+  private T min = null;
+  private T max = null;
+
+  public MinMax(PrimitiveComparator comparator, Iterator<T> iterator) {
+    this.comparator = comparator;
+    this.iterator = iterator;

Review comment:
       You do not need to store the iterator and comparator instances since 
they are only used at initialization. I would simply pass them to 
`getMinAndMax`.

##########
File path: parquet-column/src/main/java/org/apache/parquet/column/MinMax.java
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.column;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.parquet.io.api.Binary;
+import org.apache.parquet.schema.PrimitiveComparator;
+
+/**
+ * This class calculates the max and min values of a Set.

Review comment:
       If you are more general in implementation by using an Iterator (or 
Iterable) you should use the same in the comments.

##########
File path: parquet-column/src/main/java/org/apache/parquet/column/MinMax.java
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.column;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.parquet.io.api.Binary;
+import org.apache.parquet.schema.PrimitiveComparator;
+
+/**
+ * This class calculates the max and min values of a Set.
+ */
+public final class MinMax<T> {
+  private PrimitiveComparator comparator;
+  private Iterator<T> iterator;
+  private T min = null;
+  private T max = null;
+
+  public MinMax(PrimitiveComparator comparator, Iterator<T> iterator) {

Review comment:
       ... and you may use foreach instead of a while loop on the iterator.

##########
File path: parquet-column/src/main/java/org/apache/parquet/column/MinMax.java
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.column;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.parquet.io.api.Binary;
+import org.apache.parquet.schema.PrimitiveComparator;
+
+/**
+ * This class calculates the max and min values of a Set.
+ */
+public final class MinMax<T> {
+  private PrimitiveComparator comparator;
+  private Iterator<T> iterator;
+  private T min = null;
+  private T max = null;
+
+  public MinMax(PrimitiveComparator comparator, Iterator<T> iterator) {
+    this.comparator = comparator;
+    this.iterator = iterator;
+    getMinAndMax();
+  }
+
+  public T getMin() {
+    return min;
+  }
+
+  public T getMax() {
+    return max;
+  }
+
+  private void getMinAndMax() {
+    while(iterator.hasNext())  {
+      T element = iterator.next();
+      if (max == null) {
+        max = element;
+      } else if (max != null && element != null) {
+        if ((element instanceof Integer &&
+          ((PrimitiveComparator<Integer>)comparator).compare((Integer)max, 
(Integer)element) < 0) ||
+          (element instanceof Binary &&
+            ((PrimitiveComparator<Binary>)comparator).compare((Binary)max, 
(Binary)element) < 0) ||
+          (element instanceof Double &&
+             ((PrimitiveComparator<Double>)comparator).compare((Double)max, 
(Double)element) < 0) ||
+          (element instanceof Float &&
+             ((PrimitiveComparator<Float>)comparator).compare((Float)max, 
(Float)element) < 0) ||
+          (element instanceof Boolean &&
+            ((PrimitiveComparator<Boolean>)comparator).compare((Boolean)max, 
(Boolean)element) < 0) ||
+          (element instanceof Long &&
+            ((PrimitiveComparator<Long>)comparator).compare((Long) max, 
(Long)element) < 0))

Review comment:
       You do not need to check the instance and cast. You may expect a 
`PrimitiveComparator<T>` and use it directly.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to