Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encoder without string column #290

Merged
merged 1 commit into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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