Skip to content

Latest commit

Β 

History

18 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Vertica Expert Skill

A comprehensive skill for Vertica database migration, including migration from Oracle, DB2, SQL Server, PostgreSQL, MySQL, and Teradata, SQL syntax reference, PL/vSQL stored procedure development, UDx custom function creation, in-database machine learning.

Overview

This skill is distilled from the Vertica product documentation and my memory to provide detailed guidance on:

  • Migration Guides: Migrate scripts from Oracle, DB2, SQL Server, PostgreSQL, MySQL, and Teradata to Vertica, including DDL, DML, stored procedures, and queries
  • Stored Procedures and UDx Development: Creating custom stored procedures or functions in SQL, C++, and Python
  • Machine Learning: In-database predictive analytics with regression, classification, clustering, and time series

πŸ“š Reference Document Summaries: For large-scale migrations using the Multi-Agent Workflow, agent-optimized summaries of reference documents are available in references/reference-summaries/ directory. These summaries contain ALL information needed for migration decisions while reducing context usage by ~88%. Full documents are for human reference with detailed examples.

Skill Structure

vertica-expert-skill/
β”œβ”€β”€ SKILL.md                                # Main skill definition
β”œβ”€β”€ README.md                               # Project overview
β”œβ”€β”€ CLAUDE.md                               # Internal documentation
β”œβ”€β”€ install.sh                              # Installation script
β”œβ”€β”€ uninstall.sh                            # Uninstallation script
β”œβ”€β”€ references/                             # Detailed reference guides
β”‚   β”œβ”€β”€ sql-syntax-reference.md             # Complete SQL syntax
β”‚   β”œβ”€β”€ user-defined-sql-functions-guide.md # User-Defined SQL Functions
β”‚   β”œβ”€β”€ stored-procedures-guide.md          # PL/vSQL development
β”‚   β”œβ”€β”€ udx-development-guide.md            # Custom function development (C++, Python, Java, R)
β”‚   β”œβ”€β”€ data-type-mapping.md                # Data type mapping guide
β”‚   β”œβ”€β”€ function-mapping.md                 # Function conversion guide
β”‚   β”œβ”€β”€ query-optimization.md               # Performance optimization
β”‚   β”œβ”€β”€ migration-guides-overview.md        # Guide hierarchy and usage instructions
β”‚   β”œβ”€β”€ generic-migration-guide.md          # 🚨 MANDATORY: Master migration requirements
β”‚   β”œβ”€β”€ oltp-to-olap-rewrite-guide.md       # πŸ”„ OLTPβ†’OLAP SQL rewrite patterns
β”‚   β”œβ”€β”€ oracle-migration.md                 # Oracle-specific migration
β”‚   β”œβ”€β”€ db2-migration.md                    # IBM DB2 migration guide
β”‚   β”œβ”€β”€ sqlserver-migration.md              # SQL Server migration guide
β”‚   β”œβ”€β”€ postgresql-migration.md             # PostgreSQL migration guide
β”‚   β”œβ”€β”€ mysql-migration.md                  # MySQL migration guide
β”‚   β”œβ”€β”€ teradata-migration.md               # Teradata migration guide
β”‚   β”œβ”€β”€ machine-learning.md                 # In-database ML algorithms
β”‚   β”œβ”€β”€ ml-function-mapping.md              # Cross-database ML mapping
β”‚   β”œβ”€β”€ multi-agent-migration-guide.md      # πŸ€– Multi-agent migration guide (Manager ONLY - other agents use their own config files)
β”‚   └── reference-summaries/               # πŸ“š Agent-optimized reference summaries
β”‚       β”œβ”€β”€ generic-migration-summary.md   # Generic migration requirements (agent-optimized)
β”‚       β”œβ”€β”€ sql-syntax-summary.md          # SQL syntax reference (agent-optimized)
β”‚       β”œβ”€β”€ oltp-to-olap-summary.md        # OLTPβ†’OLAP rewrite patterns (agent-optimized)
β”‚       β”œβ”€β”€ stored-procedures-summary.md   # Stored procedures guide (agent-optimized)
β”‚       β”œβ”€β”€ user-defined-sql-functions-guide.md     # SQL functions guide
β”‚       β”œβ”€β”€ oracle-migration-summary.md    # Oracle migration (agent-optimized)
β”‚       β”œβ”€β”€ db2-migration-summary.md       # DB2 migration (agent-optimized)
β”‚       β”œβ”€β”€ sqlserver-migration-summary.md # SQL Server migration (agent-optimized)
β”‚       β”œβ”€β”€ postgresql-migration-summary.md # PostgreSQL migration (agent-optimized)
β”‚       β”œβ”€β”€ mysql-migration-summary.md     # MySQL migration (agent-optimized)
β”‚       └── teradata-migration-summary.md  # Teradata migration (agent-optimized)
β”œβ”€β”€ examples/                               # Examples of other databases
└── slides/                                 # Slides in Python format

