Skip to content

Commit

Permalink
add an 'unqualified schemas' list to the configure options (#147)
Browse files Browse the repository at this point in the history
### What

Currently the configuration server will return table and view names
qualified with their schema, unless the schema is 'public'. In this PR
we make this option configurable - we provide the user with the option
to mention which schemas will not be qualified, with the default being
'public'.

This is an additive change, but the jsonschema changes obviously.

### How

Add a field to `ConfigureOptions` named `unqualified_schemas`, set its
default to be `["public"]`, and pass it as a parameter to the
configuration sql query.

Then fix the configuration tests.
  • Loading branch information
soupi committed Nov 6, 2023
1 parent d2b901d commit 830c593
Show file tree
Hide file tree
Showing 12 changed files with 2,139 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/connectors/ndc-postgres/src/configuration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ WITH
v ->> 'operatorName' AS operator_name,
v ->> 'exposedName' AS exposed_name
FROM
jsonb_array_elements($2) AS v
jsonb_array_elements($3) AS v
),

-- Constraints are recorded in 'pg_constraint', see
Expand Down Expand Up @@ -546,7 +546,7 @@ FROM
SELECT
jsonb_object_agg(
CASE
WHEN s.schema_name = 'public'
WHEN s.schema_name = ANY ($2)
THEN rel.relation_name
ELSE s.schema_name || '_' || rel.relation_name
END,
Expand Down
11 changes: 11 additions & 0 deletions crates/connectors/ndc-postgres/src/configuration/version1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ pub struct ConfigureOptions {
/// internal schemas of Postgres, Citus, Cockroach, and the PostGIS extension.
#[serde(default = "default_excluded_schemas")]
pub excluded_schemas: Vec<String>,
/// The names of Tables and Views in these schemas will be returned unqualified.
/// The default setting will set the `public` schema as unqualified.
#[serde(default = "default_unqualified_schemas")]
pub unqualified_schemas: Vec<String>,
/// The mapping of comparison operator names to apply when updating the configuration
#[serde(default = "default_comparison_operator_mapping")]
pub comparison_operator_mapping: Vec<ComparisonOperatorMapping>,
Expand All @@ -48,6 +52,7 @@ impl Default for ConfigureOptions {
fn default() -> ConfigureOptions {
ConfigureOptions {
excluded_schemas: default_excluded_schemas(),
unqualified_schemas: default_unqualified_schemas(),
comparison_operator_mapping: default_comparison_operator_mapping(),
}
}
Expand Down Expand Up @@ -171,6 +176,10 @@ fn default_excluded_schemas() -> Vec<String> {
]
}

fn default_unqualified_schemas() -> Vec<String> {
vec!["public".to_string()]
}

/// User configuration, elaborated from a 'RawConfiguration'.
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -240,6 +249,7 @@ impl RawConfiguration {
metadata: metadata::Metadata::default(),
configure_options: ConfigureOptions {
excluded_schemas: default_excluded_schemas(),
unqualified_schemas: default_unqualified_schemas(),
comparison_operator_mapping: default_comparison_operator_mapping(),
},
}
Expand Down Expand Up @@ -341,6 +351,7 @@ pub async fn configure(

let query = sqlx::query(configuration_query)
.bind(args.configure_options.excluded_schemas.clone())
.bind(args.configure_options.unqualified_schemas.clone())
.bind(
serde_json::to_value(args.configure_options.comparison_operator_mapping.clone())
.map_err(|e| connector::UpdateConfigurationError::Other(e.into()))?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ expression: generated_schema
"columnar",
"columnar_internal"
],
"unqualifiedSchemas": [
"public"
],
"comparisonOperatorMapping": [
{
"operatorName": "=",
Expand Down Expand Up @@ -509,6 +512,16 @@ expression: generated_schema
"type": "string"
}
},
"unqualifiedSchemas": {
"description": "The names of Tables and Views in these schemas will be returned unqualified. The default setting will set the `public` schema as unqualified.",
"default": [
"public"
],
"type": "array",
"items": {
"type": "string"
}
},
"comparisonOperatorMapping": {
"description": "The mapping of comparison operator names to apply when updating the configuration",
"default": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,9 @@ expression: default_configuration
"columnar",
"columnar_internal"
],
"unqualifiedSchemas": [
"public"
],
"comparisonOperatorMapping": [
{
"operatorName": "=",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ expression: schema
"columnar",
"columnar_internal"
],
"unqualifiedSchemas": [
"public"
],
"comparisonOperatorMapping": [
{
"operatorName": "=",
Expand Down Expand Up @@ -531,6 +534,16 @@ expression: schema
"type": "string"
}
},
"unqualifiedSchemas": {
"description": "The names of Tables and Views in these schemas will be returned unqualified. The default setting will set the `public` schema as unqualified.",
"default": [
"public"
],
"type": "array",
"items": {
"type": "string"
}
},
"comparisonOperatorMapping": {
"description": "The mapping of comparison operator names to apply when updating the configuration",
"default": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ expression: schema
"columnar",
"columnar_internal"
],
"unqualifiedSchemas": [
"public"
],
"comparisonOperatorMapping": [
{
"operatorName": "=",
Expand Down Expand Up @@ -519,6 +522,16 @@ expression: schema
"type": "string"
}
},
"unqualifiedSchemas": {
"description": "The names of Tables and Views in these schemas will be returned unqualified. The default setting will set the `public` schema as unqualified.",
"default": [
"public"
],
"type": "array",
"items": {
"type": "string"
}
},
"comparisonOperatorMapping": {
"description": "The mapping of comparison operator names to apply when updating the configuration",
"default": [
Expand Down
1 change: 1 addition & 0 deletions static/aurora/chinook-deployment-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,7 @@
"columnar",
"columnar_internal"
],
"unqualifiedSchemas": ["public"],
"comparisonOperatorMapping": [
{
"operatorName": "=",
Expand Down
1 change: 1 addition & 0 deletions static/citus/chinook-deployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -1816,6 +1816,7 @@
"columnar",
"columnar_internal"
],
"unqualifiedSchemas": ["public"],
"comparisonOperatorMapping": [
{
"operatorName": "=",
Expand Down
1 change: 1 addition & 0 deletions static/cockroach/chinook-deployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,7 @@
"columnar",
"columnar_internal"
],
"unqualifiedSchemas": ["public"],
"comparisonOperatorMapping": [
{
"operatorName": "=",
Expand Down
Loading

0 comments on commit 830c593

Please sign in to comment.