-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce well-known URIs `flow://write-schema` and `flow://inferred-schema` which are available to collection read schemas. These URIs may be `$ref`'d from within a read schema, and having done so, their definitions are inlined into the effective read schema of the built collection with every publication. Extend the `validation::ControlPlane` trait to enable resolution of collections to their current inferred schemas. Implement within `flowctl` through our API, and within `agent` via out-of-transaction SQL lookups done using the agent's Postgres pool. Update the `agent` discovers handler to map the existing `x-infer-schema: true` annotation into a synthesized initial read schema, that composes the write & inferred schemas. Issue #1103
- Loading branch information
1 parent
2e36b11
commit 28b021e
Showing
30 changed files
with
899 additions
and
166 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -752,6 +752,7 @@ mod test { | |
"", | ||
&bs_url, | ||
&logs_tx, | ||
None, | ||
); | ||
|
||
let mut results: Vec<ScenarioResult> = vec![]; | ||
|
This file contains 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,62 @@ | ||
use futures::{FutureExt, TryFutureExt}; | ||
|
||
#[derive(Clone)] | ||
pub struct ControlPlane { | ||
pool: Option<sqlx::PgPool>, | ||
} | ||
|
||
impl ControlPlane { | ||
pub fn new(pool: Option<&sqlx::PgPool>) -> Self { | ||
Self { | ||
pool: pool.cloned(), | ||
} | ||
} | ||
} | ||
|
||
impl validation::ControlPlane for ControlPlane { | ||
fn resolve_collections<'a>( | ||
&'a self, | ||
collections: Vec<models::Collection>, | ||
) -> futures::future::BoxFuture<'a, anyhow::Result<Vec<proto_flow::flow::CollectionSpec>>> { | ||
let Some(pool) = self.pool.clone() else { | ||
return validation::NoOpControlPlane.resolve_collections(collections) | ||
}; | ||
let collections = collections.into_iter().map(Into::into).collect(); | ||
|
||
agent_sql::publications::resolve_collections(collections, pool) | ||
.map_err(Into::into) | ||
.map_ok(|rows| { | ||
rows.into_iter() | ||
.filter_map(|row| row.built_spec.map(|s| s.0)) | ||
.collect() | ||
}) | ||
.boxed() | ||
} | ||
|
||
fn get_inferred_schemas<'a>( | ||
&'a self, | ||
collections: Vec<models::Collection>, | ||
) -> futures::future::BoxFuture< | ||
'a, | ||
anyhow::Result<std::collections::BTreeMap<models::Collection, models::Schema>>, | ||
> { | ||
let Some(pool) = self.pool.clone() else { | ||
return validation::NoOpControlPlane.get_inferred_schemas(collections) | ||
}; | ||
let collections = collections.into_iter().map(Into::into).collect(); | ||
|
||
agent_sql::publications::get_inferred_schemas(collections, pool) | ||
.map_err(Into::into) | ||
.map_ok(|rows| { | ||
rows.into_iter() | ||
.map(|row| { | ||
( | ||
models::Collection::new(row.collection_name), | ||
models::Schema::new(row.schema.0.into()), | ||
) | ||
}) | ||
.collect() | ||
}) | ||
.boxed() | ||
} | ||
} |
This file contains 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.