Key Features

1. Database Migration

2. Vertica SQL Development

  • Complete SQL Syntax: DDL, DML, queries, CTEs, window functions
  • Advanced Analytics: Complex analytical queries and reporting
  • Data Loading: COPY statements with transformation options
  • Transaction Control: Complete transaction management

3. User-Defined SQL Functions

  • Simple SQL Extensions: Create reusable SQL expressions with CREATE FUNCTION
  • Data Transformation: NULL handling, string formatting, mathematical calculations
  • Business Logic: Encapsulate frequently used calculations and rules
  • Function Management: Overloading, privileges, and performance optimization
  • Easy Testing: Comprehensive testing strategies with VSQL

4. PL/vSQL Stored Procedure Development

  • Procedure Creation: Complete PL/vSQL development framework
  • Parameter Handling: IN, OUT, INOUT parameters with defaults
  • Control Structures: IF, CASE, loops (FOR, WHILE)
  • Exception Handling: Comprehensive error management and logging
  • Dynamic SQL: EXECUTE statements for flexible queries

5. Performance Optimization

  • Projection Design: Order-optimized, aggregate, replicated projections
  • Encoding Strategies: RLE, DELTA, GZIP, LZO for optimal compression
  • Query Optimization: Rewriting for columnar performance
  • Resource Management: Resource pools and workload prioritization
  • Statistics Management: ANALYZE_STATISTICS best practices

6. UDx Custom Function Development

  • Multiple Languages: C++, Python, Java, R support
  • Function Types: Scalar, aggregate, analytic, transform functions
  • High Performance: Optimized C++ implementations
  • Easy Deployment: Registration and installation procedures

7. Machine Learning & Data Science

  • Regression Algorithms: Linear, XGBoost, Random Forest, SVM, Poisson
  • Classification: Logistic, XGBoost, Random Forest, Naive Bayes, SVM
  • Clustering: K-Means, Bisecting K-Means, K-Prototypes
  • Time Series: Autoregression, Moving Average, ARIMA
  • Data Preparation: Imputation, encoding, outlier detection, balancing
  • Model Management: Training, evaluation, deployment, monitoring

Capabilities

This skill provides comprehensive coverage of:

  1. Database Migration - Converting Oracle, DB2, SQL Server, PostgreSQL, MySQL, and Teradata procedures
  2. OLTP to OLAP Rewrite - Rewriting row-by-row procedural code to set-based SQL for Vertica's columnar architecture
  3. Vertica SQL Development - Creating complex analytical queries from requirements
  4. PL/vSQL Development - Building stored procedures with error handling
  5. Query Optimization - Converting slow queries to high-performance Vertica
  6. UDx Development - Creating custom aggregate functions in C++
  7. Machine Learning - Implementing end-to-end ML workflows in Vertica

Key Benefits

For Database Developers

  • Automated SQL conversion with function mapping
  • Performance optimization recommendations
  • Best practices for Vertica development

For Database Administrators

  • Schema optimization guidance
  • Projection design strategies
  • Resource management best practices

For Data Architects

  • Migration planning assistance
  • Performance modeling for Vertica
  • Scalability considerations

For Data Scientists

  • In-database ML workflows without data movement
  • Algorithm selection and implementation guidance
  • Model deployment and monitoring strategies

Getting Started

