Skip to main content
Version: 0.5.0

Gravitino Spark connector

Overview

The Gravitino Spark connector leverages the Spark DataSourceV2 interface to facilitate the management of diverse catalogs under Gravitino. This capability allows users to perform federation queries, accessing data from various catalogs through a unified interface and consistent access control.

Capabilities

  1. Supports Hive catalog and Iceberg catalog.
  2. Supports federation query.
  3. Supports most DDL and DML SQLs.

Requirement

  • Spark 3.4
  • Scala 2.12
  • JDK 8,11,17

How to use it

  1. Build or download the Gravitino spark connector jar, and place it to the classpath of Spark.
  2. Configure the Spark session to use the Gravitino spark connector.
PropertyTypeDefault ValueDescriptionRequiredSince Version
spark.pluginsstring(none)Gravitino spark plugin name, com.datastrato.gravitino.spark.connector.plugin.GravitinoSparkPluginYes0.5.0
spark.sql.gravitino.metalakestring(none)The metalake name that spark connector used to request to Gravitino.Yes0.5.0
spark.sql.gravitino.uristring(none)The uri of Gravitino server address.Yes0.5.0
./bin/spark-sql -v \
--conf spark.plugins="com.datastrato.gravitino.spark.connector.plugin.GravitinoSparkPlugin" \
--conf spark.sql.gravitino.uri=http://127.0.0.1:8090 \
--conf spark.sql.gravitino.metalake=test \
--conf spark.sql.warehouse.dir=hdfs://127.0.0.1:9000/user/hive/warehouse-hive
  1. Execute the Spark SQL query.

Suppose there are two catalogs in the metalake test, hive for Hive catalog and iceberg for Iceberg catalog.

// use hive catalog
USE hive;
CREATE DATABASE db;
USE db;
CREATE TABLE hive_students (id INT, name STRING);
INSERT INTO hive_students VALUES (1, 'Alice'), (2, 'Bob');

// use Iceberg catalog
USE iceberg;
USE db;
CREATE TABLE IF NOT EXISTS iceberg_scores (id INT, score INT) USING iceberg;
INSERT INTO iceberg_scores VALUES (1, 95), (2, 88);

// execute federation query between hive table and iceberg table
SELECT hs.name, is.score FROM hive.db.hive_students hs JOIN iceberg_scores is ON hs.id = is.id;
info

The command SHOW CATALOGS will only display the Spark default catalog, named spark_catalog, due to limitations within the Spark catalog manager. It does not list the catalogs present in the metalake. However, after explicitly using the USE command with a specific catalog name, that catalog name then becomes visible in the output of SHOW CATALOGS.

Datatype mapping

Gravitino spark connector support the following datatype mapping between Spark and Gravitino.

Spark Data TypeGravitino Data TypeSince Version
BooleanTypeboolean0.5.0
ByteTypebyte0.5.0
ShortTypeshort0.5.0
IntegerTypeinteger0.5.0
LongTypelong0.5.0
FloatTypefloat0.5.0
DoubleTypedouble0.5.0
DecimalTypedecimal0.5.0
StringTypestring0.5.0
CharTypechar0.5.0
VarcharTypevarchar0.5.0
TimestampTypetimestamp0.5.0
TimestampTypetimestamp0.5.0
DateTypedate0.5.0
BinaryTypebinary0.5.0
ArrayTypearray0.5.0
MapTypemap0.5.0
StructTypestruct0.5.0