Skip to content

fix(getRange): cannot support multiple pk#8

Merged
BlackHole1 merged 3 commits intomainfrom
fix-get-range
Nov 6, 2025
Merged

fix(getRange): cannot support multiple pk#8
BlackHole1 merged 3 commits intomainfrom
fix-get-range

Conversation

@BlackHole1
Copy link
Member

No description provided.

Copilot AI review requested due to automatic review settings November 6, 2025 10:19
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 6, 2025

Warning

Rate limit exceeded

@BlackHole1 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 44 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 503dfb1 and c58297f.

📒 Files selected for processing (5)
  • README.md (1 hunks)
  • src/const.ts (1 hunks)
  • src/index.ts (1 hunks)
  • src/operator/get-range.ts (2 hunks)
  • src/utils.ts (1 hunks)

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Summary by CodeRabbit

  • New Features

    • Introduced INF_MIN and INF_MAX constants for specifying infinite range boundaries in range queries.
    • GetRange now supports array-based primary key ranges for multi-dimensional queries.
  • Documentation

    • Updated GetRange usage examples to reflect new range boundary specifications.

Walkthrough

This change introduces support for infinite boundary constants (INF_MIN and INF_MAX) for range query operations. Two new constants are added to the public API as empty objects. The GetRangeData interface is updated to accept arrays of primary key components for inclusiveStartPrimaryKey and exclusiveEndPrimaryKey instead of single values. Internal logic in fixPlainBufferCellType is modified to recognize and handle these infinity constants when inferring variant types. Documentation is updated to demonstrate the new usage pattern with array-based boundaries combined with infinity constants.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Interface breaking changes: GetRangeData.inclusiveStartPrimaryKey and exclusiveEndPrimaryKey change from single PlainBufferCell to PlainBufferCell[] arrays — verify this change is intentional and all calling code is updated accordingly
  • Type inference logic: Review the new conditional logic in fixPlainBufferCellType that checks for INF_MIN/INF_MAX equivalence and how it interacts with inferVariantType fallback
  • Constant definitions: Verify that INF_MIN and INF_MAX empty objects are the correct representations and that they correctly compare with cell values in fixPlainBufferCellType
  • Encoding changes: Confirm that the mapping of primaryKey arrays through fixPlainBufferCellType maintains correct semantics for both boundaries

Pre-merge checks

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to assess whether any description relates to the changeset. Add a description explaining the motivation, implementation details, and any breaking changes related to converting primary keys from single values to arrays.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the required format '(): ' and clearly describes the main change: fixing getRange to support multiple primary keys instead of single ones.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the GetRange operation to support composite primary keys with infinity bounds. The key changes include:

  • Introduced INF_MIN and INF_MAX constants for specifying infinite bounds in range queries
  • Updated GetRange to accept arrays of primary key cells instead of single cells
  • Enhanced type inference to properly handle infinity values

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/const.ts Adds INF_MIN and INF_MAX constants as empty objects to represent infinity bounds
src/index.ts Exports the new INF_MIN and INF_MAX constants
src/plainbuffer.ts Imports infinity constants (unused in diff but needed for future logic)
src/utils.ts Updates fixPlainBufferCellType to detect infinity constants and assign correct VariantType
src/operator/get-range.ts Changes primary key parameters from single cell to arrays, imports VariantType
README.md Updates documentation with example showing composite primary keys using infinity bounds
Comments suppressed due to low confidence (2)

src/operator/get-range.ts:8

  • Unused import VariantType.
import { decodePlainBuffer, encodePlainBuffer, VariantType } from "../plainbuffer";

src/plainbuffer.ts:1

  • Unused imports INF_MAX, INF_MIN.
import { INF_MAX, INF_MIN } from "./const";

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

