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 DataTypeChecks

From Leeroopedia


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

Overview

DataTypeChecks provides utility methods for checking and extracting properties from DataType instances, avoiding repetitive type casting and boilerplate code.

Description

DataTypeChecks is a final utility class that offers a comprehensive set of static methods for inspecting and validating data types in Apache Paimon. It leverages the visitor pattern to extract type-specific attributes such as length (for string and binary types), precision (for decimal and timestamp types), scale (for numeric types), and field information (for composite types). The class eliminates the need for explicit type casting and instanceof checks by providing type-safe accessor methods.

The utility includes methods like getLength(), getPrecision(), getScale() for extracting numeric properties with appropriate defaults, and getFieldCount(), getFieldNames(), getFieldTypes() for working with structured types. It also provides isCompositeType() to identify row types, hasWellDefinedString() to check if a type's internal representation has a meaningful string format, and getNestedTypes() to extract child types from collection and map types.

Internally, DataTypeChecks uses specialized extractor classes that extend DataTypeDefaultVisitor to traverse the type hierarchy and retrieve the requested properties. These extractors throw descriptive exceptions when used on incompatible types, ensuring type safety. The class design follows the utility class pattern with a private constructor to prevent instantiation.

Usage

Use DataTypeChecks when you need to inspect properties of DataType objects without knowing their concrete type, when validating type compatibility, or when writing generic type processing code. It is particularly useful in serialization, query optimization, and schema validation scenarios where type properties must be examined dynamically.

Code Reference

Source Location

Signature

public final class DataTypeChecks {

    public static boolean isCompositeType(DataType dataType)

    public static int getLength(DataType dataType)

    public static boolean hasLength(DataType dataType, int length)

    public static Integer getPrecision(@Nullable DataType dataType)

    public static boolean hasPrecision(DataType dataType, int precision)

    public static int getScale(DataType dataType)

    public static boolean hasScale(DataType dataType, int scale)

    public static int getFieldCount(DataType dataType)

    public static List<String> getFieldNames(DataType dataType)

    public static List<DataType> getFieldTypes(DataType dataType)

    public static List<DataType> getNestedTypes(DataType dataType)

    public static boolean hasWellDefinedString(DataType dataType)
}

Import

import org.apache.paimon.types.DataTypeChecks;

I/O Contract

Inputs

Name Type Required Description
dataType DataType Yes The data type to inspect or validate
length/precision/scale int Context-dependent Expected value for validation methods

Outputs

Name Type Description
Property value int/Integer/List Extracted type property (length, precision, scale, etc.)
Validation result boolean Whether the type has the expected property value
Field information List<String>/List<DataType> Field names or types for composite types

Usage Examples

// Check if type is composite
DataType rowType = DataTypes.ROW(
    DataTypes.FIELD(0, "id", DataTypes.INT()),
    DataTypes.FIELD(1, "name", DataTypes.STRING())
);
boolean isComposite = DataTypeChecks.isCompositeType(rowType); // true

// Extract length from string types
DataType varchar = DataTypes.VARCHAR(100);
int length = DataTypeChecks.getLength(varchar); // 100
boolean hasLength = DataTypeChecks.hasLength(varchar, 100); // true

// Extract precision and scale from decimal
DataType decimal = DataTypes.DECIMAL(10, 2);
Integer precision = DataTypeChecks.getPrecision(decimal); // 10
int scale = DataTypeChecks.getScale(decimal); // 2
boolean hasPrecision = DataTypeChecks.hasPrecision(decimal, 10); // true

// Work with composite types
int fieldCount = DataTypeChecks.getFieldCount(rowType); // 2
List<String> fieldNames = DataTypeChecks.getFieldNames(rowType);
// Returns ["id", "name"]
List<DataType> fieldTypes = DataTypeChecks.getFieldTypes(rowType);
// Returns [INT, STRING]

// Extract nested types from collections
DataType arrayType = DataTypes.ARRAY(DataTypes.INT());
List<DataType> nested = DataTypeChecks.getNestedTypes(arrayType);
// Returns [INT]

DataType mapType = DataTypes.MAP(DataTypes.STRING(), DataTypes.INT());
List<DataType> mapNested = DataTypeChecks.getNestedTypes(mapType);
// Returns [STRING, INT]

// Check for well-defined string representation
boolean wellDefined = DataTypeChecks.hasWellDefinedString(DataTypes.INT()); // true
boolean notWellDefined = DataTypeChecks.hasWellDefinedString(arrayType); // false

Related Pages

Page Connections

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