|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Development Commands |
| 6 | + |
| 7 | +### Testing |
| 8 | +- `bundle exec rake spec` - Run all RSpec tests |
| 9 | +- `bundle exec rspec spec/[filename]_spec.rb` - Run specific test file |
| 10 | + |
| 11 | +### Building |
| 12 | +- `bundle exec rake build` - Build the gem |
| 13 | +- `bundle exec rake` - Default task (runs spec and build) |
| 14 | + |
| 15 | +### Code Quality |
| 16 | +- `bundle exec standardrb` - Run StandardRB linter (code style enforcement) |
| 17 | +- `bundle exec standardrb --fix` - Auto-fix style issues |
| 18 | + |
| 19 | +### Model Generation |
| 20 | +- `bundle exec rake modelgen:latest` - Generate model files from latest Trino version |
| 21 | +- `bundle exec rake modelgen:all` - Generate all model versions |
| 22 | + |
| 23 | +## Architecture Overview |
| 24 | + |
| 25 | +This is a Ruby client library for Trino (distributed SQL query engine). The architecture is layered: |
| 26 | + |
| 27 | +### Core Components |
| 28 | + |
| 29 | +1. **Client Layer** (`lib/trino/client/client.rb`): |
| 30 | + - `Trino::Client::Client` - Main API entry point |
| 31 | + - Provides `run()`, `run_with_names()`, `query()`, `kill()` methods |
| 32 | + - Handles synchronous and streaming query execution |
| 33 | + |
| 34 | +2. **Query Layer** (`lib/trino/client/query.rb`): |
| 35 | + - `Query` class - Manages query execution lifecycle |
| 36 | + - Handles streaming results via `each_row`, `each_row_chunk` |
| 37 | + - Provides column metadata and result transformation |
| 38 | + |
| 39 | +3. **Statement Client** (`lib/trino/client/statement_client.rb`): |
| 40 | + - `StatementClient` - Low-level HTTP communication with Trino |
| 41 | + - Manages query state machine (running, finished, failed, aborted) |
| 42 | + - Handles retries, timeouts, and error conditions |
| 43 | + - Supports both JSON and MessagePack response formats |
| 44 | + |
| 45 | +4. **HTTP Layer** (`lib/trino/client/faraday_client.rb`): |
| 46 | + - Uses Faraday for HTTP requests with middleware for gzip and redirects |
| 47 | + - Handles authentication, SSL configuration, proxy settings |
| 48 | + |
| 49 | +### Model System |
| 50 | + |
| 51 | +- **Versioned Models** (`lib/trino/client/model_versions/`): |
| 52 | + - Generated from Trino source code for different Trino versions |
| 53 | + - Each version (351, 316, 303, etc.) has its own model definitions |
| 54 | + - Default is version 351 |
| 55 | + |
| 56 | +- **Model Generation** (`modelgen/`): |
| 57 | + - Automated model generation from Trino Java source |
| 58 | + - Downloads Trino source and extracts model definitions |
| 59 | + |
| 60 | +### Key Features |
| 61 | + |
| 62 | +- **Streaming Results**: Query results can be processed row-by-row without loading all data into memory |
| 63 | +- **Timeout Control**: Supports both query-level and plan-level timeouts |
| 64 | +- **Error Recovery**: Built-in retry logic for transient failures (502, 503, 504) |
| 65 | +- **Multiple Result Formats**: Raw arrays, named hashes, or streaming iteration |
| 66 | +- **ROW Type Support**: Can parse Trino ROW types into Ruby hashes via `transform_row` |
| 67 | + |
| 68 | +### Testing |
| 69 | + |
| 70 | +Tests are organized by component: |
| 71 | +- `spec/client_spec.rb` - Client API tests |
| 72 | +- `spec/statement_client_spec.rb` - Low-level protocol tests |
| 73 | +- `spec/column_value_parser_spec.rb` - Data parsing tests |
| 74 | +- `spec/tpch_query_spec.rb` - Integration tests with TPC-H queries |
0 commit comments