# TD Native Data Types

Treasure AI supports many different sources and targets of data. To keep schemas consistent across the platform, Treasure AI uses a specific set of native data types for table schemas.

Treasure Data (TD) processes queries using different query engines, including Trino and Hive. Each engine has its own data type system, and TD native data types map to types available in the query engine.

It is important to understand [how TD native data types relate to query engines and storage](#how-td-native-data-types-relate-to-query-engines-and-storage). Otherwise, you might see query results or data types that are different than expected.

If you are going to store an unsupported data type, consider converting the data type to a TD natively supported data type by using `cast()`.

## Supported TD native data types

The following TD native data types are available for table schemas.

| Data type | Description |
|  --- | --- |
| `string` | Text values. |
| `int` | Integer values. |
| `long` | Long integer values. |
| `float` | Floating-point values. |
| `double` | Double-precision floating-point values. |
| `array of strings` | An array whose elements are strings. |
| `array of ints` | An array whose elements are integers. |
| `array of longs` | An array whose elements are long integers. |
| `array of floats` | An array whose elements are floating-point values. |
| `array of doubles` | An array whose elements are double-precision floating-point values. |
| `array of arrays of strings` | A nested array whose inner array elements are strings. |
| `array of arrays of ints` | A nested array whose inner array elements are integers. |
| `array of arrays of longs` | A nested array whose inner array elements are long integers. |
| `array of arrays of floats` | A nested array whose inner array elements are floating-point values. |
| `array of arrays of doubles` | A nested array whose inner array elements are double-precision floating-point values. |


In the Schema edit UI, array types are selected as `array of strings`, `array of ints`, `array of longs`, `array of floats`, `array of doubles`, or nested `array of arrays of ...` types.

## How TD native data types relate to query engines and storage

TD native data types are the schema types that users select for tables. Query engines and storage use their own type systems, so the same column can be represented differently depending on where you inspect it.

### Query engine type mapping

| **Treasure Data**  | **Trino**  | **Hive**  |
|  --- | --- | --- |
| `int` | `bigint` | `smallint` |
| `int` | `bigint` | `int` |
| `long` | `bigint` | `bigint` |
| `double` | `double` | `decimal` |
| `float` | `double` | `float` |
| `double` | `double` | `double` |
| Convert to `string` or `int` | `boolean` | `boolean` |
| `string` | `varchar` | `string` or `varchar` |
| `string` or convert to `long` | `date` | `string` |
| `string` or convert to `long` | `timestamp` | `timestamp` |


Array types map to the corresponding array type in each query engine.

| **TD native data type**  | **Query engine representation**  |
|  --- | --- |
| `array of strings` | Array of string values. |
| `array of ints`, `array of longs` | Array of integer or bigint values. |
| `array of floats`, `array of doubles` | Array of floating-point values. |
| `array of arrays of ...` | Nested array values. |


Query engines might display type syntax differently. Refer to the OSS documents for query engines' data types.

* [Trino](https://trino.io/docs/423/language/types.html)
* [Hive](https://hive.apache.org/docs/latest/language/languagemanual-types/)


### Storage format

TD stores table data in MessagePack mpc1 format. MessagePack mpc1 is an internal storage format and is different from the TD native data types that users select in the Schema edit UI.

### Query result type behavior

Some query result paths can expose mapped types instead of the exact TD native data type selected in the table schema. For example, in the Hive query result for ResultWorker, a `float` data type becomes a `double` data type.

| **TD primitive data types**  | **Hive query result for ResultWorker**  | **Trino result msgpack ValueType**  |
|  --- | --- | --- |
| `int` | `int` > `int` | Integer |
| `long` | `bigint` > `long` | integer |
| `float` | `float` > `double` | float |
| `double` | `double` > `double` | float |
| `string` | `string` > `string` | string |