Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,13 @@ This product includes code from Delta Lake.
Copyright: 2020 The Delta Lake Project Authors.
Home page: https://delta.io/
License: https://www.apache.org/licenses/LICENSE-2.0

--------------------------------------------------------------------------------

This product includes code from Apache Commons.

* Core ArrayUtil.

Copyright: 2020 The Apache Software Foundation
Home page: https://commons.apache.org/
License: https://www.apache.org/licenses/LICENSE-2.0
Comment thread
pan3793 marked this conversation as resolved.
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -1069,8 +1069,6 @@ project(':iceberg-pig') {
compile project(':iceberg-core')
compile project(':iceberg-parquet')

compile "org.apache.commons:commons-lang3"

compileOnly("org.apache.pig:pig") {
exclude group: "junit", module: "junit"
}
Expand Down
244 changes: 244 additions & 0 deletions core/src/main/java/org/apache/iceberg/util/ArrayUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.iceberg.util;

import java.lang.reflect.Array;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Expand All @@ -28,6 +29,14 @@ public class ArrayUtil {
private ArrayUtil() {
}

public static final boolean[] EMPTY_BOOLEAN_ARRAY = new boolean[0];
public static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
public static final short[] EMPTY_SHORT_ARRAY = new short[0];
public static final int[] EMPTY_INT_ARRAY = new int[0];
public static final long[] EMPTY_LONG_ARRAY = new long[0];
public static final float[] EMPTY_FLOAT_ARRAY = new float[0];
public static final double[] EMPTY_DOUBLE_ARRAY = new double[0];

public static List<Integer> toIntList(int[] ints) {
if (ints != null) {
return IntStream.of(ints).boxed().collect(Collectors.toList());
Expand Down Expand Up @@ -59,4 +68,239 @@ public static long[] toLongArray(List<Long> longs) {
return null;
}
}

/**
* Converts an array of object Booleans to primitives.
* <p>
* This method returns {@code null} for a {@code null} input array.
* <p>
* This code is borrowed from `org.apache.commons:commons-lang3`.
*
* @param array a {@code Boolean} array, may be {@code null}
* @return a {@code boolean} array, {@code null} if null array input
* @throws NullPointerException if array content is {@code null}
*/
public static boolean[] toPrimitive(final Boolean[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
return EMPTY_BOOLEAN_ARRAY;
}
final boolean[] result = new boolean[array.length];
for (int i = 0; i < array.length; i++) {
result[i] = array[i].booleanValue();
}
return result;
}
Comment thread
pan3793 marked this conversation as resolved.

/**
* Converts an array of object Bytes to primitives.
* <p>
* This method returns {@code null} for a {@code null} input array.
* <p>
* This code is borrowed from `org.apache.commons:commons-lang3`.
*
* @param array a {@code Byte} array, may be {@code null}
* @return a {@code byte} array, {@code null} if null array input
* @throws NullPointerException if array content is {@code null}
*/
public static byte[] toPrimitive(final Byte[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
return EMPTY_BYTE_ARRAY;
}
final byte[] result = new byte[array.length];
for (int i = 0; i < array.length; i++) {
result[i] = array[i].byteValue();
}
return result;
}

/**
* Converts an array of object Shorts to primitives.
* <p>
* This method returns {@code null} for a {@code null} input array.
* <p>
* This code is borrowed from `org.apache.commons:commons-lang3`.
*
* @param array a {@code Short} array, may be {@code null}
* @return a {@code byte} array, {@code null} if null array input
* @throws NullPointerException if array content is {@code null}
*/
public static short[] toPrimitive(final Short[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
return EMPTY_SHORT_ARRAY;
}
final short[] result = new short[array.length];
for (int i = 0; i < array.length; i++) {
result[i] = array[i].shortValue();
}
return result;
}

/**
* Converts an array of object Integers to primitives.
* <p>
* This method returns {@code null} for a {@code null} input array.
* <p>
* This code is borrowed from `org.apache.commons:commons-lang3`.
*
* @param array a {@code Integer} array, may be {@code null}
* @return an {@code int} array, {@code null} if null array input
* @throws NullPointerException if array content is {@code null}
*/
public static int[] toPrimitive(final Integer[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
return EMPTY_INT_ARRAY;
}
final int[] result = new int[array.length];
for (int i = 0; i < array.length; i++) {
result[i] = array[i].intValue();
}
return result;
}

/**
* Converts an array of object Longs to primitives.
* <p>
* This method returns {@code null} for a {@code null} input array.
* <p>
* This code is borrowed from `org.apache.commons:commons-lang3`.
*
* @param array a {@code Long} array, may be {@code null}
* @return a {@code long} array, {@code null} if null array input
* @throws NullPointerException if array content is {@code null}
*/
public static long[] toPrimitive(final Long[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
return EMPTY_LONG_ARRAY;
}
final long[] result = new long[array.length];
for (int i = 0; i < array.length; i++) {
result[i] = array[i].longValue();
}
return result;
}

/**
* Converts an array of object Floats to primitives.
* <p>
* This method returns {@code null} for a {@code null} input array.
* <p>
* This code is borrowed from `org.apache.commons:commons-lang3`.
*
* @param array a {@code Float} array, may be {@code null}
* @return a {@code float} array, {@code null} if null array input
* @throws NullPointerException if array content is {@code null}
*/
public static float[] toPrimitive(final Float[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
return EMPTY_FLOAT_ARRAY;
}
final float[] result = new float[array.length];
for (int i = 0; i < array.length; i++) {
result[i] = array[i].floatValue();
}
return result;
}

/**
* Converts an array of object Doubles to primitives.
* <p>
* This method returns {@code null} for a {@code null} input array.
* <p>
* This code is borrowed from `org.apache.commons:commons-lang3`.
*
* @param array a {@code Double} array, may be {@code null}
* @return a {@code double} array, {@code null} if null array input
* @throws NullPointerException if array content is {@code null}
*/
public static double[] toPrimitive(final Double[] array) {
if (array == null) {
return null;
} else if (array.length == 0) {
return EMPTY_DOUBLE_ARRAY;
}
final double[] result = new double[array.length];
for (int i = 0; i < array.length; i++) {
result[i] = array[i].doubleValue();
}
return result;
}

/**
* Copies the given array and adds the given element at the end of the new array.
* <p>
* The new array contains the same elements of the input
* array plus the given element in the last position. The component type of
* the new array is the same as that of the input array.
* <p>
* If the input array is {@code null}, a new one element array is returned
* whose component type is the same as the element, unless the element itself is null,
* in which case the return type is Object[]
*
* <pre>
* ArrayUtils.add(null, null) = IllegalArgumentException
* ArrayUtils.add(null, "a") = ["a"]
* ArrayUtils.add(["a"], null) = ["a", null]
* ArrayUtils.add(["a"], "b") = ["a", "b"]
* ArrayUtils.add(["a", "b"], "c") = ["a", "b", "c"]
* </pre>
*
* This code is borrowed from `org.apache.commons:commons-lang3`.
*
* @param <T> the component type of the array
* @param array the array to "add" the element to, may be {@code null}
* @param element the object to add, may be {@code null}
* @return A new array containing the existing elements plus the new element
* The returned array type will be that of the input array (unless null),
* in which case it will have the same type as the element.
* If both are null, an IllegalArgumentException is thrown
* @since 2.1
* @throws IllegalArgumentException if both arguments are null
*/
public static <T> T[] add(final T[] array, final T element) {
Class<?> type;
if (array != null) {
type = array.getClass().getComponentType();
} else if (element != null) {
type = element.getClass();
} else {
throw new IllegalArgumentException("Arguments cannot both be null");
}
@SuppressWarnings("unchecked") // type must be T
final T[] newArray = (T[]) copyArrayGrow1(array, type);
newArray[newArray.length - 1] = element;
return newArray;
}

/**
* Returns a copy of the given array of size 1 greater than the argument.
* The last value of the array is left to the default value.
* <p>
* This code is borrowed from `org.apache.commons:commons-lang3`.
*
* @param array The array to copy, must not be {@code null}.
* @param newArrayComponentType If {@code array} is {@code null}, create a
* size 1 array of this type.
* @return A new copy of the array of size 1 greater than the input.
*/
private static Object copyArrayGrow1(final Object array, final Class<?> newArrayComponentType) {
if (array != null) {
final int arrayLength = Array.getLength(array);
final Object newArray = Array.newInstance(array.getClass().getComponentType(), arrayLength + 1);
System.arraycopy(array, 0, newArray, 0, arrayLength);
return newArray;
}
return Array.newInstance(newArrayComponentType, 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

package org.apache.iceberg.mr;
package org.apache.iceberg.util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -35,7 +35,7 @@ private SerializationUtil() {

public static byte[] serializeToBytes(Object obj) {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos)) {
ObjectOutputStream oos = new ObjectOutputStream(baos)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the whitespace only changes in this file?

oos.writeObject(obj);
return baos.toByteArray();
} catch (IOException e) {
Expand All @@ -50,7 +50,7 @@ public static <T> T deserializeFromBytes(byte[] bytes) {
}

try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais)) {
ObjectInputStream ois = new ObjectInputStream(bais)) {
return (T) ois.readObject();
} catch (IOException e) {
throw new UncheckedIOException("Failed to deserialize object", e);
Expand Down
10 changes: 10 additions & 0 deletions flink-runtime/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,13 @@ License text:
| LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
| NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
| SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

--------------------------------------------------------------------------------

This binary includes code from Apache Commons.

* Core ArrayUtil.

Copyright: 2020 The Apache Software Foundation
Home page: https://commons.apache.org/
License: https://www.apache.org/licenses/LICENSE-2.0
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.time.ZoneOffset;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.flink.table.data.ArrayData;
import org.apache.flink.table.data.DecimalData;
import org.apache.flink.table.data.GenericRowData;
Expand All @@ -45,6 +44,7 @@
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
import org.apache.iceberg.types.Types;
import org.apache.iceberg.util.ArrayUtil;
import org.apache.parquet.column.ColumnDescriptor;
import org.apache.parquet.io.api.Binary;
import org.apache.parquet.schema.GroupType;
Expand Down Expand Up @@ -760,37 +760,37 @@ public RowData getRow(int pos, int numFields) {

@Override
public boolean[] toBooleanArray() {
return ArrayUtils.toPrimitive((Boolean[]) values);
return ArrayUtil.toPrimitive((Boolean[]) values);
}

@Override
public byte[] toByteArray() {
return ArrayUtils.toPrimitive((Byte[]) values);
return ArrayUtil.toPrimitive((Byte[]) values);
}

@Override
public short[] toShortArray() {
return ArrayUtils.toPrimitive((Short[]) values);
return ArrayUtil.toPrimitive((Short[]) values);
}

@Override
public int[] toIntArray() {
return ArrayUtils.toPrimitive((Integer[]) values);
return ArrayUtil.toPrimitive((Integer[]) values);
}

@Override
public long[] toLongArray() {
return ArrayUtils.toPrimitive((Long[]) values);
return ArrayUtil.toPrimitive((Long[]) values);
}

@Override
public float[] toFloatArray() {
return ArrayUtils.toPrimitive((Float[]) values);
return ArrayUtil.toPrimitive((Float[]) values);
}

@Override
public double[] toDoubleArray() {
return ArrayUtils.toPrimitive((Double[]) values);
return ArrayUtil.toPrimitive((Double[]) values);
}
}
}
Loading