Implementation:Apache Paimon DataTypeRoot
| Knowledge Sources | |
|---|---|
| Domains | Type System, Type Classification |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
DataTypeRoot is an enumeration containing static information about logical data types, representing the essential description of a DataType without additional parameters.
Description
DataTypeRoot is a public enum that defines the fundamental type categories in Apache Paimon's type system. Each enum constant represents a "root" type - the essential characteristics of a data type stripped of its parameters. For example, DECIMAL is a root that applies to both DECIMAL(10,2) and DECIMAL(38,10), and VARCHAR is a root that covers all variable-length character types regardless of their maximum length specification.
The enum includes 23 distinct type roots covering predefined types (CHAR, VARCHAR, BOOLEAN, BINARY, VARBINARY, DECIMAL, integer types, floating-point types, temporal types, VARIANT, BLOB) and constructed types (ARRAY, VECTOR, MULTISET, MAP, ROW). Each root is associated with one or more DataTypeFamily values that categorize it into broader groups. For instance, INTEGER belongs to PREDEFINED, NUMERIC, INTEGER_NUMERIC, and EXACT_NUMERIC families.
DataTypeRoot enables efficient type comparison during query processing and type checking without examining type parameters. It follows best practices by ordering items consistently and avoiding default fallbacks in switch statements to ensure new type roots are explicitly handled. The getFamilies() method returns an unmodifiable set of all families to which a type root belongs, enabling family-based type checking.
Usage
Use DataTypeRoot for efficient type identity checks, when implementing type-specific logic in visitors or processors, and when categorizing types without needing to inspect their parameters. It is the primary mechanism for type switching in Paimon's codebase.
Code Reference
Source Location
Signature
@Public
public enum DataTypeRoot {
CHAR(DataTypeFamily.PREDEFINED, DataTypeFamily.CHARACTER_STRING),
VARCHAR(DataTypeFamily.PREDEFINED, DataTypeFamily.CHARACTER_STRING),
BOOLEAN(DataTypeFamily.PREDEFINED),
BINARY(DataTypeFamily.PREDEFINED, DataTypeFamily.BINARY_STRING),
VARBINARY(DataTypeFamily.PREDEFINED, DataTypeFamily.BINARY_STRING),
DECIMAL(DataTypeFamily.PREDEFINED, DataTypeFamily.NUMERIC, DataTypeFamily.EXACT_NUMERIC),
TINYINT(DataTypeFamily.PREDEFINED, DataTypeFamily.NUMERIC,
DataTypeFamily.INTEGER_NUMERIC, DataTypeFamily.EXACT_NUMERIC),
SMALLINT(DataTypeFamily.PREDEFINED, DataTypeFamily.NUMERIC,
DataTypeFamily.INTEGER_NUMERIC, DataTypeFamily.EXACT_NUMERIC),
INTEGER(DataTypeFamily.PREDEFINED, DataTypeFamily.NUMERIC,
DataTypeFamily.INTEGER_NUMERIC, DataTypeFamily.EXACT_NUMERIC),
BIGINT(DataTypeFamily.PREDEFINED, DataTypeFamily.NUMERIC,
DataTypeFamily.INTEGER_NUMERIC, DataTypeFamily.EXACT_NUMERIC),
FLOAT(DataTypeFamily.PREDEFINED, DataTypeFamily.NUMERIC,
DataTypeFamily.APPROXIMATE_NUMERIC),
DOUBLE(DataTypeFamily.PREDEFINED, DataTypeFamily.NUMERIC,
DataTypeFamily.APPROXIMATE_NUMERIC),
DATE(DataTypeFamily.PREDEFINED, DataTypeFamily.DATETIME),
TIME_WITHOUT_TIME_ZONE(DataTypeFamily.PREDEFINED, DataTypeFamily.DATETIME,
DataTypeFamily.TIME),
TIMESTAMP_WITHOUT_TIME_ZONE(DataTypeFamily.PREDEFINED, DataTypeFamily.DATETIME,
DataTypeFamily.TIMESTAMP),
TIMESTAMP_WITH_LOCAL_TIME_ZONE(DataTypeFamily.PREDEFINED, DataTypeFamily.DATETIME,
DataTypeFamily.TIMESTAMP, DataTypeFamily.EXTENSION),
VARIANT(DataTypeFamily.PREDEFINED),
BLOB(DataTypeFamily.PREDEFINED),
ARRAY(DataTypeFamily.CONSTRUCTED, DataTypeFamily.COLLECTION),
VECTOR(DataTypeFamily.CONSTRUCTED, DataTypeFamily.COLLECTION),
MULTISET(DataTypeFamily.CONSTRUCTED, DataTypeFamily.COLLECTION),
MAP(DataTypeFamily.CONSTRUCTED, DataTypeFamily.EXTENSION),
ROW(DataTypeFamily.CONSTRUCTED);
public Set<DataTypeFamily> getFamilies()
}
Import
import org.apache.paimon.types.DataTypeRoot;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| Type root constant | DataTypeRoot | Yes | One of the predefined type root enum values |
Outputs
| Name | Type | Description |
|---|---|---|
| Type root | DataTypeRoot | The enum constant representing the type category |
| Families | Set<DataTypeFamily> | The set of families this type root belongs to |
Usage Examples
// Get type root from a data type
DataType intType = DataTypes.INT();
DataTypeRoot root = intType.getTypeRoot(); // DataTypeRoot.INTEGER
// Direct type root comparison
if (root == DataTypeRoot.INTEGER) {
System.out.println("This is an integer type");
}
// Check type root using DataType methods
if (intType.is(DataTypeRoot.INTEGER)) {
// Handle integer specifically
}
// Check multiple type roots
if (intType.isAnyOf(DataTypeRoot.INTEGER, DataTypeRoot.BIGINT)) {
// Handle any integer type
}
// Get families for a type root
Set<DataTypeFamily> families = DataTypeRoot.INTEGER.getFamilies();
// Returns: [PREDEFINED, NUMERIC, INTEGER_NUMERIC, EXACT_NUMERIC]
// Switch on type root
DataType type = DataTypes.VARCHAR(100);
switch (type.getTypeRoot()) {
case CHAR:
case VARCHAR:
System.out.println("Character string type");
break;
case INTEGER:
case BIGINT:
case SMALLINT:
case TINYINT:
System.out.println("Integer type");
break;
case DECIMAL:
System.out.println("Exact decimal type");
break;
case FLOAT:
case DOUBLE:
System.out.println("Approximate numeric type");
break;
case ARRAY:
case VECTOR:
System.out.println("Collection type");
break;
case ROW:
System.out.println("Structured type");
break;
default:
System.out.println("Other type");
}
// Check if type belongs to specific families via root
DataTypeRoot decimalRoot = DataTypeRoot.DECIMAL;
boolean isNumeric = decimalRoot.getFamilies()
.contains(DataTypeFamily.NUMERIC); // true
boolean isInteger = decimalRoot.getFamilies()
.contains(DataTypeFamily.INTEGER_NUMERIC); // false