Hive-compatible data type edition
The Hive-compatible data type edition is one of the three data type editions in MaxCompute and supports only Hive-compatible data types. This topic describes its definition, supported data types, and differences from other data type editions.
Definition
When a project uses the Hive-compatible data type edition, its data type properties are defined as follows.
setproject odps.sql.type.system.odps2=true; -- Enable MaxCompute V2.0 data types.
setproject odps.sql.decimal.odps2=true; -- Enable the DECIMAL data type in MaxCompute V2.0.
setproject odps.sql.hive.compatible=true; -- Enable Hive-compatible mode.Applicable scenarios
This edition is designed for MaxCompute projects migrated from Hadoop whose dependent components support the MaxCompute V2.0 data type edition.
Basic data types
The basic data types supported by the Hive-compatible data type edition are generally the same as those in the V2.0 data type edition. Only the DECIMAL data type differs between the two editions.
Data type | Constant examples | Description |
TINYINT | 1Y, -127Y | 8-bit signed integer. Value range: -128 to 127. |
SMALLINT | 32767S, -100S | 16-bit signed integer. Value range: -32,768 to 32,767. |
INT | 1000, -15645787 | 32-bit signed integer. Value range: -2 31 to 2 31-1. |
BIGINT | 100000000000L, -1L | 64-bit signed integer. Value range: -2 63+1 to 2 63-1. |
BINARY | unhex('FA34E10293CB42848573A4E39937F479') | Binary data. Max length: 8 MB. |
FLOAT | cast(3.14159261E+7 as float) | 32-bit binary floating-point. |
DOUBLE | 3.14159261E+7 | 64-bit binary floating-point. |
DECIMAL(precision,scale) | 3.5BD, 99999999999.9999999BD | Base-10 exact numeric type. The default is
|
VARCHAR(n) | None | Variable-length character type. n specifies the length. Value range: 1 to 65,535. |
CHAR(n) | None | Fixed-length character type. n specifies the length, up to 255. Values shorter than n are padded with spaces, which are ignored in comparisons. |
STRING | "abc", 'bcd', "alibaba", 'inc' | String type. Max length: 8 MB. |
DATE | DATE'2017-11-11' | Date type. Format: Value range: 0000-01-01 to 9999-12-31. |
DATETIME | DATETIME'2017-11-11 00:00:00' | Date and time type. Value range: 0000-01-01 00:00:00.000 to 9999-12-31 23:59:59.999, with millisecond precision. |
TIMESTAMP | TIMESTAMP'2017-11-11 00:00:00.123456789' | Time zone-independent timestamp type. Value range: 0000-01-01 00:00:00.000000000 to 9999-12-31 23:59:59.999999999, with nanosecond precision. Note For time zone-related functions such as |
BOOLEAN | True, False | Boolean type. Value range: True or False. |
The data types have the following characteristics:
All the preceding data types support NULL values.
The INT keyword in SQL represents a 32-bit integer.
-- Convert a to a 32-bit integer. cast(a as INT)Unsuffixed integer literals default to INT. For example, the integer literal 1 in
SELECT 1 + a;is treated as INT. If the value exceeds the INT range but fits in BIGINT, it is treated as BIGINT. If it exceeds the BIGINT range, it is treated as DOUBLE.Implicit conversions
Some implicit type conversions are disabled. For example, STRING->BIGINT, STRING->DATETIME, DOUBLE->BIGINT, DECIMAL->DOUBLE, and DECIMAL->BIGINT can cause precision loss or errors. Use the CAST function to explicitly perform conversions that are disabled implicitly.
VARCHAR constants can be implicitly converted to STRING constants.
Tables, functions, and UDFs
Built-in functions whose parameters use V2.0 data types can be used normally.
Data types in UDFs are parsed and overloaded according to the Hive-compatible data types.
The data type of a partition key column can be STRING, VARCHAR, CHAR, TINYINT, SMALLINT, INT, or BIGINT.
In Hive-compatible mode, some functions do not support partition pruning. For more information, see Built-in function comparison with Hive, MySQL, and Oracle.
String constants can be concatenated directly. For example, abc and xyz combine to abcxyz.
When inserting a constant into a DECIMAL column, use the format specified in the constant definition, such as
3.5BDin the following example.insert into test_tb(a) values (3.5BD)DATETIME values displayed in query results do not include milliseconds. Tunnel commands use
-dfpto specify the time format, which can include milliseconds. For example,tunnel upload -dfp 'yyyy-MM-dd HH:mm:ss.SSS'. For more information about Tunnel commands, see Tunnel commands.
Complex data types
Data type | Definition examples | Constructor examples |
ARRAY |
|
|
MAP |
|
|
STRUCT |
|
|
Differences from other editions
INSERT type conversion rules differ.
In Hive-compatible mode, if a source data type can be explicitly converted to the target column type, MaxCompute automatically inserts a conversion function and runs it.
In V1.0 and V2.0 modes, the source type must be implicitly convertible to the target column type; otherwise, an error is returned.
-- Succeeds in Hive-compatible mode but fails in other modes. create table t (a bigint); insert into table select 1.5;
Function behavior differences
+,-,*,/, and POW functionHive-compatible data type edition: On data overflow, the value wraps around (returns to the initial value after exceeding the range).
V1.0 and V2.0 data type editions: An error is returned on data overflow; in other modes, NULL is returned.
>,>=,=,<,<=Hive-compatible data type edition: DOUBLE values are compared directly.
V1.0 and V2.0 data type editions: DOUBLE values are considered equal if the first 15 digits to the right of the decimal point are the same. Digits after the 15th decimal place are not compared.
Bitwise operators
&,|,^Hive-compatible data type edition: The return type is the same as the input type.
V1.0 and V2.0 data type editions: The return type is BIGINT.
LENGTH, LENGTHB, FIND_IN_SET, INSTR, SIZE, HASH, and SIGN functions
Hive-compatible data type edition: The return type is INT.
V1.0 and V2.0 data type editions: The return type is BIGINT.
FLOOR, CEIL
Hive-compatible data type edition: If the input parameter is of the DECIMAL type, a DECIMAL value is returned.
V1.0 and V2.0 data type editions: If the input parameter is of the DECIMAL type, a BIGINT value is returned.
FROM_UNIXTIME
Hive-compatible data type edition: A STRING value is returned.
V1.0 and V2.0 data type editions: A DATETIME value is returned.
CONCAT_WS
Hive-compatible data type edition: If an input string to be concatenated is NULL, it is ignored.
V1.0 and V2.0 data type editions: If any input string to be concatenated is NULL, NULL is returned.
FIND_IN_SET
Hive-compatible data type edition: An empty string matches the tail of the search string.
-- In Hive-compatible mode: find_in_set("", "") -- Returns 1. find_in_set("", "a,") -- Returns 2.V1.0 and V2.0 data type editions: An empty string is treated as unmatched and 0 is returned.
REGEXP_(EXTRACT/REPLACE)
Hive-compatible data type edition: REGEXP patterns follow Java regular expression specifications.
V1.0 and V2.0 data type editions: REGEXP patterns follow MaxCompute specifications.
SUBSTR
string substr(string <str>, bigint <start_position>[, bigint <length>])start_position: Required. BIGINT type. The default start position is 1.
Hive-compatible data type version: If start_position=0, it behaves the same as position 1.
1.0 and 2.0 data type versions: If start_position=0, it returns NULL.