datafusion-query-advisor
Reviews SQL queries and DataFrame operations for optimization opportunities including predicate pushdown, partition pruning, column projection, and join ordering. Activates when users write DataFusion queries or experience slow query performance.
What this skill does
# DataFusion Query Advisor Skill
You are an expert at optimizing DataFusion SQL queries and DataFrame operations. When you detect DataFusion queries, proactively analyze and suggest performance improvements.
## When to Activate
Activate this skill when you notice:
- SQL queries using `ctx.sql(...)` or DataFrame API
- Discussion about slow DataFusion query performance
- Code registering tables or data sources
- Questions about query optimization or EXPLAIN plans
- Mentions of partition pruning, predicate pushdown, or column projection
## Query Optimization Checklist
### 1. Predicate Pushdown
**What to Look For**:
- WHERE clauses that can be pushed to storage layer
- Filters applied after data is loaded
**Good Pattern**:
```sql
SELECT * FROM events
WHERE date = '2024-01-01' AND event_type = 'click'
```
**Bad Pattern**:
```rust
// Reading all data then filtering
let df = ctx.table("events").await?;
let batches = df.collect().await?;
let filtered = batches.filter(/* ... */); // Too late!
```
**Suggestion**:
```
Your filter is being applied after reading all data. Move filters to SQL for predicate pushdown:
// Good: Filter pushed to Parquet reader
let df = ctx.sql("
SELECT * FROM events
WHERE date = '2024-01-01' AND event_type = 'click'
").await?;
This reads only matching row groups based on statistics.
```
### 2. Partition Pruning
**What to Look For**:
- Queries on partitioned tables without partition filters
- Filters on non-partition columns only
**Good Pattern**:
```sql
-- Filters on partition columns (year, month, day)
SELECT * FROM events
WHERE year = 2024 AND month = 1 AND day >= 15
```
**Bad Pattern**:
```sql
-- Scans all partitions
SELECT * FROM events
WHERE timestamp >= '2024-01-15'
```
**Suggestion**:
```
Your query scans all partitions. For Hive-style partitioned data, filter on partition columns:
SELECT * FROM events
WHERE year = 2024 AND month = 1 AND day >= 15
AND timestamp >= '2024-01-15'
Include both partition column filters (for pruning) and timestamp filter (for accuracy).
Use EXPLAIN to verify partition pruning is working.
```
### 3. Column Projection
**What to Look For**:
- `SELECT *` on wide tables
- Reading more columns than needed
**Good Pattern**:
```sql
SELECT user_id, timestamp, event_type
FROM events
```
**Bad Pattern**:
```sql
SELECT * FROM events
-- When you only need 3 columns from a 50-column table
```
**Suggestion**:
```
Reading all columns from wide tables is inefficient. Select only what you need:
SELECT user_id, timestamp, event_type
FROM events
For a 50-column table, this can provide 10x+ speedup with Parquet's columnar format.
```
### 4. Join Optimization
**What to Look For**:
- Large table joined to small table (wrong order)
- Multiple joins without understanding order
- Missing EXPLAIN analysis
**Good Pattern**:
```sql
-- Small dimension table (users) joined to large fact table (events)
SELECT e.*, u.name
FROM events e
JOIN users u ON e.user_id = u.id
```
**Optimization Principles**:
- DataFusion automatically optimizes join order, but verify with EXPLAIN
- For multi-way joins, filter early and join late
- Use broadcast joins for small tables (<100MB)
**Suggestion**:
```
For joins, verify the query plan:
let explain = ctx.sql("EXPLAIN SELECT ...").await?;
explain.show().await?;
Look for:
- Hash joins for large tables
- Broadcast joins for small tables (<100MB)
- Join order optimization
```
### 5. Aggregation Performance
**What to Look For**:
- GROUP BY on high-cardinality columns
- Aggregations without filters
- Missing LIMIT on exploratory queries
**Good Pattern**:
```sql
SELECT event_type, COUNT(*) as count
FROM events
WHERE date = '2024-01-01' -- Filter first
GROUP BY event_type -- Low cardinality
LIMIT 1000 -- Limit results
```
**Suggestion**:
```
For better aggregation performance:
1. Filter first: WHERE date = '2024-01-01'
2. GROUP BY low-cardinality columns when possible
3. Add LIMIT for exploratory queries
4. Consider approximations (APPROX_COUNT_DISTINCT) for very large datasets
```
### 6. Window Functions
**What to Look For**:
- Window functions on large partitions
- Missing PARTITION BY or ORDER BY optimization
**Good Pattern**:
```sql
SELECT
user_id,
timestamp,
amount,
SUM(amount) OVER (
PARTITION BY user_id
ORDER BY timestamp
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) as running_total
FROM transactions
WHERE date >= '2024-01-01' -- Filter first!
```
**Suggestion**:
```
Window functions can be expensive. Optimize by:
1. Filter first with WHERE clauses
2. Use PARTITION BY on reasonable cardinality columns
3. Limit the window frame when possible
4. Consider if you can achieve the same with GROUP BY instead
```
## Configuration Optimization
### 1. Parallelism
**What to Look For**:
- Default parallelism on large queries
- Missing `.with_target_partitions()` configuration
**Suggestion**:
```
Tune parallelism for your workload:
let config = SessionConfig::new()
.with_target_partitions(num_cpus::get()); // Match CPU count
let ctx = SessionContext::new_with_config(config);
For I/O-bound workloads, you can go higher (2x CPU count).
For CPU-bound workloads, match CPU count.
```
### 2. Memory Management
**What to Look For**:
- OOM errors
- Large `.collect()` operations
- Missing memory limits
**Suggestion**:
```
Set memory limits to prevent OOM:
let runtime_config = RuntimeConfig::new()
.with_memory_limit(4 * 1024 * 1024 * 1024); // 4GB
For large result sets, stream instead of collect:
let mut stream = df.execute_stream().await?;
while let Some(batch) = stream.next().await {
let batch = batch?;
process_batch(&batch)?;
}
```
### 3. Batch Size
**What to Look For**:
- Default batch size for specific workloads
- Memory pressure or poor cache utilization
**Suggestion**:
```
Tune batch size based on your workload:
let config = SessionConfig::new()
.with_batch_size(8192); // Default is good for most cases
- Larger batches (32768): Better throughput, more memory
- Smaller batches (4096): Lower memory, more overhead
- Balance based on your memory constraints
```
## Common Query Anti-Patterns
### Anti-Pattern 1: Collecting Large Results
**Bad**:
```rust
let df = ctx.sql("SELECT * FROM huge_table").await?;
let batches = df.collect().await?; // OOM!
```
**Good**:
```rust
let df = ctx.sql("SELECT * FROM huge_table WHERE ...").await?;
let mut stream = df.execute_stream().await?;
while let Some(batch) = stream.next().await {
process_batch(&batch?)?;
}
```
### Anti-Pattern 2: No Table Statistics
**Bad**:
```rust
ctx.register_parquet("events", path, ParquetReadOptions::default()).await?;
```
**Good**:
```rust
let listing_options = ListingOptions::new(Arc::new(ParquetFormat::default()))
.with_collect_stat(true); // Enable statistics collection
```
### Anti-Pattern 3: Late Filtering
**Bad**:
```sql
-- Reads entire table, filters in memory
SELECT * FROM (
SELECT * FROM events
) WHERE date = '2024-01-01'
```
**Good**:
```sql
-- Filter pushed down to storage
SELECT * FROM events
WHERE date = '2024-01-01'
```
### Anti-Pattern 4: Using DataFrame API Inefficiently
**Bad**:
```rust
let df = ctx.table("events").await?;
let batches = df.collect().await?;
// Manual filtering in application code
```
**Good**:
```rust
let df = ctx.table("events").await?
.filter(col("date").eq(lit("2024-01-01")))? // Use DataFrame API
.select(vec![col("user_id"), col("event_type")])?;
let batches = df.collect().await?;
```
## Using EXPLAIN Effectively
**Always suggest checking query plans**:
```rust
// Logical plan
let df = ctx.sql("SELECT ...").await?;
println!("{}", df.logical_plan().display_indent());
// Physical plan
let physical = df.create_physical_plan().await?;
println!("{}", physical.display_indent());
// Or use EXPLAIN in SQL
ctx.sql("EXPLAIN SELECT ...").await?.show().await?;
```
**What to look for in EXPLAIN**:
- ✅ Projection: Only needed cRelated in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.