Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
BREAKING:
* srid is now the same type as PG -- i32
* renamed config vals `table_sources` and `function_sources` into `tables` and `functions`

Fixes:
* predictable order of instantiation
* bounding boxes computed in parallel for all tables (when not configured)
* split up discovery and query creation - this way user overrides happen before the final query is generated
* more proper name escaping
* lots of test improvements
  • Loading branch information
nyurik committed Dec 4, 2022
1 parent b3f384c commit 31cfd47
Show file tree
Hide file tree
Showing 15 changed files with 620 additions and 490 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ tilejson = "0.3"
[dev-dependencies]
ctor = "0.1"
indoc = "1"
#test-log = "0.2"

[dev-dependencies.criterion]
version = "0.4.0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ pool_size: 20
worker_processes: 8

# Associative arrays of table sources
table_sources:
tables:
table_source_id:
# Table schema (required)
schema: public
Expand Down Expand Up @@ -512,7 +512,7 @@ table_sources:
gid: int4

# Associative arrays of function sources
function_sources:
functions:
function_source_id:
# Schema name (required)
schema: public
Expand Down
6 changes: 3 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ bench: start-db
test: test-unit test-int

# Run Rust unit and doc tests (cargo test)
test-unit: start-db
cargo test --all-targets
cargo test --all-targets --all-features
test-unit *ARGS: start-db
cargo test --all-targets {{ARGS}}
cargo test --all-targets --all-features {{ARGS}}
cargo test --doc

# Run integration tests
Expand Down
8 changes: 4 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ mod tests {
pool_size: 20
worker_processes: 8
table_sources:
tables:
table_source:
schema: public
table: table_source
Expand All @@ -106,7 +106,7 @@ mod tests {
properties:
gid: int4
function_sources:
functions:
function_zxy_query:
schema: public
function: function_zxy_query
Expand All @@ -133,7 +133,7 @@ mod tests {
pool_size: 20,
discover_functions: false,
discover_tables: false,
table_sources: HashMap::from([(
tables: HashMap::from([(
"table_source".to_string(),
TableInfo {
schema: "public".to_string(),
Expand All @@ -152,7 +152,7 @@ mod tests {
unrecognized: HashMap::new(),
},
)]),
function_sources: HashMap::from([(
functions: HashMap::from([(
"function_zxy_query".to_string(),
FunctionInfo::new_extended(
"public".to_string(),
Expand Down
58 changes: 19 additions & 39 deletions src/pg/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct TableInfo {
pub table: String,

/// Geometry SRID
pub srid: u32,
pub srid: i32,

/// Geometry column name
pub geometry_column: String,
Expand Down Expand Up @@ -98,23 +98,6 @@ impl PgInfo for TableInfo {
}
}

#[derive(Clone, Debug)]
pub struct PgSqlInfo {
pub query: String,
pub has_query_params: bool,
pub signature: String,
}

impl PgSqlInfo {
pub fn new(query: String, has_query_params: bool, signature: String) -> Self {
Self {
query,
has_query_params,
signature,
}
}
}

pub trait PgInfo {
fn format_id(&self) -> String;
fn to_tilejson(&self) -> TileJSON;
Expand Down Expand Up @@ -190,12 +173,9 @@ impl PgInfo for FunctionInfo {
}
}

pub type TableInfoSources = HashMap<String, TableInfo>;
pub type FuncInfoSources = HashMap<String, FunctionInfo>;
pub type InfoMap<T> = HashMap<String, T>;
pub type SqlFuncInfoMapMap = HashMap<String, HashMap<String, (PgSqlInfo, FunctionInfo)>>;
pub type SqlTableInfoMapMapMap =
HashMap<String, HashMap<String, HashMap<String, (PgSqlInfo, TableInfo)>>>;
pub type TableInfoSources = InfoMap<TableInfo>;
pub type FuncInfoSources = InfoMap<FunctionInfo>;

#[derive(Clone, Debug, Serialize, PartialEq)]
pub struct PgConfig {
Expand All @@ -212,8 +192,8 @@ pub struct PgConfig {
pub discover_functions: bool,
#[serde(skip_serializing)]
pub discover_tables: bool,
pub table_sources: TableInfoSources,
pub function_sources: FuncInfoSources,
pub tables: TableInfoSources,
pub functions: FuncInfoSources,
}

#[derive(Debug, Default, PartialEq, Deserialize)]
Expand All @@ -225,8 +205,8 @@ pub struct PgConfigBuilder {
pub danger_accept_invalid_certs: Option<bool>,
pub default_srid: Option<i32>,
pub pool_size: Option<u32>,
pub table_sources: Option<TableInfoSources>,
pub function_sources: Option<FuncInfoSources>,
pub tables: Option<TableInfoSources>,
pub functions: Option<FuncInfoSources>,
}

impl PgConfigBuilder {
Expand All @@ -241,21 +221,21 @@ impl PgConfigBuilder {
);
set_option(&mut self.default_srid, other.default_srid);
set_option(&mut self.pool_size, other.pool_size);
set_option(&mut self.table_sources, other.table_sources);
set_option(&mut self.function_sources, other.function_sources);
set_option(&mut self.tables, other.tables);
set_option(&mut self.functions, other.functions);
self
}

/// Apply defaults to the config, and validate if there is a connection string
pub fn finalize(self) -> io::Result<PgConfig> {
if let Some(ref ts) = self.table_sources {
if let Some(ref ts) = self.tables {
for (k, v) in ts {
report_unrecognized_config(&format!("table_sources.{}.", k), &v.unrecognized);
report_unrecognized_config(&format!("tables.{}.", k), &v.unrecognized);
}
}
if let Some(ref fs) = self.function_sources {
if let Some(ref fs) = self.functions {
for (k, v) in fs {
report_unrecognized_config(&format!("function_sources.{}.", k), &v.unrecognized);
report_unrecognized_config(&format!("functions.{}.", k), &v.unrecognized);
}
}
let connection_string = self.connection_string.ok_or_else(|| {
Expand All @@ -272,10 +252,10 @@ impl PgConfigBuilder {
danger_accept_invalid_certs: self.danger_accept_invalid_certs.unwrap_or_default(),
default_srid: self.default_srid,
pool_size: self.pool_size.unwrap_or(POOL_SIZE_DEFAULT),
discover_functions: self.table_sources.is_none() && self.function_sources.is_none(),
discover_tables: self.table_sources.is_none() && self.function_sources.is_none(),
table_sources: self.table_sources.unwrap_or_default(),
function_sources: self.function_sources.unwrap_or_default(),
discover_functions: self.tables.is_none() && self.functions.is_none(),
discover_tables: self.tables.is_none() && self.functions.is_none(),
tables: self.tables.unwrap_or_default(),
functions: self.functions.unwrap_or_default(),
})
}
}
Expand Down Expand Up @@ -306,8 +286,8 @@ impl From<(PgArgs, Option<String>)> for PgConfigBuilder {
})
}),
pool_size: args.pool_size,
table_sources: None,
function_sources: None,
tables: None,
functions: None,
}
}
}
Loading

0 comments on commit 31cfd47

Please sign in to comment.