Skip to content

Add getSchema() to Records for schema access with empty results#2777

Merged
chernser merged 1 commit intoClickHouse:mainfrom
PierceAndy:feature/records-get-schema
Mar 5, 2026
Merged

Add getSchema() to Records for schema access with empty results#2777
chernser merged 1 commit intoClickHouse:mainfrom
PierceAndy:feature/records-get-schema

Conversation

@PierceAndy
Copy link
Contributor

@PierceAndy PierceAndy commented Mar 5, 2026

Summary

Add getSchema() method to Records class to enable access to table schema metadata even when query results are empty.

Following the pattern from PR #2004, this change exposes the TableSchema from the underlying ClickHouseBinaryFormatReader, making it consistent with GenericRecord.getSchema().

Use case: When queryRecords() or queryAll() returns no rows, users can still inspect column metadata (names, types, etc.) without needing to iterate through records.

Example:

Records records = client.queryRecords("SELECT * FROM table WHERE 1=0").get();
if (records.isEmpty()) {
    TableSchema schema = records.getSchema();
    schema.getColumns().forEach(col ->
        System.out.println(col.getColumnName() + ": " + col.getDataType())
    );
}

Checklist

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG

CHANGELOG entry:

* Add `Records.getSchema()` method to access table schema from query results, including empty result sets

Note

Low Risk
Low risk API addition that delegates to the existing binary reader schema with only new test coverage; minimal impact beyond adding a new method.

Overview
Adds Records.getSchema() to return the underlying TableSchema, enabling schema inspection even when Records.isEmpty() is true.

Extends QueryTests with integration coverage for getSchema() on both empty and non-empty result sets, and asserts records’ per-row schema matches the collection schema.

Written by Cursor Bugbot for commit ab709af. This will update automatically on new commits. Configure here.

Expose TableSchema from Records to enable access to column metadata even
when query results are empty
@CLAassistant
Copy link

CLAassistant commented Mar 5, 2026

CLA assistant check
All committers have signed the CLA.

@PierceAndy PierceAndy marked this pull request as ready for review March 5, 2026 06:10
@chernser
Copy link
Contributor

chernser commented Mar 5, 2026

@PierceAndy,

thank you for the contribution!

@chernser chernser merged commit df9692f into ClickHouse:main Mar 5, 2026
18 of 21 checks passed
@PierceAndy PierceAndy deleted the feature/records-get-schema branch March 6, 2026 01:18
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.

3 participants