Repository: incubator-pirk Updated Branches: refs/heads/master b998cab4f -> 0937b5baa
Change DataPartitioner to refer to List interface -- closes apache/incubator-pirk#53 Project: http://git-wip-us.apache.org/repos/asf/incubator-pirk/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-pirk/commit/0937b5ba Tree: http://git-wip-us.apache.org/repos/asf/incubator-pirk/tree/0937b5ba Diff: http://git-wip-us.apache.org/repos/asf/incubator-pirk/diff/0937b5ba Branch: refs/heads/master Commit: 0937b5baa7715d52a2c628a0b086bf342c620f84 Parents: b998cab Author: tellison <[email protected]> Authored: Wed Aug 10 18:13:48 2016 -0400 Committer: eawilliams <[email protected]> Committed: Wed Aug 10 18:13:48 2016 -0400 ---------------------------------------------------------------------- .../apache/pirk/query/wideskies/QueryUtils.java | 4 +- .../data/partitioner/DataPartitioner.java | 25 ++++++----- .../data/partitioner/IPDataPartitioner.java | 2 +- .../partitioner/ISO8601DatePartitioner.java | 2 +- .../partitioner/PrimitiveTypePartitioner.java | 45 +++----------------- 5 files changed, 22 insertions(+), 56 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/0937b5ba/src/main/java/org/apache/pirk/query/wideskies/QueryUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/pirk/query/wideskies/QueryUtils.java b/src/main/java/org/apache/pirk/query/wideskies/QueryUtils.java index f8bac62..396afbf 100644 --- a/src/main/java/org/apache/pirk/query/wideskies/QueryUtils.java +++ b/src/main/java/org/apache/pirk/query/wideskies/QueryUtils.java @@ -232,9 +232,9 @@ public class QueryUtils /** * Method to convert the given selector into the extracted BigInteger partitions */ - public static ArrayList<BigInteger> embeddedSelectorToPartitions(Object selector, String type, Object partitioner) throws Exception + public static List<BigInteger> embeddedSelectorToPartitions(Object selector, String type, Object partitioner) throws Exception { - ArrayList<BigInteger> parts; + List<BigInteger> parts; int partitionBits = ((DataPartitioner) partitioner).getBits(type); if (partitionBits > 32) // hash and add 32-bit hash value to partitions http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/0937b5ba/src/main/java/org/apache/pirk/schema/data/partitioner/DataPartitioner.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/pirk/schema/data/partitioner/DataPartitioner.java b/src/main/java/org/apache/pirk/schema/data/partitioner/DataPartitioner.java index 8981dcf..94bc201 100644 --- a/src/main/java/org/apache/pirk/schema/data/partitioner/DataPartitioner.java +++ b/src/main/java/org/apache/pirk/schema/data/partitioner/DataPartitioner.java @@ -20,7 +20,6 @@ package org.apache.pirk.schema.data.partitioner; import java.io.Serializable; import java.math.BigInteger; -import java.util.ArrayList; import java.util.List; import org.apache.pirk.utils.PIRException; @@ -33,36 +32,36 @@ import org.apache.pirk.utils.PIRException; public interface DataPartitioner extends Serializable { /** - * Method to partition the given Object into an ArrayList of BigInteger partition elements given its type identifier + * Method to partition the given Object into a List of BigInteger partition elements given its type identifier. * <p> - * If the Object does not have/need a specific type identifier, use null + * If the Object does not have/need a specific type identifier, use null. */ - ArrayList<BigInteger> toPartitions(Object object, String type) throws PIRException; + List<BigInteger> toPartitions(Object object, String type) throws PIRException; /** - * Method to reconstruct an Object given an ArrayList of its BigInteger partition elements and its type identifier + * Method to reconstruct an Object given a List of its BigInteger partition elements and its type identifier. * <p> - * If the Object does not have/need a specific type identifier, use null + * If the Object does not have/need a specific type identifier, use null. */ - Object fromPartitions(ArrayList<BigInteger> parts, int partsIndex, String type) throws PIRException; + Object fromPartitions(List<BigInteger> parts, int partsIndex, String type) throws PIRException; /** - * Method to return the number of bits of an object with the given type + * Returns the number of bits of an object with the given type. */ int getBits(String type) throws PIRException; /** - * Create partitions for an array of the same type of elements - used when a data value field is an array and we wish to encode these into the return value + * Creates partitions for an array of the same type of elements - used when a data value field is an array and we wish to encode these into the return value. */ - ArrayList<BigInteger> arrayToPartitions(List<?> elementList, String type) throws PIRException; + List<BigInteger> arrayToPartitions(List<?> elementList, String type) throws PIRException; /** - * Method to get an empty set of partitions by data type - used for padding return array values + * Method to get an empty set of partitions by data type - used for padding return array values. */ - ArrayList<BigInteger> getPaddedPartitions(String type) throws PIRException; + List<BigInteger> getPaddedPartitions(String type) throws PIRException; /** - * Method to get the number of partitions of the data object given the type + * Method to get the number of partitions of the data object given the type. */ int getNumPartitions(String type) throws PIRException; } http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/0937b5ba/src/main/java/org/apache/pirk/schema/data/partitioner/IPDataPartitioner.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/pirk/schema/data/partitioner/IPDataPartitioner.java b/src/main/java/org/apache/pirk/schema/data/partitioner/IPDataPartitioner.java index d2e63c4..f0c3e2e 100644 --- a/src/main/java/org/apache/pirk/schema/data/partitioner/IPDataPartitioner.java +++ b/src/main/java/org/apache/pirk/schema/data/partitioner/IPDataPartitioner.java @@ -48,7 +48,7 @@ public class IPDataPartitioner implements DataPartitioner } @Override - public Object fromPartitions(ArrayList<BigInteger> parts, int partsIndex, String type) + public Object fromPartitions(List<BigInteger> parts, int partsIndex, String type) { Object element; http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/0937b5ba/src/main/java/org/apache/pirk/schema/data/partitioner/ISO8601DatePartitioner.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/pirk/schema/data/partitioner/ISO8601DatePartitioner.java b/src/main/java/org/apache/pirk/schema/data/partitioner/ISO8601DatePartitioner.java index 329a083..e8d03bf 100644 --- a/src/main/java/org/apache/pirk/schema/data/partitioner/ISO8601DatePartitioner.java +++ b/src/main/java/org/apache/pirk/schema/data/partitioner/ISO8601DatePartitioner.java @@ -58,7 +58,7 @@ public class ISO8601DatePartitioner implements DataPartitioner } @Override - public Object fromPartitions(ArrayList<BigInteger> parts, int partsIndex, String type) throws PIRException + public Object fromPartitions(List<BigInteger> parts, int partsIndex, String type) throws PIRException { long dateLongFormat = (long) ptp.fromPartitions(parts, partsIndex, PrimitiveTypePartitioner.LONG); http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/0937b5ba/src/main/java/org/apache/pirk/schema/data/partitioner/PrimitiveTypePartitioner.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/pirk/schema/data/partitioner/PrimitiveTypePartitioner.java b/src/main/java/org/apache/pirk/schema/data/partitioner/PrimitiveTypePartitioner.java index f8f86e9..a2ac532 100644 --- a/src/main/java/org/apache/pirk/schema/data/partitioner/PrimitiveTypePartitioner.java +++ b/src/main/java/org/apache/pirk/schema/data/partitioner/PrimitiveTypePartitioner.java @@ -101,7 +101,7 @@ public class PrimitiveTypePartitioner implements DataPartitioner */ public static BigInteger formBitMask(int partitionSize) { - return (BigInteger.valueOf(2).pow(partitionSize)).subtract(BigInteger.ONE); + return BigInteger.valueOf(2).pow(partitionSize).subtract(BigInteger.ONE); } /** @@ -111,39 +111,7 @@ public class PrimitiveTypePartitioner implements DataPartitioner @Override public int getNumPartitions(String type) throws PIRException { - int partitionSize = 8; - - int numParts; - switch (type) - { - case BYTE: - numParts = Byte.SIZE / partitionSize; - break; - case SHORT: - numParts = Short.SIZE / partitionSize; - break; - case INT: - numParts = Integer.SIZE / partitionSize; - break; - case LONG: - numParts = Long.SIZE / partitionSize; - break; - case FLOAT: - numParts = Float.SIZE / partitionSize; - break; - case DOUBLE: - numParts = Double.SIZE / partitionSize; - break; - case CHAR: - numParts = Character.SIZE / partitionSize; - break; - case STRING: - numParts = Integer.parseInt(SystemConfiguration.getProperty("pir.stringBits")) / partitionSize; - break; - default: - throw new PIRException("type = " + type + " not recognized!"); - } - return numParts; + return getBits(type) / 8; } /** @@ -189,7 +157,7 @@ public class PrimitiveTypePartitioner implements DataPartitioner * Reconstructs the object from the partitions */ @Override - public Object fromPartitions(ArrayList<BigInteger> parts, int partsIndex, String type) throws PIRException + public Object fromPartitions(List<BigInteger> parts, int partsIndex, String type) throws PIRException { Object element; @@ -239,7 +207,6 @@ public class PrimitiveTypePartitioner implements DataPartitioner { byte[] bytes = appendBytes(parts, partsIndex, getNumPartitions(type)); element = new String(bytes).trim(); // this should remove 0 padding added for partitioning underflowing strings - break; } default: @@ -248,7 +215,7 @@ public class PrimitiveTypePartitioner implements DataPartitioner return element; } - private byte[] appendBytes(ArrayList<BigInteger> parts, int partsIndex, int numParts) + private byte[] appendBytes(List<BigInteger> parts, int partsIndex, int numParts) { ByteArrayBuffer buf = new ByteArrayBuffer(numParts); for (int i = 0; i < numParts; ++i) @@ -354,7 +321,7 @@ public class PrimitiveTypePartitioner implements DataPartitioner case CHAR: if (obj instanceof String) { - bytes = ByteBuffer.allocate(numParts).putChar(((String) (obj)).charAt(0)).array(); + bytes = ByteBuffer.allocate(numParts).putChar(((String) obj).charAt(0)).array(); } else { @@ -367,7 +334,7 @@ public class PrimitiveTypePartitioner implements DataPartitioner for (byte b : bytes) { // Make sure that BigInteger treats the byte as 'unsigned' literal - parts.add(BigInteger.valueOf(((long) b) & 0xFF)); + parts.add(BigInteger.valueOf((long) b & 0xFF)); } break; }
