JSON external table

Updated at:

This topic describes how to create, read from, and write to a JSON external table in OSS.

Scope

Permission description

  • When you access OSS external tables, data is accessed through the role specified in the odps.properties.rolearn parameter, regardless of whether you use an Alibaba Cloud account, a RAM user, or a RAM role. Therefore, you must create a RAM role and grant it permissions to access the target OSS bucket, then configure the ARN of the role in the odps.properties.rolearn parameter. For more information, see Parameters.

  • You can authorize same-account or cross-account access based on your business requirements. We recommend that you use a custom authorization policy for more fine-grained access control. For more information, see Authorization for external data sources.

Create an external table

Syntax

If a JSON file has fewer columns than the external table definition, MaxCompute populates the missing columns with NULL. If the file has more columns, MaxCompute discards the extra columns.

Streamlined syntax

CREATE EXTERNAL TABLE <mc_oss_extable_name>
(
  <col_name> <data_type>,
  ...
)
[COMMENT <table_comment>]
[PARTITIONED BY (<col_name> <data_type>, ...)]
ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
STORED AS textfile
LOCATION '<oss_location>';

Full syntax

CREATE EXTERNAL TABLE <mc_oss_extable_name>
(
  <col_name> <data_type>,
  ...
)
[COMMENT <table_comment>]
[PARTITIONED BY (<col_name> <data_type>, ...)]
ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
  [WITH serdeproperties (
    ['<property_name>'='<property_value>',...])
  ]
STORED AS textfile
LOCATION '<oss_location>'
[tblproperties ('<tbproperty_name>'='<tbproperty_value>',...)];

Common parameters

For more information, see Common syntax parameters.

Exclusive parameters

Tblproperties parameters

Parameter

Use case

Description

Value

Default

mcfed.mapreduce.output.fileoutputformat.compress

To write TEXTFILE data to OSS in a compressed format.

TEXTFILE compression property. If set to True, MaxCompute compresses TEXTFILE data when writing to OSS.

  • True

  • False

False

mcfed.mapreduce.output.fileoutputformat.compress.codec

To write TEXTFILE data to OSS in a compressed format.

TEXTFILE compression property. Sets the compression codec for TEXTFILE data files. By default, files are compressed by using the .deflate codec.

Note: Only the compression method in property_value is supported.

  • com.hadoop.compression.lzo.LzoCodec

  • com.hadoop.compression.lzo.LzopCodec

  • org.apache.hadoop.io.compress.SnappyCodec

  • org.apache.hadoop.io.compress.BZip2Codec

  • org.apache.hadoop.io.compress.Lz4Codec

  • org.apache.hadoop.io.compress.DeflateCodec

  • org.apache.hadoop.io.compress.GzipCodec

  • org.apache.hadoop.io.compress.odps.ZstandardCodec

org.apache.hadoop.io.compress.DeflateCodec

odps.external.data.output.prefix

(backward compatible with odps.external.data.prefix)

To add a custom prefix to the names of output files.

  • The prefix can contain only digits (0-9), letters (a-z, A-Z), and underscores (_).

  • The prefix must be 1 to 10 characters in length.

A valid character combination, such as mc_.

None

odps.external.data.enable.extension

To add a file extension to the names of output files.

If set to True, a file extension is added to the names of output files. Otherwise, no file extension is added.

  • True

  • False

False

odps.external.data.output.suffix

To add a custom suffix to the names of output files.

The suffix can contain only digits (0-9), letters (a-z, A-Z), and underscores (_).

A valid string, such as '_hangzhou'.

None

odps.external.data.output.explicit.extension

To add a custom file extension to the names of output files.

  • The extension can contain only digits (0-9), letters (a-z, A-Z), and underscores (_).

  • The file extension must be 1 to 10 characters in length.

  • Overrides the odps.external.data.enable.extension parameter.

A valid character combination, such as jsonl.

None

odps.ext.column.mapping

Add this property when field names in OSS data files contain special characters. 

his property defines custom column name mappings. For example, if the OSS file fields are id BIGINT, $_test DOUBLE, and =name STRING, set the parameter value to t_test:$_test,t_name:=_name when creating the external table. You only need to specify mappings for fields that contain special characters.

No fixed value

None

odps.ext.column.mapping.delimiters

(Use only when characters in column names conflict with the default delimiters in column name mappings. Generally not recommended.)

