Skip to content

Commit

Permalink
Add clip_geom,buffer under auto_publish conf
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkAndshark committed Sep 18, 2023
1 parent 56b819a commit 0235e1a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
6 changes: 6 additions & 0 deletions martin/src/pg/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ pub struct PgCfgPublishType {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(alias = "id_column")]
pub id_columns: Option<OneOrMany<String>>,

#[serde(skip_serializing_if = "Option::is_none")]
pub clip_geom: Option<bool>,

#[serde(skip_serializing_if = "Option::is_none")]
pub buffer: Option<u32>,
}

impl PgConfig {
Expand Down
15 changes: 14 additions & 1 deletion martin/src/pg/configurator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub struct PgBuilderAuto {
source_id_format: String,
schemas: Option<HashSet<String>>,
id_columns: Option<Vec<String>>,
clip_geom: Option<bool>,
buffer: Option<u32>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -63,7 +65,12 @@ impl PgBuilder {
// FIXME: this function has gotten too long due to the new formatting rules, need to be refactored
#[allow(clippy::too_many_lines)]
pub async fn instantiate_tables(&self) -> Result<(Sources, TableInfoSources)> {
let mut db_tables_info = query_available_tables(&self.pool).await?;
let (clip_geom, buffer) = if let Some(auto_tables) = &self.auto_tables {
(auto_tables.clip_geom, auto_tables.buffer)
} else {
(None, None)
};
let mut db_tables_info = query_available_tables(&self.pool, clip_geom, buffer).await?;

// Match configured sources with the discovered ones and add them to the pending list.
let mut used = HashSet::<(&str, &str, &str)>::new();
Expand Down Expand Up @@ -317,6 +324,8 @@ fn new_auto_publish(config: &PgConfig, is_function: bool) -> Option<PgBuilderAut
source_id_format: default_id_fmt(is_function),
schemas,
id_columns: None,
clip_geom: None,
buffer: None,
})
};

Expand All @@ -339,6 +348,8 @@ fn new_auto_publish(config: &PgConfig, is_function: bool) -> Option<PgBuilderAut
Some(ids.iter().cloned().collect())
}
}),
clip_geom: item.clip_geom,
buffer: item.buffer,
}),
BoolOrObject::Bool(true) => default(merge_opt_hs(&a.from_schemas, &None)),
BoolOrObject::Bool(false) => None,
Expand Down Expand Up @@ -420,6 +431,8 @@ mod tests {
source_id_format: source_id_format.to_string(),
schemas: schemas.map(|s| s.iter().map(|s| (*s).to_string()).collect()),
id_columns: None,
clip_geom: None,
buffer: None,
})
}

Expand Down
10 changes: 7 additions & 3 deletions martin/src/pg/table_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ static DEFAULT_EXTENT: u32 = 4096;
static DEFAULT_BUFFER: u32 = 64;
static DEFAULT_CLIP_GEOM: bool = true;

pub async fn query_available_tables(pool: &PgPool) -> Result<SqlTableInfoMapMapMap> {
pub async fn query_available_tables(
pool: &PgPool,
clip_geom: Option<bool>,
buffer: Option<u32>,
) -> Result<SqlTableInfoMapMapMap> {
let conn = pool.get().await?;
let rows = conn
.query(include_str!("scripts/query_available_tables.sql"), &[])
Expand Down Expand Up @@ -55,8 +59,8 @@ pub async fn query_available_tables(pool: &PgPool) -> Result<SqlTableInfoMapMapM
maxzoom: None,
srid: row.get("srid"), // casting i32 to u32?
extent: Some(DEFAULT_EXTENT),
buffer: Some(DEFAULT_BUFFER),
clip_geom: Some(DEFAULT_CLIP_GEOM),
buffer: Some(buffer.unwrap_or(DEFAULT_BUFFER)),
clip_geom: Some(clip_geom.unwrap_or(DEFAULT_CLIP_GEOM)),
geometry_type: row.get("type"),
properties: Some(json_to_hashmap(&row.get("properties"))),
prop_mapping: HashMap::new(),
Expand Down

0 comments on commit 0235e1a

Please sign in to comment.