Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Risingwavelabs Risingwave PkComparator

From Leeroopedia
Revision as of 16:32, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Risingwavelabs_Risingwave_PkComparator.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Metadata

Property Value
File java/connector-node/connector-api/src/main/java/com/risingwave/connector/api/PkComparator.java
Language Java
Module connector-api
Package com.risingwave.connector.api
Classes PkComparator
Lines 43
Interfaces Implemented Comparator<List<Comparable<Object>>>

Overview

PkComparator implements the Comparator interface for comparing two lists of Comparable values, representing composite primary keys in the RisingWave connector framework. It performs a lexicographic comparison of the primary key columns, checking each column in order and returning the first non-zero comparison result.

If the two primary key lists have different lengths, the comparator throws a gRPC FAILED_PRECONDITION runtime exception, since mismatched primary key lengths indicate a data integrity issue.

Code Reference

Source Location

java/connector-node/connector-api/src/main/java/com/risingwave/connector/api/PkComparator.java

Signature

public class PkComparator implements Comparator<List<Comparable<Object>>> {
    @Override
    public int compare(List<Comparable<Object>> objects1, List<Comparable<Object>> objects2)
}

Imports

import io.grpc.Status;
import java.util.Comparator;
import java.util.List;

I/O Contract

compare

Parameter Type Description
objects1 List<Comparable<Object>> First composite primary key (list of column values)
objects2 List<Comparable<Object>> Second composite primary key (list of column values)
Direction Type Description
Output int Negative if objects1 < objects2, zero if equal, positive if objects1 > objects2

Error Handling:

  • Throws StatusRuntimeException with FAILED_PRECONDITION status if the two lists have different sizes, indicating a primary key length mismatch.

Algorithm:

  1. Verify both lists have the same length
  2. Iterate through each column index, comparing corresponding values
  3. Return the first non-zero comparison result
  4. If all columns are equal, return 0

Usage Examples

// Create a PkComparator instance
PkComparator comparator = new PkComparator();

// Compare two composite primary keys
List<Comparable<Object>> pk1 = Arrays.asList(castToComparable(1), castToComparable("abc"));
List<Comparable<Object>> pk2 = Arrays.asList(castToComparable(1), castToComparable("def"));

int result = comparator.compare(pk1, pk2);
// result < 0 because "abc" < "def"

// Can be used with sorting collections
TreeMap<List<Comparable<Object>>, SinkRow> sortedRows = new TreeMap<>(new PkComparator());

Related Pages

  • TableSchema - Provides primary key column information used with PkComparator
  • SinkRow Interface - The row interface whose primary key values are compared
  • SinkWriterV1 Interface - Sink writers that may use PkComparator for deduplication and upsert logic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment