tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject git commit: TAJO-701: Invalid bytes when creating BlobDatum with offset. (jinho)
Date Wed, 26 Mar 2014 02:32:17 GMT
Repository: tajo
Updated Branches:
  refs/heads/branch-0.8.0 67c2a2134 -> d42f84d9b


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/d42f84d9
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/d42f84d9
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/d42f84d9

Branch: refs/heads/branch-0.8.0
Commit: d42f84d9b4437ff703d99c45cb0120932d7f5d27
Parents: 67c2a21
Author: jinossy <jinossy@gmail.com>
Authored: Wed Mar 26 11:31:33 2014 +0900
Committer: jinossy <jinossy@gmail.com>
Committed: Wed Mar 26 11:31:33 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/d42f84d9/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 515fd64..d2789c9 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-705: CTAS always stores tables with CSV storage type into catalog.
     (jinho)
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/d42f84d9/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/d42f84d9/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());
   }
 }


Mime
View raw message