Quick Start

Preparation

Paimon currently supports Spark 3.5, 3.4, 3.3, 3.2 and 3.1. We recommend the latest Spark version for a better experience.

Download the jar file with corresponding version.

VersionJar
Spark 3.5paimon-spark-3.5-0.8.2.jar
Spark 3.4paimon-spark-3.4-0.8.2.jar
Spark 3.3paimon-spark-3.3-0.8.2.jar
Spark 3.2paimon-spark-3.2-0.8.2.jar
Spark 3.1paimon-spark-3.1-0.8.2.jar

You can also manually build bundled jar from the source code.

To build from source code, clone the git repository.

Build bundled jar with the following command.

  1. mvn clean install -DskipTests

For Spark 3.3, you can find the bundled jar in ./paimon-spark/paimon-spark-3.3/target/paimon-spark-3.3-0.8.2.jar.

Setup

If you are using HDFS, make sure that the environment variable HADOOP_HOME or HADOOP_CONF_DIR is set.

Step 1: Specify Paimon Jar File

Append path to paimon jar file to the --jars argument when starting spark-sql.

  1. spark-sql ... --jars /path/to/paimon-spark-3.3-0.8.2.jar

OR use the --packages option.

  1. spark-sql ... --packages org.apache.paimon:paimon-spark-3.3:0.8.2

Alternatively, you can copy paimon-spark-3.3-0.8.2.jar under spark/jars in your Spark installation directory.

Step 2: Specify Paimon Catalog

Catalog

When starting spark-sql, use the following command to register Paimon’s Spark catalog with the name paimon. Table files of the warehouse is stored under /tmp/paimon.

  1. spark-sql ... \
  2. --conf spark.sql.catalog.paimon=org.apache.paimon.spark.SparkCatalog \
  3. --conf spark.sql.catalog.paimon.warehouse=file:/tmp/paimon \
  4. --conf spark.sql.extensions=org.apache.paimon.spark.extensions.PaimonSparkSessionExtensions

Catalogs are configured using properties under spark.sql.catalog.(catalog_name). In above case, ‘paimon’ is the catalog name, you can change it to your own favorite catalog name.

After spark-sql command line has started, run the following SQL to create and switch to database default.

  1. USE paimon;
  2. USE default;

After switching to the catalog ('USE paimon'), Spark’s existing tables will not be directly accessible, you can use the spark_catalog.${database_name}.${table_name} to access Spark tables.

Generic Catalog

When starting spark-sql, use the following command to register Paimon’s Spark Generic catalog to replace Spark default catalog spark_catalog. (default warehouse is Spark spark.sql.warehouse.dir)

Currently, it is only recommended to use SparkGenericCatalog in the case of Hive metastore, Paimon will infer Hive conf from Spark session, you just need to configure Spark’s Hive conf.

  1. spark-sql ... \
  2. --conf spark.sql.catalog.spark_catalog=org.apache.paimon.spark.SparkGenericCatalog \
  3. --conf spark.sql.extensions=org.apache.paimon.spark.extensions.PaimonSparkSessionExtensions

Using SparkGenericCatalog, you can use Paimon tables in this Catalog or non-Paimon tables such as Spark’s csv, parquet, Hive tables, etc.

Create Table

Catalog

  1. create table my_table (
  2. k int,
  3. v string
  4. ) tblproperties (
  5. 'primary-key' = 'k'
  6. );

Generic Catalog

  1. create table my_table (
  2. k int,
  3. v string
  4. ) USING paimon
  5. tblproperties (
  6. 'primary-key' = 'k'
  7. ) ;

Insert Table

Paimon currently supports Spark 3.2+ for SQL write.

  1. INSERT INTO my_table VALUES (1, 'Hi'), (2, 'Hello');

Query Table

SQL

  1. SELECT * FROM my_table;
  2. /*
  3. 1 Hi
  4. 2 Hello
  5. */

DataFrame

  1. val dataset = spark.read.format("paimon").load("file:/tmp/paimon/default.db/my_table")
  2. dataset.show()
  3. /*
  4. +---+------+
  5. | k | v|
  6. +---+------+
  7. | 1| Hi|
  8. | 2| Hello|
  9. +---+------+
  10. */

Spark Type Conversion

This section lists all supported type conversion between Spark and Paimon. All Spark’s data types are available in package org.apache.spark.sql.types.

Spark Data TypePaimon Data TypeAtomic Type
StructTypeRowTypefalse
MapTypeMapTypefalse
ArrayTypeArrayTypefalse
BooleanTypeBooleanTypetrue
ByteTypeTinyIntTypetrue
ShortTypeSmallIntTypetrue
IntegerTypeIntTypetrue
LongTypeBigIntTypetrue
FloatTypeFloatTypetrue
DoubleTypeDoubleTypetrue
StringTypeVarCharType, CharTypetrue
DateTypeDateTypetrue
TimestampTypeTimestampType, LocalZonedTimestamptrue
DecimalType(precision, scale)DecimalType(precision, scale)true
BinaryTypeVarBinaryType, BinaryTypetrue