Add this property when column names contain the special characters : or ,

This property customizes the intra-group and inter-group delimiters for key-value pairs. The value must contain exactly two characters: the first character serves as the key-value delimiter, and the second character serves as the delimiter between different key-value pairs.

No fixed value. Example: =|.

Default value: ':,'

  • By default, ':' is used as the delimiter between keys and values.

  • The comma ',' is used as the delimiter between different key-value pairs. 

  • Leading and trailing spaces in keys and values are trimmed during parsing.

odps.text.option.bad.row.skipping

To skip dirty data in OSS data files.

Specifies whether to skip dirty data when MaxCompute reads from OSS files.

  • rigid: Enforces the row skipping logic. This setting cannot be overridden by session-level or project-level configurations.

  • flexible: Enables flexible skipping at the data layer. This setting can be overridden by session-level or project-level configurations.

When creating an external table for JSON with nested objects (structs), do not define the object field's data type as STRING or JSON. Otherwise, MaxCompute cannot parse its subfields.

The following two approaches are recommended. For detailed steps, see the examples in this topic:

  • Define the field as STRING and use functions such as get_json_object in your queries to extract the content of internal subfields as needed.

  • Use the STRUCT type to structurally define the field, mapping each subfield of the JSON object to a separate sub-column. This allows you to directly access the internal data by using the field_name.subfield_name syntax.

Whitelist and blacklist

MaxCompute OSS external tables support whitelist and blacklist filtering. By setting whitelist and blacklist parameters in tblproperties, you can filter which files to read from a directory. For details, see Whitelist and blacklist.

Write data

For information about the syntax for writing data from MaxCompute to OSS, see Write data to OSS.

Query data

BadRowSkipping

The BadRowSkipping feature lets you skip rows that contain dirty data or cause parsing errors. It does not change how the underlying data format is interpreted.

Parameters

  • Parameter descriptions

    Parameter level

    Parameter

    Description

    Table-level parameter

    odps.text.option.bad.row.skipping

    • rigid: Forces skipping. This setting cannot be overridden by session-level or project-level configurations.

    • flexible: Enables flexible skipping. This setting can be overridden by session-level or project-level configurations.

    tblproperties (
      'odps.text.option.bad.row.skipping' = 'flexible'   -- Flexible mode, can be disabled at the session level.
    )

    Session-level and project-level parameters

    odps.sql.unstructured.text.bad.row.skipping

    Can override a flexible table-level parameter, but not a rigid one.

    • on: Enables the feature. If the feature is not configured for the table, it is enabled.

    • off: Disables the feature. If the table is configured as flexible, the feature is disabled. Otherwise, the table-level configuration is used.

    • <null> or invalid input: The table-level configuration is used.

    -- Enable at the session level.
    SET odps.sql.unstructured.text.bad.row.skipping=on;
    
    -- Enable at the project level.
    SETPROJECT odps.sql.unstructured.text.bad.row.skipping=on;

    odps.sql.unstructured.text.bad.row.skipping.debug.num

    Specifies the number of error results to print to stdout in Logview.

    • The maximum value is 1000.

    • If the value is less than or equal to 0, printing is disabled.

    • If the value is invalid, printing is disabled.

    -- Print problematic rows at the session level. The maximum is 1000. If the value is less than or equal to 0, printing is disabled.
    SET odps.sql.unstructured.text.bad.row.skipping.debug.num=10;
    
    -- Print problematic rows at the project level. The maximum is 1000. If the value is less than or equal to 0, printing is disabled.
    SETPROJECT odps.sql.unstructured.text.bad.row.skipping.debug.num=10;
  • Interaction between session-level parameters and table properties

    tbl property

    session flag

    result

    rigid

    on

    On, Forced on

    off

    <null>, an invalid value, or the parameter is not configured

    flexible

    on

    On

    off

    Off, Disabled by session

    <null>, an invalid value, or the parameter is not configured

    On

    Not configured

    on

    On, Enabled by session

    off

    Off

    <null>, an invalid value, or the parameter is not configured

Examples

Note

