The semantic data layer is an experimental feature, suggested to advanced users.
What are Views?
Views are a feature of SQL databases that allow you to define logical subsets of data that can be used in queries. In PandasAI, you can define views in your semantic layer schema to organize and structure your data. Views are particularly useful when you want to:- Combine data from multiple datasets
- Create a simplified or filtered view of your data
- Define relationships between different datasets
Creating Views
You can create views either through YAML configuration or programmatically using Python.Python Code Example
YAML Configuration
Example Configuration
Constraints
-
Mutual Exclusivity:
- A schema cannot define both
tableandviewsimultaneously. - If
viewistrue, then the schema represents a view.
- A schema cannot define both
-
Column Format:
- For views:
- All columns must follow the format
[table].[column]. fromandtofields inrelationsmust follow the[table].[column]format.- Example:
loans.payment_amount,heart.condition.
- All columns must follow the format
- For views:
-
Relationships for Views:
- Each table referenced in
columnsmust have at least one relationship defined inrelations. - Relationships must specify
fromandtoattributes in the[table].[column]format. - Relations define how different tables in your view are connected.
- Each table referenced in
-
Dataset Requirements:
- All referenced datasets must exist before creating the view.
- The columns specified in the view must exist in their respective source datasets.
- The columns used in relations (
fromandto) must be compatible types.
