Implementation:Apache Paimon View
| Knowledge Sources | |
|---|---|
| Domains | View Management, Query Abstraction |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
View is an interface defining the contract for view definitions in Apache Paimon, providing query abstraction over tables.
Description
View is a public interface that represents a saved query or virtual table in Apache Paimon's catalog system. A view encapsulates a SQL query that can be referenced like a table but doesn't store data itself - instead, it dynamically executes the underlying query when accessed. The interface defines six essential properties: name (simple identifier), fullName (database-qualified identifier), rowType (the schema of query results), query (the primary SQL representation), dialects (alternate SQL representations for different query engines), and comment (optional documentation).
The interface supports multi-dialect queries through the dialects() map, which stores query variations for different SQL engines or processing frameworks. The query(String dialect) convenience method retrieves the query for a specific dialect, falling back to the default query if no dialect-specific version exists. This enables views to work across heterogeneous query engines while maintaining semantic equivalence.
Views are configurable through an options map, supporting view-specific behaviors or hints. The interface also defines a copy() method that creates a new view with additional dynamic options merged in, enabling runtime parameterization without modifying the stored view definition. The optional comment provides documentation for schema exploration and metadata management. Views integrate with Paimon's catalog system, appearing alongside tables in database listings and supporting similar DDL operations.
Usage
Use View when defining reusable query abstractions, creating logical data models over physical tables, supporting multiple query engines with dialect-specific SQL, or building data access layers that hide complex joins and transformations.
Code Reference
Source Location
- Repository: Apache_Paimon
- File: paimon-api/src/main/java/org/apache/paimon/view/View.java
Signature
public interface View {
String name();
String fullName();
RowType rowType();
String query();
Map<String, String> dialects();
default String query(String dialect);
Optional<String> comment();
Map<String, String> options();
View copy(Map<String, String> dynamicOptions);
}
Import
import org.apache.paimon.view.View;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| dialect | String | No | Query dialect identifier for dialect-specific retrieval |
| dynamicOptions | Map<String, String> | For copy | Additional options to merge |
Outputs
| Name | Type | Description |
|---|---|---|
| Name | String | Simple view name |
| Full name | String | Database-qualified view name |
| Row type | RowType | Schema of the view's result set |
| Query | String | SQL query (default or dialect-specific) |
| Dialects | Map<String, String> | All dialect-specific query variants |
| Comment | Optional<String> | View documentation |
| Options | Map<String, String> | View configuration options |
| Copied view | View | New view with merged dynamic options |
Usage Examples
// Access view properties
String viewName = view.name(); // "customer_summary"
String fullName = view.fullName(); // "analytics.customer_summary"
// Get view schema
RowType schema = view.rowType();
List<DataField> fields = schema.getFields();
// Get default query
String sql = view.query();
// Returns: "SELECT customer_id, COUNT(*) as order_count FROM orders GROUP BY customer_id"
// Get dialect-specific query
String sparkQuery = view.query("spark");
// Returns Spark-specific SQL if available, otherwise falls back to default
// Get all dialect queries
Map<String, String> allDialects = view.dialects();
// e.g., {"spark": "...", "flink": "..."}
// Check if view has comment
Optional<String> comment = view.comment();
comment.ifPresent(c -> System.out.println("View description: " + c));
// Access view options
Map<String, String> options = view.options();
String materializationHint = options.get("materialization.enabled");
// Create parameterized copy
Map<String, String> runtimeOptions = new HashMap<>();
runtimeOptions.put("filter.date", "2024-01-01");
runtimeOptions.put("limit", "1000");
View parameterizedView = view.copy(runtimeOptions);
// Example: Multi-dialect view usage
public String getViewQuery(View view, String engine) {
return view.query(engine);
}
String flinkSql = getViewQuery(view, "flink");
String sparkSql = getViewQuery(view, "spark");
// Example: View with dialect support
class MyView implements View {
private final Map<String, String> dialectQueries;
@Override
public String query() {
return "SELECT * FROM base_table"; // Standard SQL
}
@Override
public Map<String, String> dialects() {
Map<String, String> dialects = new HashMap<>();
dialects.put("spark", "SELECT /*+ BROADCAST(t1) */ * FROM base_table");
dialects.put("flink", "SELECT * FROM base_table /*+ OPTIONS('scan.parallelism'='4') */");
return dialects;
}
@Override
public String query(String dialect) {
return dialects().getOrDefault(dialect, query());
}
// ... other methods
}
// Example: Using views in queries
public void queryView(Catalog catalog, String viewName) {
View view = catalog.getView(new ObjectPath("mydb", viewName));
// Execute for current engine
String query = view.query();
executeQuery(query);
// Or execute with specific dialect
String dialectQuery = view.query("spark");
executeQuery(dialectQuery);
}
// Example: Dynamic parameterization
View baseView = catalog.getView(path);
Map<String, String> params = Map.of(
"start_date", "2024-01-01",
"end_date", "2024-12-31"
);
View filtered = baseView.copy(params);
// Use filtered view with parameter context