Skip to content
Open
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
6 changes: 6 additions & 0 deletions docs/docs/concepts/views.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ View metadata is persisted only when the catalog implementation supports it:
- **Hive metastore catalog** – view metadata is stored together with table metadata inside the
metastore warehouse.
- **REST catalog** – view metadata is kept in the REST backend and exposed through the catalog API.
- **JDBC catalog** – view metadata is stored in the catalog database in the `paimon_views`
metadata table. The table is created automatically when the JDBC catalog is initialized.

File-system catalogs do not currently support views because they lack persistent metadata storage.

Expand All @@ -57,6 +59,10 @@ view using their native dialect.
Use `CREATE VIEW` or `CREATE OR REPLACE VIEW` to register a view. Paimon assigns a UUID, writes the
first metadata file, and records version `1`.

The catalog stores the view definition. It does not resolve or validate referenced tables when the
view is created, so missing or cross-database table references are checked by the compute engine when
the view is queried.

```sql
CREATE VIEW sales_view AS
SELECT region, SUM(amount) AS total_amount
Expand Down
12 changes: 12 additions & 0 deletions docs/docs/flink/sql-ddl.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ You can also perform logical isolation for databases under multiple catalogs by

Additionally, when creating a JdbcCatalog, you can specify the maximum length for the lock key by configuring "lock-key-max-length," which defaults to 255. Since this value is a combination of {catalog-key}.{database-name}.{table-name}, please adjust accordingly.

JDBC catalog supports persistent Paimon views. View metadata is stored in the automatically created
`paimon_views` table in the catalog database. The view SQL is stored as catalog metadata and is not
resolved when the view is created.

```sql
CREATE VIEW sales_view AS SELECT name, amount FROM sales WHERE amount > 100;

SHOW VIEWS;

DROP VIEW sales_view;
```

You can define any default table options with the prefix `table-default.` for tables created in the catalog.

## Create Table
Expand Down
5 changes: 4 additions & 1 deletion docs/docs/spark/sql-ddl.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ Paimon JDBC Catalog in Spark needs to correctly add the corresponding jar packag
| mysql | mysql-connector-java | [Download](https://mvnrepository.com/artifact/mysql/mysql-connector-java) |
| postgres | postgresql | [Download](https://mvnrepository.com/artifact/org.postgresql/postgresql) |

JDBC catalog supports persistent Paimon views. View metadata is stored in the automatically created
`paimon_views` table in the catalog database.

```bash
spark-sql ... \
--conf spark.sql.catalog.paimon=org.apache.paimon.spark.SparkCatalog \
Expand Down Expand Up @@ -375,7 +378,7 @@ CREATE TABLE target_tbl LIKE source_tbl;
## View

Views are based on the result-set of an SQL query, when using `org.apache.paimon.spark.SparkCatalog`, views are managed by paimon itself.
And in this case, views are supported when the `metastore` type is `hive` or `rest`.
And in this case, views are supported when the `metastore` type is `hive`, `rest` or `jdbc`.

### Create Or Replace View

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.apache.paimon.table.system.SystemTableLoader;
import org.apache.paimon.utils.DVMetaCache;
import org.apache.paimon.utils.SegmentsCache;
import org.apache.paimon.view.View;
import org.apache.paimon.view.ViewChange;

import org.apache.paimon.shade.caffeine2.com.github.benmanes.caffeine.cache.Cache;
import org.apache.paimon.shade.caffeine2.com.github.benmanes.caffeine.cache.Caffeine;
Expand Down Expand Up @@ -368,6 +370,40 @@ public void invalidateTable(Identifier identifier) {
}
}

@Override
public void createView(Identifier identifier, View view, boolean ignoreIfExists)
throws ViewAlreadyExistException, DatabaseNotExistException {
wrapped.createView(identifier, view, ignoreIfExists);
}

@Override
public View getView(Identifier identifier) throws ViewNotExistException {
return wrapped.getView(identifier);
}

@Override
public List<String> listViews(String databaseName) throws DatabaseNotExistException {
return wrapped.listViews(databaseName);
}

@Override
public void dropView(Identifier identifier, boolean ignoreIfNotExists)
throws ViewNotExistException {
wrapped.dropView(identifier, ignoreIfNotExists);
}

@Override
public void renameView(Identifier fromView, Identifier toView, boolean ignoreIfNotExists)
throws ViewNotExistException, ViewAlreadyExistException {
wrapped.renameView(fromView, toView, ignoreIfNotExists);
}

@Override
public void alterView(Identifier view, List<ViewChange> viewChanges, boolean ignoreIfNotExists)
throws ViewNotExistException, DialectAlreadyExistException, DialectNotExistException {
wrapped.alterView(view, viewChanges, ignoreIfNotExists);
}

// ================================== Cache Public API
// ================================================

Expand Down
Loading
Loading