Skip to content

Commit 92f45e3

Browse files
authored
[Fix] the cell's timestamp of the Get result is always int64_max (#34)
1 parent 8c082ed commit 92f45e3

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/main/java/com/alipay/oceanbase/hbase/OHTable.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,8 @@ public void getKeyValueFromResult(AbstractQueryStreamResult clientQueryStreamRes
393393
KeyValue kv = new KeyValue((byte[]) row.get(0).getValue(),//K
394394
familyAndQualifier[0], // family
395395
familyAndQualifier[1], // qualifier
396-
(byte[]) row.get(3).getValue()//T
396+
(Long) row.get(2).getValue(), // T
397+
(byte[]) row.get(3).getValue()// V
397398
);
398399
keyValueList.add(kv);
399400
}

src/test/java/com/alipay/oceanbase/hbase/HTableTestBase.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ PRIMARY KEY (`K`, `Q`, `T`)
7373
Result r = hTable.get(get);
7474
Assert.assertEquals(1, r.raw().length);
7575
for (KeyValue keyValue : r.raw()) {
76+
Assert.assertEquals(key, Bytes.toString(keyValue.getRow()));
77+
Assert.assertEquals(column1, Bytes.toString(keyValue.getQualifier()));
78+
Assert.assertEquals(timestamp, keyValue.getTimestamp());
79+
Assert.assertEquals(value + "1", Bytes.toString(keyValue.getValue()));
7680
System.out.println("rowKey: " + new String(keyValue.getRow()) + " family :"
7781
+ new String(keyValue.getFamily()) + " columnQualifier:"
7882
+ new String(keyValue.getQualifier()) + " timestamp:"
@@ -86,6 +90,10 @@ PRIMARY KEY (`K`, `Q`, `T`)
8690
r = hTable.get(get);
8791
Assert.assertEquals(1, r.raw().length);
8892
for (KeyValue keyValue : r.raw()) {
93+
Assert.assertEquals(key, Bytes.toString(keyValue.getRow()));
94+
Assert.assertEquals(column1, Bytes.toString(keyValue.getQualifier()));
95+
Assert.assertEquals(timestamp, keyValue.getTimestamp());
96+
Assert.assertEquals(value + "1", Bytes.toString(keyValue.getValue()));
8997
System.out.println("rowKey: " + new String(keyValue.getRow()) + " family :"
9098
+ new String(keyValue.getFamily()) + " columnQualifier:"
9199
+ new String(keyValue.getQualifier()) + " timestamp:"
@@ -98,6 +106,10 @@ PRIMARY KEY (`K`, `Q`, `T`)
98106
ResultScanner scanner = hTable.getScanner(scan);
99107
for (Result result : scanner) {
100108
for (KeyValue keyValue : result.raw()) {
109+
Assert.assertEquals(key, Bytes.toString(keyValue.getRow()));
110+
Assert.assertEquals(column1, Bytes.toString(keyValue.getQualifier()));
111+
Assert.assertEquals(timestamp, keyValue.getTimestamp());
112+
Assert.assertEquals(value + "1", Bytes.toString(keyValue.getValue()));
101113
System.out.println("rowKey: " + new String(keyValue.getRow()) + " family :"
102114
+ new String(keyValue.getFamily()) + " columnQualifier:"
103115
+ new String(keyValue.getQualifier()) + " timestamp:"
@@ -135,7 +147,9 @@ private void testBasic(String family) throws Exception {
135147
+ new String(keyValue.getQualifier()) + " timestamp:"
136148
+ keyValue.getTimestamp() + " value:"
137149
+ new String(keyValue.getValue()));
150+
Assert.assertEquals(key, Bytes.toString(keyValue.getRow()));
138151
Assert.assertEquals(column1, Bytes.toString(keyValue.getQualifier()));
152+
Assert.assertEquals(timestamp, keyValue.getTimestamp());
139153
Assert.assertEquals(value, Bytes.toString(keyValue.getValue()));
140154
}
141155

@@ -161,15 +175,17 @@ private void testBasic(String family) throws Exception {
161175
+ new String(keyValue.getQualifier()) + " timestamp:"
162176
+ keyValue.getTimestamp() + " value:"
163177
+ new String(keyValue.getValue()));
178+
Assert.assertEquals(key, Bytes.toString(keyValue.getRow()));
164179
Assert.assertEquals(column1, Bytes.toString(keyValue.getQualifier()));
180+
Assert.assertEquals(timestamp + 1, keyValue.getTimestamp());
165181
Assert.assertEquals(value, Bytes.toString(keyValue.getValue()));
166182
}
167183

168184
try {
169185
for (int j = 0; j < 10; j++) {
170186
put = new Put((key + "_" + j).getBytes());
171-
put.add(family.getBytes(), column1.getBytes(), toBytes(value));
172-
put.add(family.getBytes(), column2.getBytes(), toBytes(value));
187+
put.add(family.getBytes(), column1.getBytes(), timestamp + 2, toBytes(value));
188+
put.add(family.getBytes(), column2.getBytes(), timestamp + 2, toBytes(value));
173189
hTable.put(put);
174190
}
175191

@@ -178,7 +194,7 @@ private void testBasic(String family) throws Exception {
178194
scan.addColumn(family.getBytes(), column2.getBytes());
179195
scan.setStartRow(toBytes(key + "_" + 0));
180196
scan.setStopRow(toBytes(key + "_" + 9));
181-
scan.setMaxVersions(9);
197+
scan.setMaxVersions(1);
182198
ResultScanner scanner = hTable.getScanner(scan);
183199
int i = 0;
184200
int count = 0;
@@ -192,6 +208,7 @@ private void testBasic(String family) throws Exception {
192208
Assert.assertEquals(key + "_" + i, Bytes.toString(keyValue.getRow()));
193209
Assert.assertTrue(column1.equals(Bytes.toString(keyValue.getQualifier()))
194210
|| column2.equals(Bytes.toString(keyValue.getQualifier())));
211+
Assert.assertEquals(timestamp + 2, keyValue.getTimestamp());
195212
Assert.assertEquals(value, Bytes.toString(keyValue.getValue()));
196213
if (countAdd) {
197214
countAdd = false;
@@ -205,6 +222,7 @@ private void testBasic(String family) throws Exception {
205222

206223
// scan.setBatch(1);
207224

225+
scan.setMaxVersions(9);
208226
scanner = hTable.getScanner(scan);
209227
i = 0;
210228
count = 0;

0 commit comments

Comments
 (0)