-
Notifications
You must be signed in to change notification settings - Fork 4
SQL: Query topics #574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kbatuigas
merged 11 commits into
rp-sql
from
DOC-1990-document-feature-query-redpanda-topics
May 23, 2026
+183
−17
Merged
SQL: Query topics #574
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bbc2cff
Start query RP topics doc
kbatuigas 545f2ca
DOC-1990: Move query directory and rewrite streaming-topics how-to
kbatuigas 48a30ca
Change rp connection to catalog
kbatuigas 96b0ff1
Add wire protocol option
kbatuigas 0c9d767
schema_subject required
kbatuigas dc49543
Review pass
kbatuigas 05e88bc
Review pass
kbatuigas 32d4833
Address review comments
kbatuigas 6523314
Add info on redpanda and redpanda_raw structs
kbatuigas 9cf7608
Review pass
kbatuigas 0f5aba1
Adjust column widths
kbatuigas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| = Query Data | ||
| :description: Query live and historical data in your Redpanda topics using standard PostgreSQL syntax. | ||
| :page-layout: index |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| = Query Streaming Topics | ||
| :description: Map a Redpanda topic to a SQL table and run analytical queries directly against live streaming data. | ||
| :page-topic-type: how-to | ||
| :personas: app_developer, data_engineer | ||
| :learning-objective-1: Map a Redpanda topic to a SQL table using the default Redpanda catalog | ||
| :learning-objective-2: Run analytical SQL queries against live topic data | ||
|
|
||
| Map a Redpanda topic to a SQL table to run analytical queries directly against live streaming data without building ETL pipelines. Redpanda SQL reads each record's fields from the topic's registered schema. | ||
|
|
||
| To extend queries past your Redpanda retention window by reading the Iceberg history of Iceberg-enabled topics, see xref:sql:query-data/query-iceberg-topics.adoc[Query Iceberg-enabled Topics]. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly @kbatuigas ! :) |
||
|
|
||
| Use this page to: | ||
|
|
||
| * [ ] {learning-objective-1} | ||
| * [ ] {learning-objective-2} | ||
|
|
||
| == Prerequisites | ||
|
|
||
| Before you query a topic with SQL: | ||
|
|
||
| * Enable the Redpanda SQL engine on your Redpanda Bring Your Own Cloud (BYOC) cluster. See xref:sql:get-started/deploy-sql-cluster.adoc[Enable Redpanda SQL]. | ||
| * Have a Redpanda Cloud user with the *SQL: Access* (or *SQL: Manage*) data-plane RBAC permission. For a *SQL: Access* user to query a topic, a *SQL: Manage* user must first `GRANT SELECT` on the topic to that user. See xref:sql:manage/manage-access.adoc[Manage access to Redpanda SQL]. | ||
| * Connect to Redpanda SQL with `psql` or another PostgreSQL client. See xref:sql:get-started/sql-quickstart.adoc[] for a `psql` example, or xref:sql:connect-to-sql/index.adoc[Connect to Redpanda SQL]. | ||
| * Confirm that the Redpanda topic you want to query has a schema registered in Schema Registry. Redpanda SQL supports Protobuf, JSON, and Avro schemas. | ||
|
|
||
| == Map the topic to a SQL table | ||
|
|
||
| Each Redpanda topic appears as a SQL table inside a Redpanda catalog. When Redpanda SQL is enabled, a catalog named `default_redpanda_catalog` is created automatically and points at your cluster. | ||
|
|
||
| Define a table against the topic with `CREATE TABLE`: | ||
|
|
||
| [source,sql] | ||
| ---- | ||
| CREATE TABLE default_redpanda_catalog=>orders WITH ( | ||
| topic = 'orders', | ||
| schema_subject = 'orders-value' | ||
| ); | ||
| ---- | ||
|
|
||
| Replace `orders` with your topic name and `orders-value` with the Schema Registry subject that holds the topic's value schema. `schema_subject` is optional. If omitted, Redpanda SQL uses the topic-name strategy default (`<topic>-value`). | ||
|
|
||
| If the topic uses a Protobuf schema that defines more than one message, also set `output_schema_message_full_name` to the fully-qualified name of the message to use: | ||
|
|
||
| [source,sql] | ||
| ---- | ||
| CREATE TABLE default_redpanda_catalog=>orders WITH ( | ||
| topic = 'orders', | ||
| schema_subject = 'orders-value', | ||
| output_schema_message_full_name = 'com.example.orders.Order' | ||
| ); | ||
| ---- | ||
|
|
||
| The table inherits its column definitions from the registered schema. Each top-level field in the schema becomes a SQL column. For querying nested fields in struct types, see xref:sql:query-data/query-nested-fields.adoc[]. | ||
|
|
||
| In addition to the columns derived from your topic's schema, Redpanda SQL adds two struct columns to every catalog-mapped table: | ||
|
|
||
| * `redpanda`: Kafka record metadata such as partition, offset, and timestamp. | ||
| * `redpanda_raw`: Populated only when `error_handling_policy = 'FILL_NULL'` and a record fails to decode. | ||
|
|
||
| For details, see xref:reference:sql/sql-statements/create-table.adoc#auto-added-columns[Auto-added columns]. | ||
|
|
||
| == Run queries | ||
|
|
||
| Query the table with standard `SELECT` syntax. The following query returns the first 10 records: | ||
|
|
||
| [source,sql] | ||
| ---- | ||
| SELECT * FROM default_redpanda_catalog=>orders LIMIT 10; | ||
| ---- | ||
|
|
||
| Aggregate and filter records using familiar PostgreSQL constructs: | ||
|
|
||
| [source,sql] | ||
| ---- | ||
| SELECT customer_id, SUM(amount) AS total | ||
| FROM default_redpanda_catalog=>orders | ||
| WHERE status = 'completed' | ||
| GROUP BY customer_id | ||
| ORDER BY total DESC | ||
| LIMIT 10; | ||
| ---- | ||
|
|
||
| == Next steps | ||
|
|
||
| * xref:sql:query-data/query-iceberg-topics.adoc[Query Iceberg-enabled Topics]: run queries against historical data retained beyond your Redpanda retention window. | ||
| * xref:reference:sql/sql-statements/create-table.adoc[CREATE TABLE]: full reference for the table-against-topic syntax, including all options. | ||
| * xref:reference:sql/index.adoc[Redpanda SQL Reference]: supported SQL statements, clauses, data types, and functions. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder where should we mention the existence of
redpandaandredpanda_rawstructs. The first is iceberg equivalent so allpartitionoffsetetc properties are there. The second is DLQ equivalent, filled whenFILL_NULLerror policy is setThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JacekGalazka1 do those only exist for Iceberg topics? There is mention of them in this other doc specifically for querying Iceberg https://github.com/redpanda-data/cloud-docs/pull/575/changes#diff-3ab2a15f947f028cb3f75cdb5184029657557cac26b1c961cb27c72554ba3533R83 Is redpanda_raw populated only when FILL_NULL is set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are always added to each kafka reader, so both pure kafka and iceberg backed will have it.
redpanda_raw is populated only when FILL_NULL is set and only for records that failed to decode. in all other cases it's NULL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JacekGalazka1 Added to CREATE TABLE: https://github.com/redpanda-data/cloud-docs/pull/574/changes#diff-4bce4f4f19fcf950f1034b3f3186de2e99bdfc3ba7d66276569d458e13dcec5eR76
and brief description on this page: https://github.com/redpanda-data/cloud-docs/pull/574/changes#diff-b3c7d2ada14afb120454cfcdba2a29f97af19440772908571bfc21ebd02f344fR55
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect. Good to go