Skip to content

Commit

Permalink
fix encoder without string col (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
laura-ding authored Apr 13, 2021
1 parent 83df15f commit 529ce61
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public RowWriterImpl(SchemaProviderImpl schema, ByteOrder byteOrder) throws Runt
if (numNullables > 0) {
numNullBytes = ((numNullables - 1) >> 3) + 1;
}
buf = ByteBuffer.allocate(headerLen + numNullBytes + schema.size());
buf = ByteBuffer.allocate(headerLen + numNullBytes + schema.size() + Long.BYTES);
buf.order(this.byteOrder);
buf.put(header);
if (ver > 0) {
Expand Down Expand Up @@ -767,9 +767,9 @@ public ByteBuffer processOutOfSpace() {

// Reserve enough space to avoid memory re-allocation
// Copy the data except the strings
temp = temp.put(buf.array());
temp = temp.put(buf.array(), 0, buf.array().length - Long.BYTES);

int strOffset = buf.array().length;
int strOffset = buf.array().length - Long.BYTES;

// Now let's process all strings
int strNum = 0;
Expand Down Expand Up @@ -812,7 +812,7 @@ public void finish() {
buf = processOutOfSpace();
}
// Save the timestamp to the tail of buf
buf.putLong(getTimestamp());
buf.putLong(buf.array().length - Long.BYTES, getTimestamp());
}

private long getTimestamp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ public Schema genEmptyString() {
return new Schema(columns, null);
}

public Schema genWithoutString() {
List<ColumnDef> columns = new ArrayList<>();
ColumnDef columnDef = new ColumnDef(("Col01").getBytes(),
new ColumnTypeDef(PropertyType.INT64));
columns.add(columnDef);
return new Schema(columns, null);
}

public MetaCacheImplTest() {
spaceItem.space_id = 1;
SpaceDesc spaceDesc = new SpaceDesc("test_space".getBytes(),
Expand Down Expand Up @@ -190,6 +198,12 @@ public MetaCacheImplTest() {
tagItem3.schema = genEmptyString();
this.tagItems.put(new String(tagItem3.tag_name), tagItem3);

TagItem tagItem4 = new TagItem();
tagItem4.tag_name = "tag_without_string".getBytes();
tagItem4.version = 7;
tagItem4.schema = genWithoutString();
this.tagItems.put(new String(tagItem4.tag_name), tagItem4);

EdgeItem edgeItem1 = new EdgeItem();
edgeItem1.edge_name = "edge_no_default".getBytes();
edgeItem1.schema = genNoDefaultVal();
Expand Down
14 changes: 14 additions & 0 deletions client/src/test/java/com/vesoft/nebula/encoder/TestEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public void testEncodeVertexValue() {
TagItem tagItem1 = cacheImplTest.getTag("test", "tag_no_default");
TagItem tagItem2 = cacheImplTest.getTag("test", "tag_with_empty_string");
TagItem tagItem3 = cacheImplTest.getTag("test", "tag_with_default");
TagItem tagItem4 = cacheImplTest.getTag("test", "tag_without_string");
try {
codec.encodeTag(tagItem1, colNames, colVals);
Assert.fail();
Expand Down Expand Up @@ -253,6 +254,19 @@ public void testEncodeVertexValue() {
"Unsupported default value yet".getBytes());
assert (true);
}

// test without string type
try {
byte[] encodeStr = codec.encodeTag(
tagItem4, Arrays.asList("Col01"), Arrays.asList(1024));
String hexStr = Hex.encodeHexString(encodeStr);
String expectResult = "09070004000000000000";
Assert.assertArrayEquals(expectResult.getBytes(),
hexStr.substring(0, hexStr.length() - 16).getBytes());
} catch (Exception exception) {
exception.printStackTrace();
Assert.fail(exception.getMessage());
}
}

@Test()
Expand Down

0 comments on commit 529ce61

Please sign in to comment.