Overview
Pylar allows you to work with Local Dataframes—data that’s already loaded in your Pylar session. This enables you to query and join multiple dataframes using SQL, creating unified views without needing to connect to external databases.What Are Local Dataframes?
Local Dataframes are:- Data tables loaded into your Pylar session
- Accessible through the SQL IDE
- Queryable using standard SQL syntax
- Joinable across multiple dataframes
Setting Up Dataframe Queries
To query local dataframes:- Select Dataframe Source: In the SQL IDE, set the datasource dropdown to “Local Dataframes”
- Reference Dataframe Names: Use the dataframe name as the table name in your SQL query
- Write Standard SQL: Use familiar SQL syntax to query and join your dataframes
Dataframe names are case-sensitive and must match exactly. Make sure you know the exact names of your loaded dataframes before querying.
Basic Dataframe Queries
Selecting from a Single Dataframe
Query a specific subset of data from a dataframe:- References
table0as a dataframe in your session - Filters rows where
event_typeequals'login' - Returns all columns (
*) from matching rows
Selecting Specific Columns
Filtering and Sorting
Joining Multiple Dataframes
One of the most powerful features is joining data from multiple dataframes to create unified views.Basic Join Syntax
Example: Joining on Common ID
Join two dataframes on a common identifier:- Joins
table1andtable2dataframes - Matches rows where
event_idvalues are equal - Returns selected columns from both dataframes
- Uses table aliases (
t1,t2) for clarity
Advanced Join Patterns
Multiple Dataframe Joins
Join three or more dataframes:Left Join for Optional Data
Include all rows from the first dataframe, with optional data from the second:Full Outer Join
Include all rows from both dataframes:Real-World Examples
Example 1: Customer Event Analysis
Combine customer events with user profiles:Example 2: Marketing Attribution
Join campaign data with conversion events:Example 3: Product Performance Analysis
Combine product catalog with sales and reviews:Join Types for Dataframes
INNER JOIN
Returns only rows that have matches in both dataframes.LEFT JOIN
Returns all rows from the left dataframe, matched rows from the right.RIGHT JOIN
Returns all rows from the right dataframe, matched rows from the left.FULL OUTER JOIN
Returns all rows from both dataframes, with NULLs for missing matches.Handling Data Type Mismatches
When joining dataframes, ensure join keys are compatible:String vs Numeric IDs
Handling NULL Values
Case-Insensitive Matching
Best Practices
1. Use Descriptive Aliases
2. Select Specific Columns
3. Filter Early
4. Handle NULLs Explicitly
5. Verify Dataframe Existence
Before querying, ensure your dataframes are loaded and named correctly. Test with a simple query first:Common Issues and Solutions
Issue: “Table not found” Error
Cause: Dataframe doesn’t exist or name is incorrect. Solution:- Verify dataframe is loaded in your session
- Check dataframe name matches exactly (case-sensitive)
- Ensure datasource is set to “Local Dataframes”
Issue: Join Returns No Results
Cause: Join keys don’t match or have incompatible types. Solution:- Verify join keys exist in both dataframes
- Check data types match (use CAST if needed)
- Test join keys individually:
Issue: Column Name Conflicts
Cause: Both dataframes have columns with the same name. Solution:- Use table aliases and qualify column names
- Use
ASto rename columns in SELECT - Example:
Issue: Performance Issues
Cause: Large dataframes or complex joins. Solution:- Filter dataframes before joining
- Use LIMIT to test with smaller datasets
- Consider aggregating dataframes first
Next Steps
Now that you understand cross-database joins:- Writing Your First View - Create comprehensive views using joins
- View Best Practices - Optimize your views for performance and maintainability
Create Unified Views
Learn how to combine dataframe queries with database queries