[
https://issues.apache.org/jira/browse/PIRK-49?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15419082#comment-15419082
]
ASF GitHub Bot commented on PIRK-49:
------------------------------------
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.
> PrimitivePartioner does not account for locale settings
> -------------------------------------------------------
>
> Key: PIRK-49
> URL: https://issues.apache.org/jira/browse/PIRK-49
> Project: PIRK
> Issue Type: Bug
> Reporter: Tim Ellison
> Assignee: Tim Ellison
>
> The class org.apache.pirk.schema.data.partitioner.PrimitiveTypePartitioner
> splits types into parts using logic that is specific to the current locale of
> the runtime environment.
> In particular, it does not take account of default big endian or little
> endian byte ordering, and it uses the platform default encoding for
> converting to and from Strings. This is likely to lead to data corruption
> when exchanging data across different machine architectures and OS
> installations.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)