|
| 1 | +# Multi-Variant Spark/Scala Build System |
| 2 | + |
| 3 | +This document describes how to build and publish multiple Spark/Scala variants of the substrait-spark module. |
| 4 | + |
| 5 | +## Supported Variants |
| 6 | + |
| 7 | +The substrait-spark module supports three build variants: |
| 8 | + |
| 9 | +| Variant | Spark Version | Scala Version | Classifier | Subproject | |
| 10 | +|---------|---------------|---------------|------------|------------| |
| 11 | +| Spark 3.4 | 3.4.4 | 2.12.20 | `spark34_2.12` | `:spark:spark-3.4_2.12` | |
| 12 | +| Spark 3.5 | 3.5.4 | 2.12.20 | `spark35_2.12` | `:spark:spark-3.5_2.12` | |
| 13 | +| Spark 4.0 | 4.0.2 | 2.13.18 | `spark40_2.13` | `:spark:spark-4.0_2.13` | |
| 14 | + |
| 15 | +## Architecture |
| 16 | + |
| 17 | +The build system uses **Gradle subprojects** for each variant. |
| 18 | + |
| 19 | +### Project Structure |
| 20 | + |
| 21 | +``` |
| 22 | +spark/ |
| 23 | +├── build.gradle.kts # Orchestrator project |
| 24 | +├── src/ # Shared source code |
| 25 | +│ ├── main/ |
| 26 | +│ │ ├── scala/ # Common code for all versions |
| 27 | +│ │ ├── spark-3.4/ # Spark 3.4 specific implementations |
| 28 | +│ │ ├── spark-3.5/ # Spark 3.5 specific implementations |
| 29 | +│ │ └── spark-4.0/ # Spark 4.0 specific implementations |
| 30 | +│ └── test/ |
| 31 | +│ ├── scala/ # Common test code |
| 32 | +│ ├── spark-3.4/ # Spark 3.4 specific tests |
| 33 | +│ ├── spark-3.5/ # Spark 3.5 specific tests |
| 34 | +│ └── spark-4.0/ # Spark 4.0 specific tests |
| 35 | +├── spark-3.4_2.12/ |
| 36 | +│ └── build.gradle.kts # Spark 3.4 variant build |
| 37 | +├── spark-3.5_2.12/ |
| 38 | +│ └── build.gradle.kts # Spark 3.5 variant build |
| 39 | +└── spark-4.0_2.13/ |
| 40 | + └── build.gradle.kts # Spark 4.0 variant build |
| 41 | +``` |
| 42 | + |
| 43 | +Each subproject references the shared source code in `../src/` using Gradle's source set configuration. |
| 44 | + |
| 45 | +## Building Variants |
| 46 | + |
| 47 | +### Build a Specific Variant |
| 48 | + |
| 49 | +Build a specific variant using its subproject path: |
| 50 | + |
| 51 | +```bash |
| 52 | +# Build Spark 3.4 with Scala 2.12 |
| 53 | +./gradlew :spark:spark-3.4_2.12:build |
| 54 | + |
| 55 | +# Build Spark 3.5 with Scala 2.12 |
| 56 | +./gradlew :spark:spark-3.5_2.12:build |
| 57 | + |
| 58 | +# Build Spark 4.0 with Scala 2.13 |
| 59 | +./gradlew :spark:spark-4.0_2.13:build |
| 60 | +``` |
| 61 | + |
| 62 | +### Build All Variants |
| 63 | + |
| 64 | +To build all variants: |
| 65 | + |
| 66 | +```bash |
| 67 | +./gradlew :spark:build |
| 68 | +``` |
| 69 | + |
| 70 | +## Publishing Variants |
| 71 | + |
| 72 | +### Publish to Local Maven Repository |
| 73 | + |
| 74 | +Publish a specific variant: |
| 75 | + |
| 76 | +```bash |
| 77 | +# Publish Spark 3.4 with Scala 2.12 |
| 78 | +./gradlew :spark:spark-3.4_2.12:publishToMavenLocal |
| 79 | + |
| 80 | +# Publish Spark 3.5 with Scala 2.12 |
| 81 | +./gradlew :spark:spark-3.5_2.12:publishToMavenLocal |
| 82 | + |
| 83 | +# Publish Spark 4.0 with Scala 2.13 |
| 84 | +./gradlew :spark:spark-4.0_2.13:publishToMavenLocal |
| 85 | +``` |
| 86 | + |
| 87 | +### Publish All Variants |
| 88 | + |
| 89 | +To publish all variants to your local Maven repository: |
| 90 | + |
| 91 | +```bash |
| 92 | +./gradlew :spark:publishAllVariants |
| 93 | +``` |
| 94 | + |
| 95 | +Published artifacts will be available at: |
| 96 | +``` |
| 97 | +~/.m2/repository/io/substrait/{classifier}/{version}/ |
| 98 | +``` |
| 99 | + |
| 100 | +For example: |
| 101 | +- `~/.m2/repository/io/substrait/spark34_2.12/0.78.0/` |
| 102 | +- `~/.m2/repository/io/substrait/spark35_2.12/0.78.0/` |
| 103 | +- `~/.m2/repository/io/substrait/spark40_2.13/0.78.0/` |
| 104 | + |
| 105 | +### Publish to Maven Central Portal |
| 106 | + |
| 107 | +Publish all variants to Maven Central: |
| 108 | + |
| 109 | +```bash |
| 110 | +./gradlew :spark:publishAllVariantsToCentralPortal |
| 111 | +``` |
| 112 | + |
| 113 | +Or publish a specific variant: |
| 114 | + |
| 115 | +```bash |
| 116 | +./gradlew :spark:spark-4.0_2.13:publishMaven-publishPublicationToNmcpRepository |
| 117 | +``` |
| 118 | + |
| 119 | +## Using Published Artifacts |
| 120 | + |
| 121 | +### Maven |
| 122 | + |
| 123 | +Add the appropriate variant as a dependency in your `pom.xml`: |
| 124 | + |
| 125 | +```xml |
| 126 | +<!-- Spark 3.4 with Scala 2.12 --> |
| 127 | +<dependency> |
| 128 | + <groupId>io.substrait</groupId> |
| 129 | + <artifactId>spark34_2.12</artifactId> |
| 130 | + <version>0.80.0</version> |
| 131 | +</dependency> |
| 132 | + |
| 133 | +<!-- Spark 3.5 with Scala 2.12 --> |
| 134 | +<dependency> |
| 135 | + <groupId>io.substrait</groupId> |
| 136 | + <artifactId>spark35_2.12</artifactId> |
| 137 | + <version>0.80.0</version> |
| 138 | +</dependency> |
| 139 | + |
| 140 | +<!-- Spark 4.0 with Scala 2.13 --> |
| 141 | +<dependency> |
| 142 | + <groupId>io.substrait</groupId> |
| 143 | + <artifactId>spark40_2.13</artifactId> |
| 144 | + <version>0.80.0</version> |
| 145 | +</dependency> |
| 146 | +``` |
| 147 | + |
| 148 | +### Gradle |
| 149 | + |
| 150 | +Add the appropriate variant as a dependency in your `build.gradle.kts`: |
| 151 | + |
| 152 | +```kotlin |
| 153 | +dependencies { |
| 154 | + // Spark 3.4 with Scala 2.12 |
| 155 | + implementation("io.substrait:spark34_2.12:0.80.0") |
| 156 | + |
| 157 | + // Spark 3.5 with Scala 2.12 |
| 158 | + implementation("io.substrait:spark35_2.12:0.80.0") |
| 159 | + |
| 160 | + // Spark 4.0 with Scala 2.13 |
| 161 | + implementation("io.substrait:spark40_2.13:0.80.0") |
| 162 | +} |
| 163 | +``` |
| 164 | + |
| 165 | +## Development Workflow |
| 166 | + |
| 167 | +### Adding Support for a New Spark Version |
| 168 | + |
| 169 | +1. **Create a new subproject directory**: |
| 170 | + ```bash |
| 171 | + mkdir -p spark/spark-4.1_2.13 |
| 172 | + ``` |
| 173 | + |
| 174 | +2. **Copy and modify a build.gradle.kts** from an existing variant: |
| 175 | + ```bash |
| 176 | + cp spark/spark-4.0_2.13/build.gradle.kts spark/spark-4.1_2.13/ |
| 177 | + ``` |
| 178 | + |
| 179 | +3. **Update the variant configuration** in the new `build.gradle.kts`: |
| 180 | + ```kotlin |
| 181 | + val sparkVersion = "4.1.0" |
| 182 | + val scalaVersion = "2.13.18" |
| 183 | + val sparkMajorMinor = "4.1" |
| 184 | + val scalaBinary = "2.13" |
| 185 | + val classifier = "spark41_2.13" |
| 186 | + ``` |
| 187 | + |
| 188 | +4. **Add the subproject** to `settings.gradle.kts`: |
| 189 | + ```kotlin |
| 190 | + include( |
| 191 | + // ... existing projects |
| 192 | + "spark:spark-4.1_2.13", |
| 193 | + ) |
| 194 | + ``` |
| 195 | + |
| 196 | +5. **Update the orchestrator** in `spark/build.gradle.kts`: |
| 197 | + ```kotlin |
| 198 | + tasks.register("buildAllVariants") { |
| 199 | + dependsOn( |
| 200 | + // ... existing variants |
| 201 | + ":spark:spark-4.1_2.13:build" |
| 202 | + ) |
| 203 | + } |
| 204 | + ``` |
| 205 | + |
| 206 | +6. **Create version-specific source directory**: |
| 207 | + ```bash |
| 208 | + mkdir -p spark/src/main/spark-4.1 |
| 209 | + mkdir -p spark/src/test/spark-4.1 |
| 210 | + ``` |
| 211 | + |
| 212 | +7. **Add version-specific implementations** for classes with API differences |
| 213 | + |
| 214 | +8. **Test the new variant**: |
| 215 | + ```bash |
| 216 | + ./gradlew :spark:spark-4.1_2.13:build |
| 217 | + ``` |
| 218 | + |
| 219 | +### Testing Changes Across All Variants |
| 220 | + |
| 221 | +When making changes to common code, test all variants: |
| 222 | + |
| 223 | +```bash |
| 224 | +# Quick compilation test for all variants |
| 225 | +./gradlew :spark:spark-3.4_2.12:compileScala |
| 226 | +./gradlew :spark:spark-3.5_2.12:compileScala |
| 227 | +./gradlew :spark:spark-4.0_2.13:compileScala |
| 228 | + |
| 229 | +# Or run full build for all variants |
| 230 | +./gradlew :spark:buildAllVariants |
| 231 | +``` |
| 232 | + |
| 233 | +### Cleaning Build Artifacts |
| 234 | + |
| 235 | +```bash |
| 236 | +# Clean a specific variant |
| 237 | +./gradlew :spark:spark-4.0_2.13:clean |
| 238 | + |
| 239 | +# Clean all variants |
| 240 | +./gradlew :spark:clean |
| 241 | +``` |
0 commit comments