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 DataTypes Java

From Leeroopedia
Revision as of 14:20, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Apache_Paimon_DataTypes_Java.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


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

Overview

DataTypes is a utility class providing factory methods for creating all data types supported by Apache Paimon's type system.

Description

DataTypes is a public class offering a comprehensive collection of static factory methods for instantiating DataType objects. It serves as the primary entry point for creating type instances in a clean, fluent API style. The class covers all primitive types (INT, BIGINT, TINYINT, SMALLINT, FLOAT, DOUBLE, BOOLEAN), string types (STRING, VARCHAR, CHAR), binary types (BYTES, BINARY, VARBINARY), decimal types (DECIMAL), temporal types (DATE, TIME, TIMESTAMP, TIMESTAMP_WITH_LOCAL_TIME_ZONE with various precisions), and complex types (ARRAY, VECTOR, MAP, ROW, MULTISET, VARIANT, BLOB).

The factory methods follow consistent naming conventions using uppercase for type names and accept only the necessary parameters for each type. For example, VARCHAR(int length) creates a variable-length character type, DECIMAL(int precision, int scale) creates a decimal type, and ARRAY(DataType element) creates an array type. Some methods provide convenient shortcuts like STRING() which returns a VARCHAR with maximum length, or TIMESTAMP_MILLIS() which creates a timestamp with millisecond precision.

Beyond type creation, DataTypes includes utility methods getPrecision() and getLength() that use internal visitor implementations to extract these properties from types that support them, returning OptionalInt to handle types that don't have these attributes. Available since version 0.4.0 and marked @Public, the class follows the utility pattern with no instance methods - all functionality is accessible through static methods.

Usage

Use DataTypes whenever you need to create data types programmatically, particularly when building schemas, defining table structures, or constructing complex nested types. It provides the standard, recommended way to instantiate types in Paimon applications.

Code Reference

Source Location

Signature

@Public
public class DataTypes {

    // Integer types
    public static IntType INT()
    public static TinyIntType TINYINT()
    public static SmallIntType SMALLINT()
    public static BigIntType BIGINT()

    // Floating-point types
    public static DoubleType DOUBLE()
    public static FloatType FLOAT()

    // String types
    public static VarCharType STRING()
    public static CharType CHAR(int length)
    public static VarCharType VARCHAR(int length)

    // Binary types
    public static VarBinaryType BYTES()
    public static BinaryType BINARY(int length)
    public static VarBinaryType VARBINARY(int length)

    // Other primitive types
    public static BooleanType BOOLEAN()
    public static DecimalType DECIMAL(int precision, int scale)

    // Temporal types
    public static DateType DATE()
    public static TimeType TIME()
    public static TimeType TIME(int precision)
    public static TimestampType TIMESTAMP()
    public static TimestampType TIMESTAMP_MILLIS()
    public static TimestampType TIMESTAMP(int precision)
    public static LocalZonedTimestampType TIMESTAMP_WITH_LOCAL_TIME_ZONE()
    public static LocalZonedTimestampType TIMESTAMP_WITH_LOCAL_TIME_ZONE(int precision)
    public static LocalZonedTimestampType TIMESTAMP_LTZ_MILLIS()

    // Complex types
    public static ArrayType ARRAY(DataType element)
    public static VectorType VECTOR(int length, DataType element)
    public static MapType MAP(DataType keyType, DataType valueType)
    public static MultisetType MULTISET(DataType elementType)
    public static RowType ROW(DataField... fields)
    public static RowType ROW(DataType... fieldTypes)

    // Field creation
    public static DataField FIELD(int id, String name, DataType type)
    public static DataField FIELD(int id, String name, DataType type, String description)

    // Special types
    public static VariantType VARIANT()
    public static BlobType BLOB()

    // Utility methods
    public static OptionalInt getPrecision(DataType dataType)
    public static OptionalInt getLength(DataType dataType)
}

Import

import org.apache.paimon.types.DataTypes;

I/O Contract

Inputs

Name Type Required Description
Type parameters Various Context-dependent Length, precision, scale, element types depending on the specific type

Outputs

Name Type Description
DataType instance DataType subclass The created data type object ready for use
Property value OptionalInt Extracted precision or length (for utility methods)

Usage Examples

// Basic primitive types
DataType intType = DataTypes.INT();
DataType longType = DataTypes.BIGINT();
DataType boolType = DataTypes.BOOLEAN();
DataType doubleType = DataTypes.DOUBLE();

// String types
DataType string = DataTypes.STRING(); // VARCHAR(MAX)
DataType varchar = DataTypes.VARCHAR(255);
DataType fixedChar = DataTypes.CHAR(10);

// Binary types
DataType bytes = DataTypes.BYTES(); // VARBINARY(MAX)
DataType binary = DataTypes.BINARY(16);

// Decimal types
DataType decimal = DataTypes.DECIMAL(10, 2);

// Temporal types
DataType date = DataTypes.DATE();
DataType time = DataTypes.TIME(3); // microsecond precision
DataType timestamp = DataTypes.TIMESTAMP(6);
DataType timestampMillis = DataTypes.TIMESTAMP_MILLIS();
DataType timestampLtz = DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE(3);

// Array type
DataType intArray = DataTypes.ARRAY(DataTypes.INT());
DataType nestedArray = DataTypes.ARRAY(
    DataTypes.ARRAY(DataTypes.STRING())
);

// Vector type
DataType vector = DataTypes.VECTOR(128, DataTypes.FLOAT());

// Map type
DataType map = DataTypes.MAP(
    DataTypes.STRING(),
    DataTypes.INT()
);

// Row type with fields
DataType row = DataTypes.ROW(
    DataTypes.FIELD(0, "id", DataTypes.BIGINT(), "User ID"),
    DataTypes.FIELD(1, "name", DataTypes.STRING(), "User name"),
    DataTypes.FIELD(2, "age", DataTypes.INT())
);

// Row type with just types (auto-generated field names)
DataType simpleRow = DataTypes.ROW(
    DataTypes.INT(),
    DataTypes.STRING(),
    DataTypes.DOUBLE()
);

// Complex nested structure
DataType complexType = DataTypes.ROW(
    DataTypes.FIELD(0, "id", DataTypes.BIGINT()),
    DataTypes.FIELD(1, "tags", DataTypes.ARRAY(DataTypes.STRING())),
    DataTypes.FIELD(2, "metadata", DataTypes.MAP(
        DataTypes.STRING(),
        DataTypes.STRING()
    )),
    DataTypes.FIELD(3, "embedding", DataTypes.VECTOR(768, DataTypes.FLOAT()))
);

// Using utility methods
DataType decimalType = DataTypes.DECIMAL(10, 2);
OptionalInt precision = DataTypes.getPrecision(decimalType); // OptionalInt[10]

DataType varcharType = DataTypes.VARCHAR(100);
OptionalInt length = DataTypes.getLength(varcharType); // OptionalInt[100]

Related Pages

Page Connections

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