|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Build and Development Commands |
| 6 | + |
| 7 | +### Core Build System |
| 8 | +- **Build tool**: sbt (Scala Build Tool) version 1.11.0 |
| 9 | +- **Build project**: `build/sbt compile` |
| 10 | +- **Run all tests**: `build/sbt test` |
| 11 | +- **Run single test suite**: `build/sbt "testOnly *PregelSuite"` |
| 12 | +- **Run single test**: `build/sbt "testOnly *PregelSuite -- -z 'test name pattern'"` |
| 13 | +- **Check code formatting**: `build/sbt scalafmtCheckAll` |
| 14 | +- **Apply code formatting**: `build/sbt scalafmtAll` |
| 15 | +- **Check code style**: `build/sbt "scalafixAll --check"` |
| 16 | +- **Generate documentation**: `build/sbt doc` |
| 17 | +- **Run with coverage**: `build/sbt "coverage test coverageReport"` |
| 18 | + |
| 19 | +### Multi-Spark Version Testing |
| 20 | +The project supports multiple Spark versions. Use `-Dspark.version=X.Y.Z` to specify: |
| 21 | +- `build/sbt -Dspark.version=3.5.7 test` |
| 22 | +- `build/sbt -Dspark.version=4.0.1 test` |
| 23 | +- `build/sbt -Dspark.version=4.1.0 test` |
| 24 | + |
| 25 | +### Pre-PR Checklist Commands |
| 26 | +Before raising a pull request, run these commands to ensure code quality and compatibility: |
| 27 | + |
| 28 | +1. **Format code**: `build/sbt scalafmtAll` |
| 29 | +2. **Check formatting**: `build/sbt scalafmtCheckAll` |
| 30 | +3. **Check style/linting**: `build/sbt "scalafixAll --check"` |
| 31 | +4. **Build documentation**: `build/sbt doc` |
| 32 | +5. **Run tests with coverage**: `build/sbt "coverage test coverageReport"` |
| 33 | +6. **Test against multiple Spark versions**: |
| 34 | + - `build/sbt -Dspark.version=3.5.7 test` |
| 35 | + - `build/sbt -Dspark.version=4.0.1 test` |
| 36 | + - `build/sbt -Dspark.version=4.1.0 test` |
| 37 | + |
| 38 | +**Alternative using pre-commit**: `pre-commit run all-files` (handles Python formatting: black, isort, flake8) |
| 39 | + |
| 40 | +### Python Components |
| 41 | +- **Python package location**: `/python/` directory |
| 42 | +- **Python tests**: Located in `/python/tests/` |
| 43 | + |
| 44 | +## Architecture Overview |
| 45 | + |
| 46 | +### Core Structure |
| 47 | +GraphFrames is a graph processing library built on Apache Spark DataFrames with three main components: |
| 48 | + |
| 49 | +1. **Core GraphFrame API** (`core/src/main/scala/org/graphframes/`) |
| 50 | + - `GraphFrame.scala`: Main graph abstraction using DataFrames for vertices/edges |
| 51 | + - Provides graph algorithms, motif finding, and subgraph operations |
| 52 | + |
| 53 | +2. **Algorithm Library** (`core/src/main/scala/org/graphframes/lib/`) |
| 54 | + - Standard graph algorithms: PageRank, ConnectedComponents, ShortestPaths, etc. |
| 55 | + - `Pregel.scala`: Implements Pregel-style bulk synchronous parallel processing |
| 56 | + - `AggregateMessages.scala`: Lower-level message-passing API |
| 57 | + |
| 58 | +3. **GraphX Compatibility Layer** (`graphx/src/main/scala/`) |
| 59 | + - Provides GraphX-compatible APIs for migration |
| 60 | + - Bridges between DataFrame and RDD-based graph operations |
| 61 | + |
| 62 | +### Key Design Patterns |
| 63 | + |
| 64 | +**Spark Version Compatibility**: Uses `SparkShims` pattern for version-specific implementations: |
| 65 | +- `core/src/main/scala-spark-3/`: Spark 3.x specific code |
| 66 | +- `core/src/main/scala-spark-4/`: Spark 4.x specific code |
| 67 | +- Common interface in main scala directory |
| 68 | + |
| 69 | +**DataFrame-Centric Design**: Unlike GraphX's RDD approach, GraphFrames uses DataFrames throughout: |
| 70 | +- Vertices and edges are DataFrames with required schema (id column for vertices, src/dst for edges) |
| 71 | +- Leverages Spark SQL optimizations and Catalyst query planner |
| 72 | +- Allows mixing graph operations with relational queries |
| 73 | + |
| 74 | +**Algorithm Framework**: Most algorithms follow this pattern: |
| 75 | +- Extend base traits like `Logging`, `WithLocalCheckpoints`, `WithIntermediateStorageLevel` |
| 76 | +- Use builder pattern for configuration (e.g., `graph.pregel.withVertexColumn(...).sendMsgToDst(...).run()`) |
| 77 | +- Support checkpointing and persistence for iterative algorithms |
| 78 | + |
| 79 | +### Performance Considerations |
| 80 | + |
| 81 | +**Pregel Optimizations**: The Pregel implementation includes automatic optimizations: |
| 82 | +- Detects when destination vertex state is unneeded and skips expensive joins |
| 83 | +- Conditional partitioning (source-only vs source+destination) |
| 84 | +- Automatic caching of intermediate results when beneficial |
| 85 | + |
| 86 | +**Memory Management**: |
| 87 | +- Uses configurable storage levels for persistence |
| 88 | +- Automatic cleanup of intermediate DataFrames between iterations |
| 89 | +- Checkpoint support for long-running iterative algorithms |
| 90 | + |
| 91 | +## Testing Structure |
| 92 | + |
| 93 | +### Test Organization |
| 94 | +- **Base test class**: `SparkFunSuite` provides SparkContext setup |
| 95 | +- **Algorithm tests**: Each algorithm has corresponding `*Suite.scala` in `lib/` subdirectory |
| 96 | +- **Integration tests**: `GraphFrameSuite.scala` for core API functionality |
| 97 | +- **Pattern matching**: `PatternSuite.scala` for motif finding features |
| 98 | + |
| 99 | +### Running Specific Tests |
| 100 | +- Algorithm-specific: `build/sbt "testOnly *PageRankSuite"` |
| 101 | +- Core functionality: `build/sbt "testOnly *GraphFrameSuite"` |
| 102 | +- Pregel framework: `build/sbt "testOnly *PregelSuite"` |
| 103 | +- All lib tests: `build/sbt "testOnly org.graphframes.lib.*"` |
| 104 | + |
| 105 | +### Multi-Version Testing |
| 106 | +Tests run against multiple Spark versions in CI. The build system automatically: |
| 107 | +- Selects appropriate Scala versions based on Spark version |
| 108 | +- Uses version-specific SparkShims implementations |
| 109 | +- Validates compatibility across Spark 3.5+ and 4.0+ |
| 110 | + |
| 111 | +## Multi-Language Support |
| 112 | + |
| 113 | +### Scala (Primary) |
| 114 | +- Main implementation in `core/src/main/scala/` |
| 115 | +- Uses Scala 2.12/2.13 depending on Spark version |
| 116 | +- Follows Spark's coding conventions and patterns |
| 117 | + |
| 118 | +### Python |
| 119 | +- Python bindings in `python/graphframes/` |
| 120 | +- Wraps Scala API using Spark's Python gateway |
| 121 | +- Separate test suite in `python/tests/` |
| 122 | + |
| 123 | +### Java |
| 124 | +- Java examples in `core/src/main/java/` |
| 125 | +- Uses Scala API through Java interop |
| 126 | +- Follows JavaBean conventions where applicable |
| 127 | + |
| 128 | +## Development Workflow |
| 129 | + |
| 130 | +### Code Quality |
| 131 | +- **Formatting**: scalafmt for Scala, black/isort/flake8 for Python |
| 132 | +- **Style checking**: scalafix for Scala linting |
| 133 | +- **Pre-commit hooks**: Available via `pre-commit run all-files` |
| 134 | + |
| 135 | +### Contribution Requirements |
| 136 | +- All new algorithms must include comprehensive test coverage |
| 137 | +- Performance-critical code should include benchmarks (`benchmarks/` directory) |
| 138 | +- Multi-version compatibility must be maintained |
| 139 | +- Documentation updates required for new features |
| 140 | + |
| 141 | +### Release Process |
| 142 | +The project uses automated releases through GitHub Actions: |
| 143 | +- Scala artifacts published to Maven Central |
| 144 | +- Python packages published to PyPI |
| 145 | +- Documentation deployed to graphframes.io |
0 commit comments