For Database Migration

  1. Install the skill using ./install.sh
  2. Read Generic Migration Guide (from vertica-expert skill) 🚨 MANDATORY - Understand all requirements before proceeding
    • πŸ’‘ For Multi-Agent Workflow: Use Summary version to reduce context usage
  3. Read OLTP to OLAP Rewrite Guide (from vertica-expert skill) πŸ”„ ESSENTIAL - Learn rewrite patterns for procedural/OLTP code
    • πŸ’‘ For Multi-Agent Workflow: Use Summary version to reduce context usage
  4. Identify your source database (Oracle, DB2, SQL Server, PostgreSQL, MySQL, Teradata)
  5. Process source files sequentially - never skip or reorder objects
  6. Migrate ALL objects - tables, views, procedures, functions, DML, sequences
  7. Rewrite procedural code using OLTP-to-OLAP patterns (cursors→window functions, loops→set-based SQL)
  8. Test each object individually before considering it migrated
  9. Execute complete migration and validate all dependencies
  10. Optimize and validate performance results

For Vertica Development

  1. Install the skill using ./install.sh
  2. Explore vertica-expert skill's reference guides in the references/ directory
  3. Use provided examples as templates for your development
  4. Apply best practices for optimal performance
  5. Test with your data and iterate as needed

For Machine Learning

  1. Install the skill using ./install.sh
  2. Choose your ML algorithm (regression, classification, clustering, time series)
  3. Prepare your training data with appropriate features
  4. Train and evaluate models using Vertica's in-database functions
  5. Deploy models for real-time or batch predictions

Best Practices

Migration Process

  1. Read Generic Migration Guide 🚨 MANDATORY FIRST STEP - Understand all non-negotiable requirements
    • πŸ’‘ For Multi-Agent Workflow: Use Summary version to reduce context usage
  2. Read OLTP to OLAP Rewrite Guide πŸ”„ ESSENTIAL - Understand rewrite patterns for procedural code
    • πŸ’‘ For Multi-Agent Workflow: Use Summary version to reduce context usage
  3. Assess your current database complexity and dependencies
  4. Plan your migration strategy following sequential processing requirements
  5. Convert ALL objects (tables, views, procedures, functions, DML) one-to-one
  6. Rewrite procedural code using OLTP-to-OLAP patterns (cursors→window functions, loop-DML→set-based SQL)
  7. Test every object individually before considering it migrated
  8. Execute complete migration and validate all dependencies
  9. Optimize for Vertica's columnar architecture
  10. Validate performance against baselines

Common Migration Tasks

For common database script migrations , follow this simple approach:

Step 1: Trigger the skill manually

/vertica-expert

Step 2: Execute the real migration task

Quick Start:

  • First:

    Task: Using general migration workflow to migrate Oracle database scripts from "examples/oracle/" to Vertica, saving results to "examples/vertica/" with identical file names.
    
    Before actually starting the task, pause and wait for my confirmation.
    

    Or:

    Task: Using Embedded SQL Script Migration Workflow to migrate Teradata database script from "examples/teradata/app2.pl" to Vertica, saving results to "examples/vertica/" with identical file name.
    
    Before actually starting the task, pause and wait for my confirmation.
    
  • Then:

    Please provide a detailed description of all the specific requirements you have understood for this task. Finally, pause and wait for my confirmation.
    
  • Finally:

    Be sure to keep this task and the aforementioned requirements firmly in mind. I will rigorously inspect whether you have violated these requirements during this task.
    
    Start the task.
    

For some special situations:

  • Remind the agent when the context is about to be exhausted:
    Save the state in preparation for compacting.
    
  • Continue after compacting context:
    Restore from the state file you saved before compact.
    Continue.
    

πŸ€– Multi-Agent Migration Workflow

⚠️ PREREQUISITE: Enable Background Agent Support

Before using this workflow, you may need set the environment variable CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS to enable background agent execution and SendMessage communication for better experience:

Option 1: Set in ~/.claude/settings.json (Recommended)

{
  "env": {
    "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
  }
}

Option 2: Set in profile before start claude

export CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1

πŸ“– Documentation: For more details on background agent execution and SendMessage API, see Claude Code Sub-Agents Documentation


When to Use: Multiple source files, or single file >200 lines, or multiple stored procedures/functions, or large-scale migrations requiring strict context management

When NOT to Use: Single small file, simple table structure migration, embedded SQL scripts (Shell/Perl/Python with Here doc SQL), files where temporary tables create inter-statement dependencies

4-Agent Architecture:

