You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by jh...@apache.org on 2014/03/26 03:30:31 UTC

git commit: TAJO-701: Invalid bytes when creating BlobDatum with offset. (jinho)

Repository: tajo
Updated Branches:
  refs/heads/master 5580c1732 -> 321bdc07e


TAJO-701: Invalid bytes when creating BlobDatum with offset. (jinho)


Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/321bdc07
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/321bdc07
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/321bdc07

Branch: refs/heads/master
Commit: 321bdc07e3f28a4649258e8af0b7b0dcb08765c0
Parents: 5580c17
Author: jinossy <ji...@gmail.com>
Authored: Wed Mar 26 11:30:02 2014 +0900
Committer: jinossy <ji...@gmail.com>
Committed: Wed Mar 26 11:30:02 2014 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 ++
 .../java/org/apache/tajo/datum/BlobDatum.java   |  6 +++--
 .../org/apache/tajo/datum/TestBytesDatum.java   | 26 ++++++++++++++++++++
 3 files changed, 32 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/321bdc07/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index e568713..0f64d88 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -283,6 +283,8 @@ Release 0.8.0 - unreleased
 
   BUG FIXES
 
+    TAJO-701: Invalid bytes when creating BlobDatum with offset. (jinho)
+
     TAJO-708: Test failure after a successful test. (jihoon)
 
     TAJO-705: CTAS always stores tables with CSV storage type into catalog.

http://git-wip-us.apache.org/repos/asf/tajo/blob/321bdc07/tajo-common/src/main/java/org/apache/tajo/datum/BlobDatum.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/datum/BlobDatum.java b/tajo-common/src/main/java/org/apache/tajo/datum/BlobDatum.java
index 4c4f557..13b845b 100644
--- a/tajo-common/src/main/java/org/apache/tajo/datum/BlobDatum.java
+++ b/tajo-common/src/main/java/org/apache/tajo/datum/BlobDatum.java
@@ -43,8 +43,10 @@ public class BlobDatum extends Datum {
 
   public BlobDatum(byte[] val, int offset, int length) {
     super(BLOB);
-    this.val = val;
-    this.bb = ByteBuffer.wrap(val, offset, length);
+    byte[] b = new byte[length];
+    System.arraycopy(val, offset, b, 0 , length);
+    this.val = b;
+    this.bb = ByteBuffer.wrap(b);
     bb.flip();
   }
 	

http://git-wip-us.apache.org/repos/asf/tajo/blob/321bdc07/tajo-common/src/test/java/org/apache/tajo/datum/TestBytesDatum.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/test/java/org/apache/tajo/datum/TestBytesDatum.java b/tajo-common/src/test/java/org/apache/tajo/datum/TestBytesDatum.java
index af2d814..4dcbbee 100644
--- a/tajo-common/src/test/java/org/apache/tajo/datum/TestBytesDatum.java
+++ b/tajo-common/src/test/java/org/apache/tajo/datum/TestBytesDatum.java
@@ -20,8 +20,11 @@ package org.apache.tajo.datum;
 
 import org.apache.tajo.common.TajoDataTypes.Type;
 import org.apache.tajo.json.CommonGsonHelper;
+import org.apache.tajo.util.Bytes;
 import org.junit.Test;
 
+import java.nio.ByteBuffer;
+
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
@@ -58,5 +61,28 @@ public class TestBytesDatum {
   public final void testAsTextBytes() {
     Datum d = DatumFactory.createBlob("12345".getBytes());
     assertArrayEquals(d.toString().getBytes(), d.asTextBytes());
+
+    byte[] bytes = "12345".getBytes();
+    d = DatumFactory.createBlob(bytes, 0, 1);
+    assertEquals(d.toString(), "1");
+  }
+
+  @Test
+  public final void testAsBytes() {
+    ByteBuffer buffer = ByteBuffer.allocate(14);
+    buffer.putShort((short)1);
+    buffer.putInt(123);
+    buffer.putLong(123456);
+    buffer.flip();
+    byte[] bytes = Bytes.getBytes(buffer);
+
+    Datum d = new BlobDatum(buffer);
+    assertArrayEquals(bytes, d.asByteArray());
+    buffer.clear();
+
+    byte[] bytes1 = new byte[1024];
+    System.arraycopy(bytes, 0, bytes1, 0, bytes.length);
+    d = new BlobDatum(bytes1, 0, bytes.length);
+    assertArrayEquals(bytes, d.asByteArray());
   }
 }