Github user smarthi commented on a diff in the pull request:

    https://github.com/apache/incubator-pirk/pull/57#discussion_r74619625
  
    --- Diff: 
src/main/java/org/apache/pirk/schema/data/partitioner/PrimitiveTypePartitioner.java
 ---
    @@ -346,53 +309,14 @@ public Object fromPartitions(List<BigInteger> parts, 
int partsIndex, String type
        * Method to get an empty set of partitions by data type - used for 
padding return array values
        */
       @Override
    -  public ArrayList<BigInteger> getPaddedPartitions(String type) throws 
PIRException
    +  public List<BigInteger> getPaddedPartitions(String type) throws 
PIRException
       {
    -    ArrayList<BigInteger> parts = new ArrayList<>();
    -
         int numParts = getNumPartitions(type);
    -    switch (type)
    -    {
    -      case BYTE:
    -        parts.add(new 
BigInteger(ByteBuffer.allocate(1).put(Byte.parseByte("0")).array()));
    -        break;
    -      case STRING:
    -        for (int i = 0; i < numParts; ++i)
    -        {
    -          parts.add(new 
BigInteger(ByteBuffer.allocate(1).put(Byte.parseByte("0")).array()));
    -        }
    -        break;
    -      default:
    -        // Extract the byte array
    -        byte[] bytes = new byte[0];
    -        switch (type)
    -        {
    -          case SHORT:
    -            bytes = 
ByteBuffer.allocate(numParts).putShort(Short.parseShort("0")).array();
    -            break;
    -          case INT:
    -            bytes = 
ByteBuffer.allocate(numParts).putInt(Integer.parseInt("0")).array();
    -            break;
    -          case LONG:
    -            bytes = 
ByteBuffer.allocate(numParts).putLong(Long.parseLong("0")).array();
    -            break;
    -          case FLOAT:
    -            bytes = 
ByteBuffer.allocate(numParts).putFloat(Float.parseFloat("0")).array();
    -            break;
    -          case DOUBLE:
    -            bytes = 
ByteBuffer.allocate(numParts).putDouble(Double.parseDouble("0")).array();
    -            break;
    -          case CHAR:
    -            bytes = ByteBuffer.allocate(numParts).putChar('0').array();
    -            break;
    -        }
     
    -        // Add bytes to parts ArrayList
    -        for (byte b : bytes)
    -        {
    -          parts.add(new BigInteger(ByteBuffer.allocate(1).put(b).array()));
    -        }
    -        break;
    +    List<BigInteger> parts = new ArrayList<>(numParts);
    +    for (int i = 0; i < numParts; i++)
    +    {
    +      parts.add(BigInteger.ZERO);
    --- End diff --
    
    How bout something like
    
    `BigInteger[] bigInts = new BigInteger[numParts];
     Arrays.fill(bigInts, BigInteger.ZERO);
     List<BigInteger> parts = Arrays.asList(bigInts);`
    
    that way, the for loop can be avoided in the code.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to