Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Apache Paimon DataType

From Leeroopedia


Knowledge Sources
Domains Type System, Data Structures
Last Updated 2026-02-08 00:00 GMT

Overview

DataType is the abstract base class that describes all data types in the Apache Paimon ecosystem, providing the foundation for Paimon's type system.

Description

DataType is an abstract, serializable class that serves as the root of Paimon's type hierarchy. Every data type in Paimon extends this class, which encapsulates two fundamental properties: nullability (whether values can be null) and a DataTypeRoot that represents the essential type category without parameters. For example, DECIMAL(10,2) and DECIMAL(20,5) both share the DECIMAL root but differ in their parameters.

The class provides essential functionality for all types including type checking methods like is() and isAnyOf() for comparing against type roots and families, copy operations for creating variants with different nullability, and visitor pattern support through the accept() method for type system traversal. It defines abstract methods that subclasses must implement: defaultSize() for internal size estimation, copy(boolean) for deep copying with configurable nullability, asSQLString() for SQL representation, and accept() for visitor pattern implementation.

DataType supports comprehensive equality comparisons including standard equals(), equalsIgnoreNullable() for comparing types regardless of null constraints, equalsIgnoreFieldId() for comparing complex types without field ID considerations, and isPrunedFrom() to determine if a type is derived from another through column pruning. Available since version 0.4.0 and marked @Public, DataType forms the contract that all type implementations must follow.

Usage

Use DataType as the base for all type definitions in schemas, queries, and data processing. Reference it when writing code that works with any data type generically, when implementing custom type visitors, or when performing type checking and validation across Paimon's type system.

Code Reference

Source Location

Signature

@Public
public abstract class DataType implements Serializable {

    public DataType(boolean isNullable, DataTypeRoot typeRoot)

    public boolean isNullable()

    public DataTypeRoot getTypeRoot()

    public boolean is(DataTypeRoot typeRoot)

    public boolean isAnyOf(DataTypeRoot... typeRoots)

    public boolean isAnyOf(DataTypeFamily... typeFamilies)

    public boolean is(DataTypeFamily family)

    public abstract int defaultSize()

    public abstract DataType copy(boolean isNullable)

    public final DataType copy()

    public boolean equalsIgnoreNullable(DataType o)

    public boolean equalsIgnoreFieldId(DataType o)

    public boolean isPrunedFrom(Object o)

    public abstract String asSQLString()

    public void serializeJson(JsonGenerator generator) throws IOException

    public abstract <R> R accept(DataTypeVisitor<R> visitor)

    public void collectFieldIds(Set<Integer> fieldIds)

    public DataType notNull()

    public DataType nullable()
}

Import

import org.apache.paimon.types.DataType;

I/O Contract

Inputs

Name Type Required Description
isNullable boolean Yes Whether the type allows null values
typeRoot DataTypeRoot Yes The root category of this type (e.g., INTEGER, VARCHAR)

Outputs

Name Type Description
Type root DataTypeRoot The essential type category
Nullability boolean Whether null values are permitted
SQL string String Human-readable SQL representation of the type
Default size int Internal size estimation in bytes
Copied type DataType Deep copy with potentially different nullability

Usage Examples

// Check type properties
DataType type = DataTypes.INT();
boolean nullable = type.isNullable(); // true by default
DataTypeRoot root = type.getTypeRoot(); // DataTypeRoot.INTEGER

// Type checking
if (type.is(DataTypeRoot.INTEGER)) {
    // Handle integer type
}

if (type.isAnyOf(DataTypeRoot.INTEGER, DataTypeRoot.BIGINT)) {
    // Handle any integer type
}

if (type.is(DataTypeFamily.NUMERIC)) {
    // Handle numeric family
}

// Create non-nullable version
DataType nonNull = type.notNull();
DataType nullableAgain = nonNull.nullable();

// Copy with different nullability
DataType copy = type.copy(false);

// Get SQL representation
String sql = type.asSQLString(); // "INT"

// Compare types
DataType type1 = DataTypes.INT();
DataType type2 = DataTypes.INT().notNull();
boolean sameIgnoringNull = type1.equalsIgnoreNullable(type2); // true

// Visitor pattern
Integer result = type.accept(new DataTypeVisitor<Integer>() {
    @Override
    public Integer visit(IntType intType) {
        return intType.defaultSize();
    }
    // ... other visit methods
});

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment