Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions martin/src/config/file/tiles/postgres/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,17 @@ fn warn_on_rename(old_id: &String, new_id: &String, typ: &str) {
}

fn summary(info: &TableInfo) -> String {
let relkind = match info.is_view {
Some(true) => "view",
_ => "table",
let long_relkind = match info.relkind {
Some('v') => "view".to_string(),
Some('m') => "materialized view".to_string(),
Some('r') => "table".to_string(),
// if we get to any of below lines, this is likely a bug
Some(r) => format!("unknown relkind={r}"),
None => "unknown relkind".to_string(),
};
// TODO: add column_id to the summary if it is set
format!(
"{relkind} {}.{} with {} column ({}, SRID={})",
"{long_relkind} {}.{} with {} column ({}, SRID={})",
info.schema,
info.table,
info.geometry_column,
Expand Down
9 changes: 6 additions & 3 deletions martin/src/config/file/tiles/postgres/config_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ pub struct TableInfo {
#[serde(skip)]
pub geometry_index: Option<bool>,

/// Flag indicating if table is actually a view (`PostgreSQL relkind = 'v'`)
/// Flag indicating the `PostgreSQL relkind`:
/// - `"t"`: Table
/// - `"v"`: View
/// - `"m"`: Materialized View
#[serde(skip)]
pub is_view: Option<bool>,
pub relkind: Option<char>,

/// Feature id column name
pub id_column: Option<String>,
Expand Down Expand Up @@ -131,7 +134,7 @@ impl TableInfo {
geometry_column: self.geometry_column.clone(),
// These values are not serialized, so copy auto-detected values from the database
geometry_index: self.geometry_index,
is_view: self.is_view,
relkind: self.relkind.clone(),
tilejson: self.tilejson.clone(),
// Srid requires some logic
srid: self.calc_srid(new_id, cfg_inf.srid, default_srid)?,
Expand Down
11 changes: 7 additions & 4 deletions martin/src/config/file/tiles/postgres/resolver/query_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,25 @@ pub async fn query_available_tables(pool: &PostgresPool) -> PostgresResult<SqlTa
None
};

let relkind: Option<i8> = row.get("relkind");
let info = TableInfo {
schema,
table,
geometry_column: row.get("geom"),
geometry_index: row.get("geom_idx"),
is_view: row.get("is_view"),
relkind: relkind
.map(|r| u8::try_from(r).ok().map(char::from))
.flatten(),
srid: row.get("srid"), // casting i32 to u32?
geometry_type: row.get("type"),
properties: Some(serde_json::from_value(row.get("properties")).unwrap()),
tilejson,
..Default::default()
};

// Warn for missing geometry indices. Ignore views since those can't have indices
// and will generally refer to table columns.
if let (Some(false), Some(false)) = (info.geometry_index, info.is_view) {
// Warn for missing geometry indices.
// Ignore views since those can't have indices and will generally refer to table columns.
if info.geometry_index == Some(false) && info.relkind != Some('v') {
warn!(
"Table {}.{} has no spatial index on column {}",
info.schema, info.table, info.geometry_column
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ annotated_geometry_columns AS (
geometry_columns.srid,
geometry_columns.type,
-- 'geometry' AS column_type
coalesce(cls.relkind = 'v', false) AS is_view,
cls.relkind,
bool_or(sic.column_name IS NOT null) AS geom_idx
FROM geometry_columns
INNER JOIN pg_catalog.pg_namespace AS ns
Expand All @@ -79,7 +79,7 @@ annotated_geography_columns AS (
geography_columns.srid,
geography_columns.type,
-- 'geography' AS column_type
coalesce(cls.relkind = 'v', false) AS is_view,
cls.relkind,
bool_or(sic.column_name IS NOT null) AS geom_idx
FROM geography_columns
INNER JOIN pg_catalog.pg_namespace AS ns
Expand Down Expand Up @@ -113,7 +113,7 @@ descriptions AS (
FROM pg_class AS cls
INNER JOIN pg_namespace ON cls.relnamespace = pg_namespace.oid
LEFT JOIN pg_description ON cls.oid = pg_description.objoid AND pg_description.objsubid = 0
WHERE cls.relkind = 'r' OR cls.relkind = 'v'
WHERE cls.relkind IN ('r', 'v', 'm') -- table, view or materialised view
)

SELECT
Expand All @@ -122,7 +122,7 @@ SELECT
gc.geom,
gc.srid,
gc.type,
gc.is_view,
gc.relkind,
gc.geom_idx,
dc.description,
coalesce(
Expand All @@ -145,4 +145,4 @@ LEFT JOIN descriptions AS dc
gc.schema = dc.schema_name
AND gc.name = dc.table_name
GROUP BY -- noqa: AM06
gc.schema, gc.name, gc.geom, gc.srid, gc.type, gc.is_view, gc.geom_idx, dc.description;
gc.schema, gc.name, gc.geom, gc.srid, gc.type, gc.relkind, gc.geom_idx, dc.description;
18 changes: 18 additions & 0 deletions tests/fixtures/tables/materialized_view.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CREATE TABLE fixtures_comments (
id serial PRIMARY KEY,
txt text,
geom GEOMETRY (POINT, 4326)
);

INSERT INTO fixtures_comments (txt, geom) VALUES
('a', ST_GEOMFROMTEXT('POINT(-122.4194 37.7749)', 4326)),
('b', ST_GEOMFROMTEXT('POINT(-73.935242 40.730610)', 4326));

CREATE MATERIALIZED VIEW fixtures_mv_comments AS
SELECT
id,
txt,
geom
FROM fixtures_comments;

COMMENT ON MATERIALIZED VIEW fixtures_mv_comments IS 'fixture: materialized view comments';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should make this into a proper json comment, just like other SQL, rather than ignoring this warning below

9 changes: 9 additions & 0 deletions tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ validate_log() {
remove_lines "$LOG_FILE" 'PostgreSQL 11.10.0 is older than the recommended minimum 12.0.0'
remove_lines "$LOG_FILE" 'In the used version, some geometry may be hidden on some zoom levels.'
remove_lines "$LOG_FILE" 'Unable to deserialize SQL comment on public.points2 as tilejson, the automatically generated tilejson would be used: expected value at line 1 column 1'
remove_lines "$LOG_FILE" 'Unable to deserialize SQL comment on public.fixtures_mv_comments as tilejson, the automatically generated tilejson would be used: expected value at line 1 column 1'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be ignored i think


echo "Checking for no other warnings or errors in the log"
if grep -e ' ERROR ' -e ' WARN ' "$LOG_FILE"; then
Expand Down Expand Up @@ -420,6 +421,10 @@ test_pbf antimeridian_4_0_5 antimeridian/4/0/5
test_jsn tbl_comment MixPoints
test_jsn fnc_comment function_Mixed_Name

>&2 echo "***** Test server response for materialized view *****"
test_jsn mv_comment fixtures_mv_comments
test_pbf mv_comment_0_0_0 fixtures_mv_comments/0/0/0

>&2 echo "***** Test server response for the same name in different schemas *****"
test_jsn same_name_different_schema_table1 table_name_existing_two_schemas
test_pbf same_name_different_schema_table1_0_0_0 table_name_existing_two_schemas/0/0/0
Expand All @@ -438,6 +443,8 @@ kill_process "$MARTIN_PROC_ID" Martin

test_log_has_str "$LOG_FILE" 'WARN martin::config::file::tiles::postgres::resolver::query_tables] Table public.table_source has no spatial index on column geom'
test_log_has_str "$LOG_FILE" 'WARN martin::config::file::tiles::postgres::resolver::query_tables] Table public.table_source_geog has no spatial index on column geog'
test_log_has_str "$LOG_FILE" 'WARN martin::config::file::tiles::postgres::resolver::query_tables] Table public.fixtures_comments has no spatial index on column geom'
test_log_has_str "$LOG_FILE" 'WARN martin::config::file::tiles::postgres::resolver::query_tables] Table public.fixtures_mv_comments has no spatial index on column geom'
test_log_has_str "$LOG_FILE" 'WARN martin_core::resources::fonts] Ignoring duplicate font Overpass Mono Regular from tests'
test_log_has_str "$LOG_FILE" 'was renamed to `stamen_toner__raster_CC-BY-ODbL_z3`'
test_log_has_str "$LOG_FILE" 'was renamed to `table_source_multiple_geom.1`'
Expand Down Expand Up @@ -552,6 +559,8 @@ test_metrics "metrics_1"
kill_process "$MARTIN_PROC_ID" Martin
test_log_has_str "$LOG_FILE" 'WARN martin::config::file::tiles::postgres::resolver::query_tables] Table public.table_source has no spatial index on column geom'
test_log_has_str "$LOG_FILE" 'WARN martin::config::file::tiles::postgres::resolver::query_tables] Table public.table_source_geog has no spatial index on column geog'
test_log_has_str "$LOG_FILE" 'WARN martin::config::file::tiles::postgres::resolver::query_tables] Table public.fixtures_comments has no spatial index on column geom'
test_log_has_str "$LOG_FILE" 'WARN martin::config::file::tiles::postgres::resolver::query_tables] Table public.fixtures_mv_comments has no spatial index on column geom'
test_log_has_str "$LOG_FILE" 'WARN martin_core::resources::fonts] Ignoring duplicate font Overpass Mono Regular from tests'
test_log_has_str "$LOG_FILE" "WARN martin::config::file::main] Ignoring unrecognized configuration key 'warning'. Please check your configuration file for typos."
test_log_has_str "$LOG_FILE" "WARN martin::config::file::main] Ignoring unrecognized configuration key 'observability.warning'. Please check your configuration file for typos."
Expand Down
Loading