Table-level parameters and session-level parameters are configured differently. See the following examples.

  1. Prepare data

    Upload the test data json_bad_row_skipping.json, which contains some dirty data, to the oss-mc-test/badrow/ directory in OSS. Sample data:

    {"a":1,"b":2}
    "a":3,"b":4}
    {"a:5,"b":6}
    {"a":7,"b":}
    {"a":9"b":10}
    {"a":11,"b":12
    {"a":13,"b"14}
    {"a":15,"b":16}
  2. If no table-level property is configured, skipping can be controlled by the session-level parameter.

    -- 1. No table-level property is set. Errors are handled based on the session-level parameter.
    CREATE EXTERNAL TABLE test_json_bad_data_skipping_flag
    (
      a INT,
      b INT
    )
    row format serde 'org.apache.hive.hcatalog.data.JsonSerDe'
    stored AS textfile
    location '<oss://databucketpath>';
    
    -- 2. Disable skipping at the session level. Reading the table fails with: Start token not found where expected
    SET odps.sql.unstructured.text.bad.row.skipping=off;
    SELECT * FROM test_json_bad_data_skipping_flag;
    
    -- 3. Enable skipping at the session level. Dirty rows are skipped and the table can be read successfully.
    SET odps.sql.unstructured.text.bad.row.skipping=on;
    SELECT * FROM test_json_bad_data_skipping_flag;
    
    -- The following result is returned.
    +------+------+
    | a    | b    |
    +------+------+
    | 1    | 2    |
    | 15   | 16   |
    +------+------+
    
    -- 4. Print problematic rows at the session level.
    SET odps.sql.unstructured.text.bad.row.skipping.debug.num=10;
    SELECT * FROM test_json_bad_data_skipping_flag;
    
    -- View the skipped dirty rows in the instance stdout in Logview.
    The total 10 bad rows will be printed, the complete content of row #1 is : 
    ---------------
    "a":3,"b":4}
    ---------------
    The total 10 bad rows will be printed, the complete content of row #2 is : 
    ---------------
    {"a:5,"b":6}
    ---------------
  3. Flexible skipping is enabled at the table level and can be disabled by the session-level parameter.

    -- 1. The table-level property skips error rows, but the session-level parameter can disable this behavior.
    CREATE EXTERNAL TABLE test_json_bad_data_skipping_flexible
    (
      a INT,
      b INT
    )
    row format serde 'org.apache.hive.hcatalog.data.JsonSerDe'
    stored AS textfile
    location '<oss://databucketpath>'
    tblproperties (
      'odps.text.option.bad.row.skipping' = 'flexible'   -- Flexible mode, can be disabled at the session level.
    );
    
    -- Flexible skipping is enabled at the table level. The table can be read successfully without setting the session-level parameter.
    
    -- 2. Disable skipping at the session level. With the table property set to 'flexible', dirty rows are not skipped and the query fails with: Start token not found where expected
    SET odps.sql.unstructured.text.bad.row.skipping=off;
    SELECT * FROM test_json_bad_data_skipping_flexible;
    
    -- 3. Enable skipping at the session level. With the table property set to 'flexible', dirty rows are skipped and the table can be read successfully.
    SET odps.sql.unstructured.text.bad.row.skipping=on;
    SELECT * FROM test_json_bad_data_skipping_flexible;
    
    -- The following result is returned.
    +------+------+
    | a    | b    |
    +------+------+
    | 1    | 2    |
    | 15   | 16   |
    +------+------+
  4. Forced skipping is enabled at the table level and cannot be disabled by the session-level parameter.

    -- 1. The table-level property forces error skipping. This behavior cannot be disabled at the session level.
    CREATE EXTERNAL TABLE test_json_bad_data_skipping_rigid
    (
      a INT,
      b INT
    )
    row format serde 'org.apache.hive.hcatalog.data.JsonSerDe'
    stored AS textfile
    location '<oss://databucketpath>'
    tblproperties (
      'odps.text.option.bad.row.skipping' = 'rigid'  -- Forced on.
    );
    
    -- Forced skipping is enabled at the table level. The table can be read successfully without setting the session-level parameter.
    
    -- 2. Disable skipping at the session level. The table property is set to 'rigid', so forced skipping is unaffected and the table can be read successfully.
    SET odps.sql.unstructured.text.bad.row.skipping=off;
    SELECT * FROM test_json_bad_data_skipping_rigid;
    
    -- The following result is returned.
    +------+------+
    | a    | b    |
    +------+------+
    | 1    | 2    |
    | 15   | 16   |
    +------+------+

Examples

Prerequisites

  1. You have created a MaxCompute project.

  2. You have prepared an OSS bucket and directory. For more information, see Create a bucket and Manage directories.

    Ensure your bucket is in the same region as your MaxCompute project.
  3. Grant permissions.

    1. You have permission to access OSS. You can access an OSS external table by using an Alibaba Cloud account, a RAM user, or a RAM role. For more information about how to grant permissions, see STS-mode authorization for OSS.

    2. You have the CreateTable permission in the MaxCompute project. For more information about table-related permissions, see MaxCompute permissions.

Example 1: Create, write, and query a JSON table

This example shows how to create a JSON external table using the built-in open source data parser, write data to OSS, and then query the data.

  1. Prepare data.

    Log on to the OSS console and upload the test data file json2025.txt to the external-table-test/json/dt=20250521/ directory in an OSS Bucket. For more information, see Upload files to OSS.

  2. Create a JSON external table.

    CREATE EXTERNAL TABLE mc_oss_extable_name_json
    (
      action STRING,
      time STRING
    )
    PARTITIONED BY (dt STRING)
    ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
    WITH serdeproperties (
      'odps.properties.rolearn'='acs:ram::<uid>:role/aliyunodpsdefaultrole'
    )
    STORED AS textfile
    LOCATION 'oss://oss-cn-hangzhou-internal.aliyuncs.com/external-table-test/json/';
  3. If your OSS external table is a partitioned table, you must also import the partitioned data. For more information, see OSS external table.

    -- Add partitions.
    MSCK REPAIR TABLE mc_oss_extable_name_json ADD PARTITIONS;
  4. Read data from the JSON external table.

    SELECT * FROM mc_oss_extable_name_json WHERE dt=20250526;

    The following result is returned:

    +------------+------------+------------+
    | action     | time       | dt         |
    +------------+------------+------------+
    | Close      | 1469679568 | 20250526   |
    | Close      | 1469679568 | 20250526   |
    +------------+------------+------------+
  5. Write data to the JSON external table.

    INSERT INTO mc_oss_extable_name_json PARTITION (dt='20250526') VALUES ('test','1627273823');
  6. View the written data.

    SELECT * FROM mc_oss_extable_name_json WHERE dt=20250526;

    The following result is returned:

    +------------+------------+------------+
    | action     | time       | dt         |
    +------------+------------+------------+
    | test       | 1627273823 | 20250526   |
    | Close      | 1469679568 | 20250526   |
    | Close      | 1469679568 | 20250526   |
    +------------+------------+------------+

Example 2: Read nested JSON fields

Prepare data

Create the JSON file events.json:

{"a":{"x":1, "y":2}, "id":"123"}
{"a":{"x":3, "y":4}, "id":"345"}

Log on to the OSS console and upload test data to the external-table-test/json_struct/ directory in an OSS bucket. For more information, see Upload files to OSS.

Method 1: Create a TEXTFILE external table and use the get_json_object function to read field values

  1. Create a TEXTFILE external table that contains only a single column of the string type:

    CREATE EXTERNAL TABLE extable_json_test01 (
      col STRING
    )
    ROW FORMAT DELIMITED FIELDS TERMINATED BY '\n'
    STORED AS textfile
    LOCATION 'oss://oss-cn-hangzhou-internal.aliyuncs.com/external-table-test/json_struct/';  
    
    SELECT * FROM extable_json_test01;      

    The following result is returned:

    +------------------------------------+
    |               col                  |
    +------------------------------------+
    | {"a": {"x": 1, "y": 2},"id":"123"} |
    | {"a": {"x": 3, "y": 4},"id":"345"} |
    +------------------------------------+
  2. Use the get_json_object function to read the a and id fields:

    SELECT 
        get_json_object(col, '$.a') AS a,
        get_json_object(col, '$.id') AS id
    FROM extable_json_test01;         

    The following result is returned:

    +-------------------+-----+
    |        a          | id  |
    +-------------------+-----+
    | {"x":1,"y":2}     | 123 |
    | {"x":3,"y":4}     | 345 |
    +-------------------+-----+
  3. Read the nested fields x, y, and id:

    SELECT 
        get_json_object(get_json_object(col,'$.a'),'$.x') AS x,
        get_json_object(get_json_object(col,'$.a'),'$.y') AS y,
        get_json_object(col,'$.id') AS id
    FROM extable_json_test01;          

    The following result is returned:

    +---+---+-----+
    | x | y | id  |
    +---+---+-----+
    | 1 | 2 |123  |
    | 3 | 4 |345  |
    +---+---+-----+       

Method 2: Create a JSON external table and use the STRUCT type to receive the data

  1. Create a JSON-formatted external table and use the STRUCT type to receive nested fields:

    CREATE EXTERNAL TABLE extable_json_test02
    (
      a STRUCT<x: BIGINT, y: BIGINT>,
      id STRING
    )
    ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
    STORED AS textfile
    LOCATION 'oss://oss-cn-hangzhou-internal.aliyuncs.com/external-table-test/json_struct/';          
  2. Query the data in the table directly:

    SELECT * FROM extable_json_test02;

    The following result is returned:

    +----------+-----+
    |    a     | id  |
    +----------+-----+
    | {x:1, y:2}|123 |
    | {x:3, y:4}|345 |
    +----------+-----+
  3. You can also use the get_json_object and TO_JSON functions to read the x and y fields:

    SELECT 
        get_json_object(TO_JSON(a), '$.x') AS x,
        get_json_object(TO_JSON(a), '$.y') AS y,
        id
    FROM extable_json_test02;         

    The following result is returned:

    +---+---+-----+
    | x | y | id  |
    +---+---+-----+
    | 1 | 2 |123  |
    | 3 | 4 |345  |
    +---+---+-----+       

Example 3: Customize output filenames

  1. Set the custom prefix for files written to OSS to test06_. The DDL is as follows:

    CREATE EXTERNAL TABLE  <mc_oss_extable_name>
    (
      vehicleId INT,
      recordId INT,
      patientId INT,
      calls INT,
      locationLatitute DOUBLE,
      locationLongitude DOUBLE,
      recordTime STRING,
      direction STRING
    )
    ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
    WITH serdeproperties (
      'odps.properties.rolearn'='acs:ram::<uid>:role/aliyunodpsdefaultrole'
    ) 
    STORED AS textfile
    LOCATION 'oss://oss-cn-beijing-internal.aliyuncs.com/***/'
    TBLPROPERTIES (
    -- Add a custom prefix.
        'odps.external.data.output.prefix'='test06_') 
    ;
    
    -- Write data to the external table.
    INSERT INTO  <mc_oss_extable_name> VALUES (1,32,76,1,63.32106,-92.08174,'9/14/2014 0:10','NW');

    After writing data, the files generated in OSS are named with the custom prefix test06_, for example, test06_202509101.

  2. To customize the suffix for files written to OSS as _beijing, the DDL is as follows:

    CREATE EXTERNAL TABLE <mc_oss_extable_name>
    (
      vehicleId INT,
      recordId INT,
      patientId INT,
      calls INT,
      locationLatitute DOUBLE,
      locationLongitude DOUBLE,
      recordTime STRING,
      direction STRING
    )
    ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
    WITH serdeproperties (
      'odps.properties.rolearn'='acs:ram::<uid>:role/aliyunodpsdefaultrole'
    ) 
    STORED AS textfile
    LOCATION 'oss://oss-cn-beijing-internal.aliyuncs.com/***/'
    TBLPROPERTIES (
    -- Add a custom suffix.
        'odps.external.data.output.suffix'='_beijing') 
    ;
    
    -- Write data to the external table.
    INSERT INTO <mc_oss_extable_name> VALUES (1,32,76,1,63.32106,-92.08174,'9/14/2014 0:10','NW');
  3. To automatically generate a file extension for output files, use the following DDL:

    CREATE EXTERNAL TABLE <mc_oss_extable_name>
    (
      vehicleId INT,
      recordId INT,
      patientId INT,
      calls INT,
      locationLatitute DOUBLE,
      locationLongitude DOUBLE,
      recordTime STRING,
      direction STRING
    )
    ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
    WITH serdeproperties (
      'odps.properties.rolearn'='acs:ram::<uid>:role/aliyunodpsdefaultrole'
    ) 
    STORED AS textfile
    LOCATION 'oss://oss-cn-beijing-internal.aliyuncs.com/***/'
    TBLPROPERTIES (
    -- Automatically generate a file extension.
        'odps.external.data.enable.extension'='true') 
    ;
    
    -- Write data to the external table.
    INSERT INTO <mc_oss_extable_name> VALUES (1,32,76,1,63.32106,-92.08174,'9/14/2014 0:10','NW');
  4. To customize the file extension to jsonl for files written to OSS, the DDL is as follows:

    CREATE EXTERNAL TABLE <mc_oss_extable_name>
    (
      vehicleId INT,
      recordId INT,
      patientId INT,
      calls INT,
      locationLatitute DOUBLE,
      locationLongitude DOUBLE,
      recordTime STRING,
      direction STRING
    )
    ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
    WITH serdeproperties (
      'odps.properties.rolearn'='acs:ram::<uid>:role/aliyunodpsdefaultrole'
    ) 
    STORED AS textfile
    LOCATION 'oss://oss-cn-beijing-internal.aliyuncs.com/***/'
    TBLPROPERTIES (
    -- Add a custom file extension.
       'odps.external.data.output.explicit.extension'='jsonl') 
    ;
    
    -- Write data to the external table.
    INSERT INTO <mc_oss_extable_name> VALUES (1,32,76,1,63.32106,-92.08174,'9/14/2014 0:10','NW');

    The generated file name is 20250905072538695g3mlopvxicr4_M1_1_0_0-0_TableSink1.jsonl, with the custom file extension .jsonl.

  5. For files written to OSS, set the prefix to mc_, the suffix to _beijing, and the file extension to jsonl. The DDL is as follows:

    CREATE EXTERNAL TABLE <mc_oss_extable_name>
    (
      vehicleId INT,
      recordId INT,
      patientId INT,
      calls INT,
      locationLatitute DOUBLE,
      locationLongitude DOUBLE,
      recordTime STRING,
      direction STRING
    )
    ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe'
    WITH serdeproperties (
      'odps.properties.rolearn'='acs:ram::<uid>:role/aliyunodpsdefaultrole'
    ) 
    STORED AS textfile
    LOCATION 'oss://oss-cn-beijing-internal.aliyuncs.com/***/'
    TBLPROPERTIES (
        -- Add a custom prefix.
        'odps.external.data.output.prefix'='mc_', 
        -- Add a custom suffix.
        'odps.external.data.output.suffix'='_beijing', 
        -- Add a custom file extension.
        'odps.external.data.output.explicit.extension'='jsonl') 
    ;  
    
    -- Write data to the external table.
    INSERT INTO <mc_oss_extable_name> VALUES (1,32,76,1,63.32106,-92.08174,'9/14/2014 0:10','NW');

    The generated file name is mc_20250905073013526gra1l214x6t6_M1_1_0_0-0_TableSink1_beijing.jsonl, where 20250905073013526 is the system-generated timestamp, and the middle part is the task identifier.

FAQ

Error: Unexpected end-of-input: expected close marker for OBJECT

  • Error message

    ODPS-0123131:User defined function exception - Traceback:
    com.aliyun.odps.serde.SerDeException: org.apache.hadoop.hive.serde2.SerDeException: org.codehaus.jackson.JsonParseException: Unexpected end-of-input: expected close marker for OBJECT (from [Source: java.io.ByteArrayInputStream@5a021cb9; line: 1, column: 0])
     at [Source: java.io.ByteArrayInputStream@5a021cb9; line: 1, column: 3]
    	at com.aliyun.odps.hive.wrapper.HiveSerDeWrapper.deserialize(HiveSerDeWrapper.java:122)
    	at com.aliyun.odps.udf.HiveReaderHandler.next(HiveReaderHandler.java:152)
    	at com.aliyun.odps.udf.HiveReaderHandler5c9b68c118d14fb2b392e8d916ddea8c.next(Unknown Source)
  • Cause

    This error typically occurs with invalid JSON data, such as a JSON Lines (JSONL) file. The error is triggered if a record contains an unescaped newline character, violating the one-record-per-line rule.

  • Solution

    Escape the newline characters in the JSON file and then read the data.

  • Troubleshooting

    When you enable BadRowSkipping, details about skipped rows are printed to the stdout log in Logview. This helps you diagnose data errors. Use the following settings to enable this feature:

    -- Set the BadRowSkipping parameter to on at the session level to skip the error data.
    SET odps.sql.unstructured.text.bad.row.skipping=on;
    
    -- Specify the number of error records that can be printed to stdout in Logview.
    SET odps.sql.unstructured.text.bad.row.skipping.debug.num=<number>;

Whitelist parameter error reading JSON external table: Start token not found where expected

  • Error message

    FAILED: ODPS-0123131:User defined function exception - Traceback:
    com.aliyun.odps.serde.SerDeException: org.apache.hadoop.hive.serde2.SerDeException: java.io.IOException: Start token not found where expected
            at com.aliyun.odps.hive.wrapper.HiveSerDeWrapper.deserialize(HiveSerDeWrapper.java:122)
            at com.aliyun.odps.udf.HiveReaderHandler.next(HiveReaderHandler.java:152)
    Caused by: org.apache.hadoop.hive.serde2.SerDeException: java.io.IOException: Start token not found where expected
            at org.apache.hive.hcatalog.data.JsonSerDe.deserialize(JsonSerDe.java:190)
            at com.aliyun.odps.hive.wrapper.json.JsonEnhancedSerde.deserialize(JsonEnhancedSerde.java:50)
            at com.aliyun.odps.hive.wrapper.HiveSerDeWrapper.deserialize(HiveSerDeWrapper.java:120)
            ... 1 more
    Caused by: java.io.IOException: Start token not found where expected
            at org.apache.hive.hcatalog.data.JsonSerDe.deserialize(JsonSerDe.java:176)
            ... 3 more
     | fatalInstance: Odps/yyy_yueyi_dev_20251226063242326gd2yy12fi2h3_SQL_0_1_0_job_0/M1#0_0 
  • Cause

    When matching by whitelist parameters, no files are matched.

  • Solution

    Verify that the regex pattern in the whitelist parameter is correct.

Supported data types

For more information about MaxCompute data types, see Data types (Version 1.0) and Data types (Version 2.0).

Type

Supported

Type

Supported

TINYINT

Yes

STRING

Yes

SMALLINT

Yes

DATE

Yes

INT

Yes

DATETIME

No

BIGINT

Yes

TIMESTAMP

No

BINARY

No

TIMESTAMP_NTZ

Yes

FLOAT

Yes

BOOLEAN

Yes

DOUBLE

Yes

ARRAY

Yes

DECIMAL(precision, scale)

Yes

MAP

Yes

VARCHAR(n)

Yes

STRUCT

Yes

CHAR(n)

Yes

JSON

No

Supported compression formats

To write compressed files to OSS, add the tblproperties clause and configure the compression properties. For more information, see TBLPROPERTIES parameters.

Compression property

Read

Write

Gzip

Yes

Yes

BZip2

Yes

Yes

Deflate

Yes

Yes

ZSTD

Yes

Yes

SNAPPY(SnappyRawCodec)

Yes

No

SNAPPY(SnappyCodec)

Yes

Yes

When reading compressed TEXTFILE files whose filenames contain the .bz2, .deflate, .snappy, .gz, or .zstd suffix, no additional configuration is required.

Supported Schema evolution

JSON external tables map table columns to JSON fields by name.

In the following table, Data compatibility indicates whether the table can still read historical data correctly after a schema change.

Operation

Supported

Description

Data compatibility

Add a column

Yes

  • You cannot specify the order of a new column. It is added as the last column by default.

  • Default values for newly added regular columns apply only to data written by MaxCompute.

  • Data that complies with the modified schema can be read correctly.

  • Existing data that uses the old schema is read based on the new schema.

    Example: When reading historical data that lacks the new column, MaxCompute populates that column with NULL.

Delete a column

Yes

JSON external tables map columns by name.

Compatible

Change column order

Yes

JSON external tables map columns by name.

Compatible

Change column data type

Yes

For information about supported data type conversions, see Change column data type.

Compatible

Rename a column

No

This operation is not recommended. JSON external tables map columns by name. After you rename a column, the column name in the JSON file no longer matches the new schema, which may cause read operations to fail.

  • Data that complies with the modified schema can be read correctly.

  • Existing data that uses the old schema is read based on the new schema.

    Example: After you rename a column, if the corresponding key in the JSON file is not renamed, the column returns NULL when you read the table.

Modify a column comment

Yes

The comment must be a valid string of no more than 1,024 bytes. Otherwise, an error is reported.

Compatible

Modify the non-null property of a column

No

This operation is not supported. Columns are nullable by default.

Not applicable