README.md Outdated
inclusiveStartPrimaryKey: createPrimaryKey("id", "100"),
exclusiveEndPrimaryKey: createPrimaryKey("id", "200"),
inclusiveStartPrimaryKey: [
createPrimaryKey("id", "100")
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma after createPrimaryKey('id', '100') in the array literal.

Suggested change
createPrimaryKey("id", "100")
createPrimaryKey("id", "100"),

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +2
import { INF_MAX, INF_MIN } from "./const";

Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The imported constants INF_MIN and INF_MAX are not used in this file. The actual logic to handle these constants exists in src/utils.ts. Consider removing this unused import or add a comment explaining why it's needed for future use.

Suggested change
import { INF_MAX, INF_MIN } from "./const";

Copilot uses AI. Check for mistakes.
import { OTS_API_NAME } from "../const";
import { builder } from "../pb/builder";
import { decodePlainBuffer, encodePlainBuffer } from "../plainbuffer";
import { decodePlainBuffer, encodePlainBuffer, VariantType } from "../plainbuffer";
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The imported VariantType is not used in this file. Consider removing it from the import statement.

Suggested change
import { decodePlainBuffer, encodePlainBuffer, VariantType } from "../plainbuffer";
import { decodePlainBuffer, encodePlainBuffer } from "../plainbuffer";

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
src/const.ts (1)

26-27: Add documentation and freeze sentinel constants.

These sentinel constants should be immutable and documented. Consider applying Object.freeze() to prevent accidental mutation and adding JSDoc comments to explain their purpose in multi-key range queries.

Apply this diff:

+/**
+ * Sentinel value representing negative infinity for range query boundaries.
+ * Use this with GetRange to specify an unbounded lower limit on a primary key component.
+ */
-export const INF_MIN = {};
+export const INF_MIN = Object.freeze({});
+
+/**
+ * Sentinel value representing positive infinity for range query boundaries.
+ * Use this with GetRange to specify an unbounded upper limit on a primary key component.
+ */
-export const INF_MAX = {};
+export const INF_MAX = Object.freeze({});
src/operator/get-range.ts (1)

21-22: Breaking change correctly implements multi-key range support.

The change from single PlainBufferCell to PlainBufferCell[] properly enables composite primary key ranges. Consider adding validation to ensure arrays are non-empty, and JSDoc comments to clarify the multi-key capability.

Optional: Add validation in the builder method to prevent empty arrays:

public static async builder(options: GetRangeData) {
    if (!options.inclusiveStartPrimaryKey.length || !options.exclusiveEndPrimaryKey.length) {
        throw new Error("Primary key arrays cannot be empty");
    }
    // ... rest of the method
}

And consider adding JSDoc to the interface:

 export interface GetRangeData {
     tableName: string;
     direction: typeof Direction[keyof typeof Direction];
     columnsToGet?: string[];
     timeRange?: TimeRange;
     maxVersions?: number;
     limit?: number;
+    /** Array of primary key components defining the inclusive start boundary. Use INF_MIN for unbounded lower limits. */
     inclusiveStartPrimaryKey: PlainBufferCell[];
+    /** Array of primary key components defining the exclusive end boundary. Use INF_MAX for unbounded upper limits. */
     exclusiveEndPrimaryKey: PlainBufferCell[];
     filter?: Filter;
     startColumn?: string;
     endColumn?: string;
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 799830e and 81e0791.

📒 Files selected for processing (6)
  • README.md (1 hunks)
  • src/const.ts (1 hunks)
  • src/index.ts (1 hunks)
  • src/operator/get-range.ts (3 hunks)
  • src/plainbuffer.ts (1 hunks)
  • src/utils.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/operator/get-range.ts (2)
src/plainbuffer.ts (2)
  • PlainBufferCell (653-653)
  • encodePlainBuffer (651-651)
src/utils.ts (1)
  • fixPlainBufferCellType (5-19)
src/utils.ts (2)
src/plainbuffer.ts (2)
  • PlainBufferCell (653-653)
  • VariantType (656-656)
src/const.ts (2)
  • INF_MIN (26-26)
  • INF_MAX (27-27)
src/const.ts (1)
src/index.ts (2)
  • INF_MIN (7-7)
  • INF_MAX (6-6)
🪛 GitHub Actions: PR
src/operator/get-range.ts

[error] 8-8: ESLint: 'VariantType' is defined but never used. (unused-imports/no-unused-imports)

src/plainbuffer.ts

[error] 1-1: ESLint: 'INF_MAX' is defined but never used. (unused-imports/no-unused-imports)


[error] 1-1: ESLint: 'INF_MIN' is defined but never used. (unused-imports/no-unused-imports)

🔇 Additional comments (3)
src/index.ts (1)

6-7: LGTM! Public API appropriately extended.

The addition of INF_MAX and INF_MIN to the public exports correctly supports the new multi-key range boundary feature for GetRange operations.

src/utils.ts (1)

1-19: LGTM! Sentinel value handling correctly implemented.

The addition of INF_MIN and INF_MAX checks using reference equality (===) is the correct approach for object-based sentinels. The logic properly handles these special values before falling back to type inference, maintaining backward compatibility.

src/operator/get-range.ts (1)

43-47: LGTM! Array mapping correctly processes multi-key boundaries.

The .map(fixPlainBufferCellType) approach correctly processes each primary key component, ensuring proper type inference and INF sentinel handling for composite keys.

Copilot AI review requested due to automatic review settings November 6, 2025 10:24
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +26 to +27
export const INF_MIN = {};
export const INF_MAX = {};
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The INF_MIN and INF_MAX constants are defined as empty objects {}, but the PlainBufferCell interface only allows value to be bigint | number | boolean | string | Uint8Array. This creates a type mismatch that TypeScript should flag. Additionally, using object identity (===) for sentinel values can be fragile. Consider using unique symbols instead:

export const INF_MIN = Symbol('INF_MIN');
export const INF_MAX = Symbol('INF_MAX');

This would provide type safety and clear semantic intent while maintaining reference equality checks.

Suggested change
export const INF_MIN = {};
export const INF_MAX = {};
export const INF_MIN = Symbol('INF_MIN');
export const INF_MAX = Symbol('INF_MAX');

Copilot uses AI. Check for mistakes.
Comment on lines +25 to +26

export const INF_MIN = {};
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing documentation for the exported INF_MIN and INF_MAX constants. These are special sentinel values used in range queries and should be documented to explain their purpose (e.g., "Sentinel value representing negative infinity for range query bounds" and "Sentinel value representing positive infinity for range query bounds").

Suggested change
export const INF_MIN = {};
/**
* Sentinel value representing negative infinity for range query bounds.
* Use this as the lower bound in range queries to indicate no minimum.
*/
export const INF_MIN = {};
/**
* Sentinel value representing positive infinity for range query bounds.
* Use this as the upper bound in range queries to indicate no maximum.
*/

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +2
import type { PlainBufferCell } from "./plainbuffer";
import { INF_MAX, INF_MIN } from "./const";
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import order should follow a consistent pattern. Consider grouping imports by source: type imports first, then value imports from the same module. The current order has PlainBufferCell (type) imported from "./plainbuffer", then imports from "./const", then more imports from "./plainbuffer". Suggest reordering to:

import { INF_MAX, INF_MIN } from "./const";
import type { PlainBufferCell } from "./plainbuffer";
import { inferVariantType, VariantType } from "./plainbuffer";
Suggested change
import type { PlainBufferCell } from "./plainbuffer";
import { INF_MAX, INF_MIN } from "./const";
import { INF_MAX, INF_MIN } from "./const";
import type { PlainBufferCell } from "./plainbuffer";

Copilot uses AI. Check for mistakes.
import { OTS_API_NAME } from "../const";
import { builder } from "../pb/builder";
import { decodePlainBuffer, encodePlainBuffer } from "../plainbuffer";
import { decodePlainBuffer, encodePlainBuffer, VariantType } from "../plainbuffer";
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import VariantType.

Suggested change
import { decodePlainBuffer, encodePlainBuffer, VariantType } from "../plainbuffer";
import { decodePlainBuffer, encodePlainBuffer } from "../plainbuffer";

Copilot uses AI. Check for mistakes.
BlackHole1 and others added 3 commits November 6, 2025 18:41
Signed-off-by: Kevin Cui <bh@bugs.cc>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Kevin Cui <bh@bugs.cc>
@BlackHole1 BlackHole1 merged commit cd33fd3 into main Nov 6, 2025
2 checks passed
@BlackHole1 BlackHole1 deleted the fix-get-range branch November 6, 2025 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants