Skip to content

feat(python): add get_primary_keys() method to Schema class #436

Merged
luoyuxia merged 5 commits into
apache:mainfrom
XiaoHongbo-Hope:support_primary_key
Mar 11, 2026
Merged

feat(python): add get_primary_keys() method to Schema class #436
luoyuxia merged 5 commits into
apache:mainfrom
XiaoHongbo-Hope:support_primary_key

Conversation

@XiaoHongbo-Hope

@XiaoHongbo-Hope XiaoHongbo-Hope commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

Purpose

Linked issue: close #384

Brief change log

Tests

API and Format

Documentation

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds Python-side introspection for Schema primary keys to close #384, aligning the Python bindings with existing functionality in the Rust core and the Python TableInfo API.

Changes:

  • Add Schema.get_primary_keys() to the PyO3 Python bindings (bindings/python/src/metadata.rs).
  • Add an integration assertion verifying Schema.get_primary_keys() returns the configured keys (bindings/python/test/test_admin.py).

Reviewed changes

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

File Description
bindings/python/src/metadata.rs Exposes primary key column names from the wrapped core Schema via get_primary_keys().
bindings/python/test/test_admin.py Adds a test assertion that a constructed Schema returns the expected primary key list.

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

Comment on lines +223 to +228
fn get_primary_keys(&self) -> Vec<String> {
self.__schema
.primary_key()
.map(|pk| pk.column_names().to_vec())
.unwrap_or_default()
}

Copilot AI Mar 8, 2026

Copy link

Choose a reason for hiding this comment

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

New Python API method Schema.get_primary_keys() is added in the PyO3 bindings, but the package type stubs (bindings/python/fluss/__init__.pyi) still define Schema without this method. This will leave typing users (mypy/IDE autocomplete) out of sync with runtime behavior; please update the stub to include def get_primary_keys(self) -> List[str]: ... for Schema.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

New Python API method Schema.get_primary_keys() is added in the PyO3 bindings, but the package type stubs (bindings/python/fluss/__init__.pyi) still define Schema without this method. This will leave typing users (mypy/IDE autocomplete) out of sync with runtime behavior; please update the stub to include def get_primary_keys(self) -> List[str]: ... for Schema.

Added

@@ -220,7 +220,12 @@ impl Schema {
.collect()
}

Copilot AI Mar 8, 2026

Copy link

Choose a reason for hiding this comment

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

Schema.get_primary_keys() is missing a Rust doc comment (/// ...) while the adjacent Schema methods have doc comments. Adding one keeps the generated Python docstrings/help output consistent across the API surface.

Suggested change
/// Get primary key column names

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Schema.get_primary_keys() is missing a Rust doc comment (/// ...) while the adjacent Schema methods have doc comments. Adding one keeps the generated Python docstrings/help output consistent across the API surface.

Suggested change
/// Get primary key column names

Added

@XiaoHongbo-Hope XiaoHongbo-Hope marked this pull request as draft March 8, 2026 10:10
@XiaoHongbo-Hope XiaoHongbo-Hope marked this pull request as ready for review March 8, 2026 10:47

@fresh-borzoni fresh-borzoni left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@XiaoHongbo-Hope Ty for the PR, LGTM

@charlesdong1991 charlesdong1991 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LTGM!

Nitpick: not sure if it is worth it to adding a small test to check it returns empty list when no primary key is present

@XiaoHongbo-Hope

Copy link
Copy Markdown
Contributor Author

LTGM!

Nitpick: not sure if it is worth it to adding a small test to check it returns empty list when no primary key is present

Thanks, added ut

@leekeiabstraction leekeiabstraction left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TY for the PR. Left a comment. PTAL!

def get_column_names(self) -> List[str]: ...
def get_column_types(self) -> List[str]: ...
def get_columns(self) -> List[Tuple[str, str]]: ...
def get_primary_keys(self) -> List[str]: ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should the website's api reference documentation be updated as well?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1

@luoyuxia

Copy link
Copy Markdown
Contributor

@XiaoHongbo-Hope Hi, I already push a commit to add the doc. Merging..

@luoyuxia luoyuxia merged commit 5b7f839 into apache:main Mar 11, 2026
6 checks passed
@XiaoHongbo-Hope

Copy link
Copy Markdown
Contributor Author

@XiaoHongbo-Hope Hi, I already push a commit to add the doc. Merging..

Thanks! Sorry for missing above comment for flood of CI messages with my github email...

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.

primary_key in python table schema

6 participants