-
Notifications
You must be signed in to change notification settings - Fork 26
[Rust] Add support to fetch schema from UC for dynamic proto #704
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
Open
andrijast-db
wants to merge
3
commits into
main
Choose a base branch
from
andrijast-db/effort/rust-dynamic-proto-fetch-from-uc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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,68 @@ | ||
| //! Dynamic protobuf ingestion with the schema fetched from Unity Catalog. | ||
| //! | ||
| //! Unlike `dynamic/single.rs`, which builds the descriptor in code, this fetches | ||
| //! it with `fetch_message_descriptor` and feeds it to the usual `.dynamic_proto(...)`. | ||
| //! | ||
| //! Throughput: ingest in a loop, then `flush()` once — never wait per record. | ||
|
|
||
| use std::error::Error; | ||
|
|
||
| use databricks_zerobus_ingest_sdk::{ProtoBytes, ZerobusSdk}; | ||
|
|
||
| // Change constants to match your data. | ||
| const TABLE_NAME: &str = "<your_table_name>"; | ||
| const DATABRICKS_CLIENT_ID: &str = "<your_databricks_client_id>"; | ||
| const DATABRICKS_CLIENT_SECRET: &str = "<your_databricks_client_secret>"; | ||
|
|
||
| // For AWS (for Azure, use *.azuredatabricks.net): | ||
| const DATABRICKS_WORKSPACE_URL: &str = "https://<your-workspace>.cloud.databricks.com"; | ||
| const SERVER_ENDPOINT: &str = "https://<your-shard-id>.zerobus.<region>.cloud.databricks.com"; | ||
|
|
||
| #[tokio::main] | ||
| async fn main() -> Result<(), Box<dyn Error>> { | ||
| // `unity_catalog_url` is required: it is where the schema is fetched from. | ||
| let sdk = ZerobusSdk::builder() | ||
| .endpoint(SERVER_ENDPOINT) | ||
| .unity_catalog_url(DATABRICKS_WORKSPACE_URL) | ||
| .build()?; | ||
|
|
||
| // Descriptor from live table metadata — no columns or `.proto` needed up front. | ||
| let descriptor = sdk | ||
| .fetch_message_descriptor(TABLE_NAME, DATABRICKS_CLIENT_ID, DATABRICKS_CLIENT_SECRET) | ||
| .await?; | ||
| println!( | ||
| "Fetched schema '{}' with {} fields", | ||
| descriptor.name(), | ||
| descriptor.fields().count() | ||
| ); | ||
|
|
||
| let mut stream = sdk | ||
| .stream_builder() | ||
| .table(TABLE_NAME) | ||
| .oauth(DATABRICKS_CLIENT_ID, DATABRICKS_CLIENT_SECRET) | ||
| .dynamic_proto(descriptor) | ||
| .build() | ||
| .await?; | ||
|
|
||
| // (customer_name, quantity, price) — adjust the field names to your table. | ||
| let orders = [("Alice Smith", 2i32, 25.99f64), ("Bob Johnson", 1, 89.99)]; | ||
| for (i, (customer_name, quantity, price)) in orders.iter().enumerate() { | ||
| // set()'s value must match the column's proto type (BIGINT -> i64, INT -> i32). | ||
| let mut record = stream.new_record()?; | ||
| record | ||
| .set("id", i as i64)? | ||
| .set("customer_name", *customer_name)? | ||
| .set("quantity", *quantity)? | ||
| .set("price", *price)?; | ||
| // Queue without waiting for the ack. | ||
| stream | ||
| .ingest_record_offset(ProtoBytes(record.encode()?)) | ||
| .await?; | ||
| } | ||
|
|
||
| stream.flush().await?; // wait once for all pending acks | ||
| stream.close().await?; | ||
| println!("Done"); | ||
|
|
||
| Ok(()) | ||
| } |
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
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
Oops, something went wrong.
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.
SchemaFetchErroris always non-retryable, so a connection reset, timeout, HTTP 429, or HTTP 503 tells callers to give up just like a bad request or missing table. The fetch site still has the transport error or status needed to make this distinction, butfetch_errorflattens it into a string. This also leaves the new tuple variant unable to gain retry metadata later without a breaking API change.Could we keep the classification in a non-exhaustive struct variant and set it where the underlying failure is available?
Transport failures, timeouts, HTTP 429, and HTTP 5xx can then be retryable while rejected requests and malformed bodies remain terminal. The current mock already accepts arbitrary schema statuses, so a 503 test can assert
is_retryable()istrueand the existing 404 case can assert it remainsfalse.