|
1 | 1 | # Spark |
2 | 2 |
|
3 | 3 | Vortex provides a Spark DataSource V2 connector for reading and writing Vortex files. The |
4 | | -connector is published to Maven Central as `dev.vortex:vortex-spark`. |
| 4 | +connector is published to Maven Central in two flavors: |
5 | 5 |
|
6 | | -## Installation |
| 6 | +- `dev.vortex:vortex-spark_2.13` for Spark 4.x (Scala 2.13) |
| 7 | +- `dev.vortex:vortex-spark_2.12` for Spark 3.5.x (Scala 2.12) |
7 | 8 |
|
8 | | -Add the dependency to your build. The connector is built against Spark 4.x with Scala 2.13. |
| 9 | +Use the `all` classifier JAR (e.g. `vortex-spark_2.13-0.78.0-all.jar`). It is self-contained: |
| 10 | +it bundles the Vortex JNI bindings, native libraries for Linux (x86_64 and aarch64) and macOS |
| 11 | +(aarch64), and relocates its Arrow, Guava, and Jackson dependencies to avoid classpath |
| 12 | +conflicts with Spark. The thin (unclassified) JAR does not work on its own because it |
| 13 | +references relocated classes that only ship in the `all` JAR. |
| 14 | + |
| 15 | +## Getting Vortex into Spark |
| 16 | + |
| 17 | +For `spark-shell`, `spark-submit`, or `pyspark`, pass the `all` JAR with `--jars`. Spark |
| 18 | +accepts either a local path or a URL, so you can point directly at Maven Central: |
| 19 | + |
| 20 | +```shell |
| 21 | +spark-shell --jars https://repo1.maven.org/maven2/dev/vortex/vortex-spark_2.13/0.78.0/vortex-spark_2.13-0.78.0-all.jar |
| 22 | +``` |
| 23 | + |
| 24 | +Or equivalently when building a session programmatically, e.g. in PySpark: |
| 25 | + |
| 26 | +```python |
| 27 | +spark = ( |
| 28 | + SparkSession.builder |
| 29 | + .config("spark.jars", "/path/to/vortex-spark_2.13-0.78.0-all.jar") |
| 30 | + .getOrCreate() |
| 31 | +) |
| 32 | +``` |
| 33 | + |
| 34 | +```{note} |
| 35 | +`--packages dev.vortex:vortex-spark_2.13:0.78.0` does not work: `--packages` cannot select |
| 36 | +the `all` classifier and resolves the thin JAR, which fails at runtime with |
| 37 | +`NoClassDefFoundError: dev/vortex/relocated/...`. |
| 38 | +``` |
| 39 | + |
| 40 | +Once the JAR is on the classpath, the connector registers itself automatically under the |
| 41 | +format name `vortex` — no session configuration is required. |
| 42 | + |
| 43 | +## Installation as a Build Dependency |
| 44 | + |
| 45 | +To depend on the connector from a JVM project, add the `all` classifier to the dependency: |
9 | 46 |
|
10 | 47 | ````{tab} Gradle (Kotlin) |
11 | 48 | ```kotlin |
12 | | -implementation("dev.vortex:vortex-spark:<version>") |
| 49 | +implementation("dev.vortex:vortex-spark_2.13:0.78.0:all") |
13 | 50 | ``` |
14 | 51 | ```` |
15 | 52 |
|
16 | 53 | ````{tab} Maven |
17 | 54 | ```xml |
18 | 55 | <dependency> |
19 | 56 | <groupId>dev.vortex</groupId> |
20 | | - <artifactId>vortex-spark</artifactId> |
21 | | - <version>${vortex.version}</version> |
| 57 | + <artifactId>vortex-spark_2.13</artifactId> |
| 58 | + <version>0.78.0</version> |
| 59 | + <classifier>all</classifier> |
22 | 60 | </dependency> |
23 | 61 | ``` |
24 | 62 | ```` |
25 | 63 |
|
26 | | -The connector ships as a shadow JAR that relocates its Arrow, Guava, and Protobuf dependencies |
27 | | -to avoid classpath conflicts with Spark. |
28 | | - |
29 | 64 | ## Reading Vortex Files |
30 | 65 |
|
31 | | -Use the `vortex` format to read a single file or a directory of Vortex files: |
| 66 | +Paths may be local filesystem paths (`/path/to/data`) or URLs (`file:///path/to/data`, |
| 67 | +`s3://bucket/path/to/data`). Use the `vortex` format to read a single file or a directory of |
| 68 | +Vortex files: |
32 | 69 |
|
33 | 70 | ```java |
34 | 71 | Dataset<Row> df = spark.read() |
@@ -65,6 +102,72 @@ Each Spark partition produces one output file named `part-{partitionId}-{taskId} |
65 | 102 | The connector supports all standard Spark save modes: `Overwrite`, `Append`, `Ignore`, and |
66 | 103 | `ErrorIfExists`. |
67 | 104 |
|
| 105 | +## Spark SQL |
| 106 | + |
| 107 | +The connector can also be used from pure SQL. To query existing Vortex files, register them |
| 108 | +as a temporary view: |
| 109 | + |
| 110 | +```sql |
| 111 | +CREATE TEMPORARY VIEW people |
| 112 | +USING vortex |
| 113 | +OPTIONS (path '/path/to/data'); |
| 114 | + |
| 115 | +SELECT name, age FROM people WHERE age > 30; |
| 116 | +``` |
| 117 | + |
| 118 | +Tables can be created with `USING vortex`, then written to and read back with plain SQL. |
| 119 | +With a `LOCATION` clause the table is external, backed by the files at that path; without |
| 120 | +one the table is managed, and Spark stores its data under the warehouse directory (and |
| 121 | +deletes it on `DROP TABLE`): |
| 122 | + |
| 123 | +```sql |
| 124 | +CREATE TABLE student (id INT, name STRING, age INT) |
| 125 | +USING vortex; |
| 126 | + |
| 127 | +INSERT INTO student VALUES (1, 'Alice', 20), (2, 'Bob', 21); |
| 128 | + |
| 129 | +SELECT * FROM student; |
| 130 | +``` |
| 131 | + |
| 132 | +`CREATE TABLE ... AS SELECT` works the same way: |
| 133 | + |
| 134 | +```sql |
| 135 | +CREATE TABLE adults |
| 136 | +USING vortex |
| 137 | +AS SELECT * FROM people WHERE age >= 18; |
| 138 | +``` |
| 139 | + |
| 140 | +```{note} |
| 141 | +On Spark 3.5, `CREATE TABLE ... USING vortex` additionally requires replacing the session |
| 142 | +catalog, because Spark 3.5's built-in catalog cannot read tables backed by a DataSource |
| 143 | +V2-only connector: |
| 144 | +
|
| 145 | + spark.sql.catalog.spark_catalog=dev.vortex.spark.VortexSessionCatalog |
| 146 | +
|
| 147 | +The extension delegates everything to the built-in session catalog (including the Hive |
| 148 | +metastore, if configured) and only changes how `vortex` tables are resolved; tables of other |
| 149 | +providers are untouched. It is not needed on Spark 4, though setting it is harmless. |
| 150 | +``` |
| 151 | + |
| 152 | +## Direct File Queries |
| 153 | + |
| 154 | +Spark's built-in ``SELECT * FROM format.`path` `` syntax only works for built-in file |
| 155 | +formats, so the connector ships a path-based catalog that provides the equivalent for |
| 156 | +Vortex. Register it in the session configuration under the name `vortex`: |
| 157 | + |
| 158 | +```shell |
| 159 | +spark-sql --conf spark.sql.catalog.vortex=dev.vortex.spark.VortexCatalog |
| 160 | +``` |
| 161 | + |
| 162 | +Then query a Vortex file, or a directory of Vortex files, directly by path — no view or |
| 163 | +table required: |
| 164 | + |
| 165 | +```sql |
| 166 | +SELECT * FROM vortex.`/path/to/data`; |
| 167 | + |
| 168 | +INSERT INTO vortex.`/path/to/data` VALUES (1, 'Alice', 20); |
| 169 | +``` |
| 170 | + |
68 | 171 | ## Supported Types |
69 | 172 |
|
70 | 173 | | Spark Type | Vortex Type | |
|
0 commit comments