Skip to content

Commit cd33fd3

Browse files
fix(getRange): cannot support multiple pk (#8)
Signed-off-by: Kevin Cui <bh@bugs.cc> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent a235f0c commit cd33fd3

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,20 @@ const result = await batchWriteRow.do({
193193
Query rows within a range of primary keys.
194194

195195
```typescript
196-
import { GetRange, Direction } from "alicloud-tablestore";
196+
import { GetRange, Direction, INF_MIN, INF_MAX } from "alicloud-tablestore";
197197

198198
const getRange = new GetRange(client);
199199
const result = await getRange.do({
200200
tableName: "users",
201201
direction: Direction.FORWARD, // or Direction.BACKWARD
202-
inclusiveStartPrimaryKey: createPrimaryKey("id", "100"),
203-
exclusiveEndPrimaryKey: createPrimaryKey("id", "200"),
202+
inclusiveStartPrimaryKey: [
203+
createPrimaryKey("id", "100"),
204+
createPrimaryKey("age", INF_MIN),
205+
],
206+
exclusiveEndPrimaryKey: [
207+
createPrimaryKey("id", "200"),
208+
createPrimaryKey("age", INF_MAX),
209+
],
204210
limit: 100,
205211
maxVersions: 1,
206212
});

src/const.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ export const OTS_API_NAME = {
2222
BatchGetRow: "BatchGetRow",
2323
BatchWriteRow: "BatchWriteRow",
2424
} as const;
25+
26+
export const INF_MIN = {};
27+
export const INF_MAX = {};

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ export {
33
} from "./client";
44

55
export {
6+
INF_MAX,
7+
INF_MIN,
68
OTS_API_NAME,
79
} from "./const";
810

src/operator/get-range.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export interface GetRangeData {
1818
timeRange?: TimeRange;
1919
maxVersions?: number;
2020
limit?: number;
21-
inclusiveStartPrimaryKey: PlainBufferCell;
22-
exclusiveEndPrimaryKey: PlainBufferCell;
21+
inclusiveStartPrimaryKey: PlainBufferCell[];
22+
exclusiveEndPrimaryKey: PlainBufferCell[];
2323
filter?: Filter;
2424
startColumn?: string;
2525
endColumn?: string;
@@ -40,11 +40,11 @@ export class GetRange {
4040
tableName: options.tableName,
4141
direction: options.direction,
4242
inclusiveStartPrimaryKey: Buffer.from(encodePlainBuffer([{
43-
primaryKey: [fixPlainBufferCellType(options.inclusiveStartPrimaryKey)],
43+
primaryKey: options.inclusiveStartPrimaryKey.map(fixPlainBufferCellType),
4444
attributes: [],
4545
}])),
4646
exclusiveEndPrimaryKey: Buffer.from(encodePlainBuffer([{
47-
primaryKey: [fixPlainBufferCellType(options.exclusiveEndPrimaryKey)],
47+
primaryKey: options.exclusiveEndPrimaryKey.map(fixPlainBufferCellType),
4848
attributes: [],
4949
}])),
5050
};

src/utils.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
import type { PlainBufferCell, VariantType } from "./plainbuffer";
2-
import { inferVariantType } from "./plainbuffer";
1+
import type { PlainBufferCell } from "./plainbuffer";
2+
import { INF_MAX, INF_MIN } from "./const";
3+
import { inferVariantType, VariantType } from "./plainbuffer";
34

45
export function fixPlainBufferCellType(cell: PlainBufferCell): PlainBufferCell {
56
if (cell.type) {
67
return cell;
78
}
89

10+
if (cell.value === INF_MIN) {
11+
return { ...cell, type: VariantType.INF_MIN };
12+
}
13+
if (cell.value === INF_MAX) {
14+
return { ...cell, type: VariantType.INF_MAX };
15+
}
16+
917
cell.type = inferVariantType(cell.value).type;
1018
return cell;
1119
}

0 commit comments

Comments
 (0)