Agent Role Key Constraint
Manager (main session) INITIALIZES BACKGROUND AGENTS AT STARTUP, coordinates workflow, strictly verifies Migrator/Tester results, appends to target, communicates via SendMessage 🚫 NEVER reads source files or migration references β€” reads Multi-Agent Migration Guide, NEVER re-spawns agents for each task
Requester (sub-agent) Runs in BACKGROUND MODE β€” initialized once, persists across tasks. Reads source files section-by-section using Read(offset=N, limit=50), identifies complete statement blocks 🚫 EXCLUSIVE file reader β€” no migration knowledge, returns code as-is
Migrator (sub-agent) Runs in BACKGROUND MODE β€” initialized once, persists across tasks. Performs code transformation, unit tests before returning 🚫 ONLY agent that loads migration reference document summaries
Tester (sub-agent) Runs in BACKGROUND MODE β€” initialized once, persists across tasks. Validates migrated code in single VSQL call with autocommit 🚫 Uses own config file (agents/tester.md)

Workflow Loop:

Phase 1: Migration & Functional Testing (per source file, alphabetical order)
  Manager SENDMESSAGE to requester_agent β†’ Requester READS section (offset=N, limit=50) β†’ RETURNS code snippet
  β†’ Manager SENDMESSAGE to migrator_agent β†’ MIGRATES + unit tests (up to 10 attempts)
  β†’ πŸ” MANAGER VERIFIES unit test (logs complete, no anomalies, status PASSED)
  β†’ Manager SENDMESSAGE to tester_agent β†’ FUNCTIONAL TEST (single VSQL call, autocommit, verify no errors)
  β†’ πŸ” MANAGER VERIFIES test results (logs complete, no false positives)
  β†’ PASS β†’ APPEND to target file
  β†’ FAIL β†’ Manager SENDMESSAGE to migrator_agent to fix β†’ RETEST

Phase 2: Integration Testing (after ALL objects migrated)
  Manager SENDMESSAGE to tester_agent: clears test database completely β†’ executes ALL files in order β†’ runs integration test
  β†’ PASS β†’ βœ… Migration complete
  β†’ FAIL β†’ Tester reports failures with complete logs β†’ Manager SENDMESSAGE to migrator_agent with error info and ALL target files β†’ Migrator analyzes errors and fixes issues β†’ Manager SENDMESSAGE to tester_agent to clear test database and re-run integration test β†’ Repeat until pass

Manager's Strict Limits:

  • βœ… ONLY obtains source code from Requester β€” never reads files directly
  • βœ… ONLY creates Requester, Migrator, Tester agents β€” no other agents allowed
  • βœ… ONLY provides process control β€” NEVER gives migration rules/decisions to Migrator
  • βœ… VERIFICATION, not migration expertise β€” verifies test logs, not code correctness
  • βœ… ONLY re-initializes agents if they crash β€” uses SendMessage for all subsequent tasks

Benefits: Focused context windows Β· Clear separation of concerns Β· Dual verification ensures quality Β· Two-phase testing Β· Easy debugging Β· Agents persist across tasks β€” no repeated initialization overhead

Quick Start:

Task: Please use the Multi-Agent Migration Workflow to migrate [source_db] scripts from "[source_path]" to Vertica, saving results to "[target_path]" with identical file names.

You are the Manager agent. Before starting, wait for my confirmation.

Example:

Task: Please use the Multi-Agent Migration Workflow to migrate SQL Server database scripts from "examples/sqlserver/*.sql" to Vertica, saving results to "examples/vertica/" with identical file names.

You are the Manager agent. Before starting, wait for my confirmation.

Then monitor and frequently remind the Manager:

/loop 5m You are the Manager agent. Remember:
1. Never tell Migrator how to migrate, he is the expert of migration, not you.
2. Never tell Tester how to test, he is the expert of testing, not you.
3. Don't disclose the source and target files to anyone.
4. Save state after EVERY task.
5. Use SendMessage for all subsequent tasks. If you lose the IDs of the subagents, just look for them it in the place where Claude stores subagent information.
6. NEVER switch to General Migration Workflow when subagents are unreliable - follow Agent Lifecycle Management (wait β†’ retry β†’ re-initialize β†’ resume).

Manager State File: The Manager agent saves its state to manager_state.md (in current working directory) after every task. This file prevents context loss from compaction and enables recovery from crashes. The file is automatically created and updated by the Multi-Agent Migration Workflow.

