Skip to content

Conversation

@kunalsinghdadhwal
Copy link

@kunalsinghdadhwal kunalsinghdadhwal commented Oct 2, 2025

Fixes #2267

New Features

  • Materialized views are now included alongside tables and views in listings and metadata, making them discoverable and accessible in the app.
  • Descriptions and related information now reflect materialized views where applicable.

Tests

  • Added fixtures and tests to validate materialized view handling (JSON and PBF responses).
  • Expanded cross-schema tests to cover objects with the same names across different schemas, improving reliability and preventing name-collision issues.

Copilot AI review requested due to automatic review settings October 2, 2025 17:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for PostgreSQL materialized views in Martin tile server by treating them as discoverable objects alongside regular tables and views. The change enables materialized views to be included in server listings and accessible via the API.

Key Changes:

  • Modified SQL query to include materialized views (relkind = 'm') in database object discovery
  • Added test fixtures and validation for materialized view functionality
  • Expanded test coverage for cross-schema object handling

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
martin/src/config/file/postgres/resolver/scripts/query_available_tables.sql Updated WHERE clause to include materialized views in database object queries
tests/fixtures/tables/materialized_view.sql Added test fixture with materialized view creation and sample data
tests/test.sh Added test cases for materialized view JSON and PBF response validation

@CommanderStorm CommanderStorm changed the title Add support for Postgres materialized views (relkind = 'm') and test feat(pg): Add support for Postgres materialized views (relkind = 'm') and test Oct 2, 2025
Copy link
Member

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

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

Two requests:

Please run just bless to bless the tests snapshots.

Below, there is is_view. It is used to give debug information like here:
https://github.com/maplibre/martin/blob/c16ceabed73ff66fe8d55452341fe01b5f64681f/martin/src/config/file/postgres/builder.rs#L500C4-L500C11

Let's change this to relkind and give more accurate error messages in the usages.

@CommanderStorm CommanderStorm marked this pull request as draft October 6, 2025 03:16
@kunalsinghdadhwal
Copy link
Author

Two requests:

Please run just bless to bless the tests snapshots.

Below, there is is_view. It is used to give debug information like here: https://github.com/maplibre/martin/blob/c16ceabed73ff66fe8d55452341fe01b5f64681f/martin/src/config/file/postgres/builder.rs#L500C4-L500C11

Let's change this to relkind and give more accurate error messages in the usages.

I have run just bless and for the is_view

do you want me to change it to an Option<String> because currently it is Option<bool> in the struct

config_table.rs@L37

@CommanderStorm
Copy link
Member

Yes
That, or Option<char> as it only will ever have one char.
If chars are not supported, String is also fine 😉

@kunalsinghdadhwal
Copy link
Author

I have added the Option<char> but it breaks the code.

Some trait bounds are not satisfied

Copy link
Member

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

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

I have added the Option but it breaks the code.
Some trait bounds are not satisfied

I changed this to i8 as Char gets translated this way.

I have not investigated all testcase fails, the code might not be entirely sound.

@kunalsinghdadhwal
Copy link
Author

Kindly review @CommanderStorm

Copy link
Member

@nyurik nyurik left a comment

Choose a reason for hiding this comment

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

great work! one minor thing, and i think ok to merge, but I will let @CommanderStorm drive this. Thanks!

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add explicit support for materialized views

3 participants