For some special situations:

  • Remind the agent when the context is about to be exhausted:

    Save the state in preparation for compacting.
    
  • Continue after compacting context:

    Restore from the state file `manager_state.md` (in current working directory) you saved before compact.
    You have the IDs of the subagents already, just SendMessage with them directly.
    Continue with the current Multi-Agent Migration Workflow.
    
  • Recovery from a crash:

    You are the Manager in Multi-Agent Migration Workflow.
    Load Multi-Agent Migration Workflow guide at first.
    Then restore from the state file `manager_state.md` (in current working directory) you saved before crash.
    You have the IDs of the subagents already, just SendMessage with them directly.
    Continue with the current Multi-Agent Migration Workflow.
    

Reference Documentation:

All agents use their own configuration files (not listed above):

Vertica Development

  1. Design for columnar storage from the beginning
  2. Use appropriate data types for optimal compression
  3. Create projections that match query patterns
  4. Implement proper encoding for each column type
  5. Update statistics regularly after data changes

Performance Tuning

  1. Design projections first before loading data
  2. Use appropriate encoding for each column
  3. Update statistics regularly after data changes
  4. Monitor query performance using system tables
  5. Iterate on optimization based on actual usage

Machine Learning Implementation

  1. Prepare data with feature engineering and cleaning
  2. Select algorithm based on your use case
  3. Train models using in-database functions
  4. Evaluate performance with built-in metrics
  5. Deploy for production with real-time scoring

Testing SQL and Stored Procedures

All SQL examples and stored procedures provided by this skill can be tested using the VSQL command-line tool.

VSQL Testing Setup

The environment variable VSQL encapsulates the vsql connection parameters:

export VSQL='/opt/vertica/bin/vsql -h hostname -p 5433 -U username -w password dbname'

Important Autocommit Behavior: By default, vsql has autocommit OFF for interactive sessions. For testing, either:

  • Enable autocommit: SET SESSION AUTOCOMMIT TO ON;
  • Include explicit COMMIT statements after data modifications

Important Session Behavior: Each $VSQL -c command creates a new session. For data persistence across multiple commands, either:

  1. Use explicit COMMIT statements in DML commands, or
  2. Use here document syntax for multi-statement transactions

Checking Object Availability:

  • Schema: $VSQL -c "\dn schema_name"
  • Table: $VSQL -c "\dt table_name"
  • View: $VSQL -c "\dt view_name"
  • Projection: $VSQL -c "\dj projection_name"
  • Function: $VSQL -c "\df function_name"

Additional VSQL Options:

  • Run SQL file: $VSQL -f script.sql
  • Interactive mode: $VSQL
  • Enable timing: $VSQL -i

VSQL Testing Methods

Single-line SQL commands:

$VSQL -c "SELECT VERSION();"

Multi-line SQL (recommended for stored procedures and complex queries):

$VSQL<<-'EOF'
CREATE OR REPLACE PROCEDURE example_proc() AS $$
BEGIN
    -- Your PL/vSQL code here
    RAISE NOTICE 'Test procedure executed';
END;
$$
EOF

Key Benefits of Here Document:

  • Avoid escaping special characters like $ and "
  • Maintain SQL code formatting and readability
  • Ideal for stored procedures with $$ delimiters

Support and Resources

  • Reference Documentation: comprehensive guides including mandatory Generic Migration Guide and OLTP-to-OLAP Rewrite Guide
  • Migration Hierarchy: Clear documentation structure with Generic Guide as foundation
  • Installation Tools: Easy setup and configuration scripts
  • Best Practices: Proven patterns for development, optimization, and ML
  • Troubleshooting: Common issues and solutions for all use cases
  • Examples: 100+ practical examples across development, migration, and ML

This skill provides everything needed for successful Vertica database migration, development, and machine learning with optimal performance outcomes.

How to Generate the Slides

The slides/ directory contains Python scripts that generate slides using python-pptx. Before running them, make sure the required Python package is installed:

# Check dependency
python3 -c "import pptx; print('python-pptx', pptx.__version__)"
# If missing:
pip install python-pptx

# Generate the presentation
python3 slides/vertica_expert_overview.py

The generated .pptx file will be saved in the slides/ directory.

About

A comprehensive skill for Vertica database migration, including migration from Oracle, DB2, SQL Server, PostgreSQL, MySQL, and Teradata, SQL syntax reference, PL/vSQL stored procedure development, UDx custom function creation, in-database machine learning.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Contributors

Languages