DESC TABLE/VIEW

查看MaxCompute内部表、视图、物化视图、外部表、聚簇表或Transactional表的信息。

命令格式

-- 查看内部表或视图信息。
DESC <table_name|view_name> [PARTITION (<pt_spec>)]; 
-- 查看物化视图、外部表、聚簇表或Transactional表信息。也可以查看内部表的扩展信息。
DESC extended <table_name|mv_name>; 

参数说明

  • table_name:必填。待查看表的名称。

  • view_name:必填。待查看视图的名称。

  • mv_name:待查询物化视图的名称。

  • pt_spec:可选。待查看分区表的指定分区。格式为(partition_col1 = partition_col_value1, partition_col2 = partition_col_value2, ...)

  • extended:如果为物化视图、外部表、聚簇表或Transactional表,需要包含此参数以显示表的扩展信息。对于内部表,也可以使用此参数查看扩展信息,例如列的非空属性。

返回值说明

  • Owner:表或视图的所有者账号。

  • Project:表或视图的所属项目。

  • TableComment:表或视图的注释信息。

  • CreateTime:表或视图的创建时间。

  • LastDDLTime:表或视图的DDL最后变更时间。

  • LastModifiedTime:表或视图的数据最后变更时间。

  • LastAccessTime:表或视图的数据最后访问时间。该时间为参考值,与数据实际最后访问时间最大存在24小时时间差。

    因数据可能会被频繁访问,为降低LastAccessTime刷新的性能损耗,访问某张表的数据时如果LastAccessTime在最近24h内更新过,则不会再次更新。
  • Lifecycle:生命周期(天)。

  • InternalTable:是否为内部表,Table对象才有此返回值。

  • VirtualView:是否为视图,View对象才有此返回值。

  • Size:表大小,单位为Byte。

  • NativeColumns:表或视图的列信息。

  • PartitionColumns:分区列信息,分区表才有此返回值。

使用示例

说明
  • 通过DESC table_name查看到的Size包含了在回收站的数据Size。

  • 如果需要清空回收站,可以先执行PURGE TABLE table_name,然后再执行DESC table_name查看除回收站以外的数据大小。

  • 执行SHOW recyclebin查看本项目中回收站内的数据明细。

示例1:查看创建的非分区表信息

  • 创建测试表

    CREATE TABLE test_table (
        key STRING
    );
  • 查看创建的test_table表信息

    DESC test_table;
  • 返回结果

    +------------------------------------------------------------------------------------+
    | Owner:                    ALIYUN$***_com                                           |
    | Project:                  testproject                                              |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2025-12-15 15:04:49                                      |
    | LastDDLTime:              2025-12-15 15:04:50                                      |
    | LastModifiedTime:         2025-12-15 15:04:49                                      |
    +------------------------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                                  |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field           | Type       | Label | Comment                                     |
    +------------------------------------------------------------------------------------+
    | key             | string     |       |                                             |
    +------------------------------------------------------------------------------------+

示例2:查看创建的分区表信息

  • 创建测试表

    CREATE TABLE test_table_partition (
        shop_name       STRING,
        customer_id     STRING,
        total_price     DOUBLE
    )
    PARTITIONED BY (
        sale_date       STRING,
        region          STRING
    );
  • 查看创建的表信息

    DESC test_table_partition;
  • 返回结果

    +------------------------------------------------------------------------------------+
    | Owner:                    ALIYUN$***_com                                           |
    | Project:                  testproject                                              |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2025-12-15 15:08:27                                      |
    | LastDDLTime:              2025-12-15 15:08:27                                      |
    | LastModifiedTime:         2025-12-15 15:08:27                                      |
    +------------------------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                                  |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field           | Type       | Label | Comment                                     |
    +------------------------------------------------------------------------------------+
    | shop_name       | string     |       |                                             |
    | customer_id     | string     |       |                                             |
    | total_price     | double     |       |                                             |
    +------------------------------------------------------------------------------------+
    | Partition Columns:                                                                 |
    +------------------------------------------------------------------------------------+
    | sale_date       | string     |                                                     |
    | region          | string     |                                                     |
    +------------------------------------------------------------------------------------+
    

示例3:查看包含分区表详细信息

  • 创建测试表

    CREATE TABLE IF NOT EXISTS test_table_partition (
        shop_name       STRING,
        customer_id     STRING,
        total_price     DOUBLE
    )
    PARTITIONED BY (
        sale_date       STRING,
        region          STRING
    );
  • 查看创建的表信息

    DESC EXTENDED test_table_partition;
  • 返回结果

    +------------------------------------------------------------------------------------+
    | Owner:                    ALIYUN$***_com                                           |
    | Project:                  testproject                                              |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2025-12-15 15:08:27                                      |
    | LastDDLTime:              2025-12-15 15:08:27                                      |
    | LastModifiedTime:         2025-12-15 15:08:27                                      |
    +------------------------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                                  |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field    | Type   | Label | ExtendedLabel | Nullable | DefaultValue | Comment      |
    +------------------------------------------------------------------------------------+
    | shop_name | string |      |               | true     | NULL         |              |
    | customer_id | string |    |               | true     | NULL         |              |
    | total_price | double |    |               | true     | NULL         |              |
    +------------------------------------------------------------------------------------+
    | Partition Columns:                                                                 |
    +------------------------------------------------------------------------------------+
    | sale_date       | string     |                                                     |
    | region          | string     |                                                     |
    +------------------------------------------------------------------------------------+
    | Extended Info:                                                                     |
    +------------------------------------------------------------------------------------+
    | TableID:                  8c4d6ed34c964326b45d0435a3babe45                         |
    | IsArchived:               false                                                    |
    | PhysicalSize:             0                                                        |
    | FileNum:                  0                                                        |
    | StoredAs:                 AliOrc                                                   |
    | CompressionStrategy:      normal                                                   |
    | odps.timemachine.retention.days: 1                                                        |
    | encryption_enable:        false                                                    |
    +------------------------------------------------------------------------------------+
    

示例4:查看包含生命周期表的详细信息

  • 创建测试表

    CREATE TABLE sale_detail_ctas(
        shop_name       STRING,
        customer_id     STRING,
        total_price     DOUBLE,
        sale_date       STRING,
        region          STRING
    )
    LIFECYCLE 10;
  • 查看创建的表详细信息

    DESC EXTENDED sale_detail_ctas;
  • 返回结果

    +------------------------------------------------------------------------------------+
    | Owner:                    ALIYUN$***_com                                           |
    | Project:                  testproject                                              |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2025-12-15 15:13:22                                      |
    | LastDDLTime:              2025-12-15 15:13:22                                      |
    | LastModifiedTime:         2025-12-15 15:13:22                                      |
    | Lifecycle:                10                                                       |
    +------------------------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                                  |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field    | Type   | Label | ExtendedLabel | Nullable | DefaultValue | Comment      |
    +------------------------------------------------------------------------------------+
    | shop_name | string |      |               | true     | NULL         |              |
    | customer_id | string |    |               | true     | NULL         |              |
    | total_price | double |    |               | true     | NULL         |              |
    | sale_date | string |      |               | true     | NULL         |              |
    | region   | string |       |               | true     | NULL         |              |
    +------------------------------------------------------------------------------------+
    | Extended Info:                                                                     |
    +------------------------------------------------------------------------------------+
    | TableID:                  8271334ac9724d09a4973b5b3d536f4c                         |
    | IsArchived:               false                                                    |
    | PhysicalSize:             0                                                        |
    | FileNum:                  0                                                        |
    | StoredAs:                 AliOrc                                                   |
    | CompressionStrategy:      normal                                                   |
    | odps.timemachine.retention.days: 1                                                        |
    | ColdStorageStatus:        N/A                                                      |
    | encryption_enable:        false                                                    |
    | StorageTier:              Standard                                                 |
    | StorageTierLastModifiedTime:  2025-12-15 15:13:22                                  |
    +------------------------------------------------------------------------------------+

示例5:查看创建的包含不同数据类型字段的表信息

  • 创建测试表

    CREATE TABLE  test_newtype(
        c1              TINYINT,
        c2              SMALLINT,
        c3              INT,
        c4              BIGINT,
        c5              FLOAT,
        c6              DOUBLE,
        c7              DECIMAL,
        c8              BINARY,
        c9              TIMESTAMP,
        c10             ARRAY<MAP<BIGINT, BIGINT>>,
        c11             MAP<STRING, ARRAY<BIGINT>>,
        c12             STRUCT<s1:STRING, s2:BIGINT>,
        c13             VARCHAR(20)
    );
  • 查看创建的表详细信息

    DESC test_newtype;
  • 返回结果

    +------------------------------------------------------------------------------------+
    | Owner:                    ALIYUN$***_com                                           |
    | Project:                  testproject                                              |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2025-12-15 16:09:18                                      |
    | LastDDLTime:              2025-12-15 16:09:18                                      |
    | LastModifiedTime:         2025-12-15 16:09:18                                      |
    +------------------------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                                  |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field           | Type       | Label | Comment                                     |
    +------------------------------------------------------------------------------------+
    | c1              | tinyint    |       |                                             |
    | c2              | smallint   |       |                                             |
    | c3              | int        |       |                                             |
    | c4              | bigint     |       |                                             |
    | c5              | float      |       |                                             |
    | c6              | double     |       |                                             |
    | c7              | decimal(38,18) |   |                                             |
    | c8              | binary     |       |                                             |
    | c9              | timestamp  |       |                                             |
    | c10             | array<map<bigint,bigint>> |       |                              |
    | c11             | map<string,array<bigint>> |       |                              |
    | c12             | struct<s1:string,s2:bigint> |       |                            |
    | c13             | varchar(20) |       |                                            |
    +------------------------------------------------------------------------------------+

示例6:查看创建的Hash聚簇非分区表信息

  • 创建测试表

    CREATE TABLE hash_clustered_nonpar (
        a               STRING,
        b               STRING,
        c               BIGINT
    )
    CLUSTERED BY (c)
    SORTED BY (c ASC)
    INTO 1024 BUCKETS;
    
  • 查看创建的表详细信息

    DESC EXTENDED hash_clustered_nonpar;
  • 返回结果

    聚簇属性将显示在Extended Info中。

    +------------------------------------------------------------------------------------+
    | Owner:                    ALIYUN$***_com                                           |
    | Project:                  testproject                                              |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2025-12-15 16:18:07                                      |
    | LastDDLTime:              2025-12-15 16:18:07                                      |
    | LastModifiedTime:         2025-12-15 16:18:07                                      |
    +------------------------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                                  |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field    | Type   | Label | ExtendedLabel | Nullable | DefaultValue | Comment      |
    +------------------------------------------------------------------------------------+
    | a        | string |       |               | true     | NULL         |              |
    | b        | string |       |               | true     | NULL         |              |
    | c        | bigint |       |               | true     | NULL         |              |
    +------------------------------------------------------------------------------------+
    | Extended Info:                                                                     |
    +------------------------------------------------------------------------------------+
    | TableID:                  904e6a0d76624346903d59a2b536d0a3                         |
    | IsArchived:               false                                                    |
    | PhysicalSize:             0                                                        |
    | FileNum:                  0                                                        |
    | StoredAs:                 AliOrc                                                   |
    | CompressionStrategy:      normal                                                   |
    | odps.timemachine.retention.days: 1                                                 |
    | ColdStorageStatus:        N/A                                                      |
    | encryption_enable:        false                                                    |
    | ClusterType:              hash                                                     |
    | BucketNum:                1024                                                     |
    | ClusterColumns:           [c]                                                      |
    | SortColumns:              [c ASC]                                                  |
    | StorageTier:              Standard                                                 |
    | StorageTierLastModifiedTime:  2025-12-15 16:18:07                                  |
    +------------------------------------------------------------------------------------+

示例7:查看创建的Hash聚簇分区表信息

  • 创建测试表

    CREATE TABLE hash_clustered_par (
        a               STRING,
        b               STRING,
        c               BIGINT
    )
    PARTITIONED BY (
        dt              STRING
    )
    CLUSTERED BY (c)
    SORTED BY (c ASC)
    INTO 1024 BUCKETS
    LIFECYCLE 2;
    
  • 查看创建的表详细信息

    DESC EXTENDED hash_clustered_par;
  • 返回结果

    聚簇属性将显示在Extended Info中。

    +------------------------------------------------------------------------------------+
    | Owner:                    ALIYUN$***_com                                           |
    | Project:                  testproject                                              |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2025-12-15 16:26:24                                      |
    | LastDDLTime:              2025-12-15 16:26:24                                      |
    | LastModifiedTime:         2025-12-15 16:26:24                                      |
    | Lifecycle:                2                                                        |
    +------------------------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                                  |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field    | Type   | Label | ExtendedLabel | Nullable | DefaultValue | Comment      |
    +------------------------------------------------------------------------------------+
    | a        | string |       |               | true     | NULL         |              |
    | b        | string |       |               | true     | NULL         |              |
    | c        | bigint |       |               | true     | NULL         |              |
    +------------------------------------------------------------------------------------+
    | Partition Columns:                                                                 |
    +------------------------------------------------------------------------------------+
    | dt              | string     |                                                     |
    +------------------------------------------------------------------------------------+
    | Extended Info:                                                                     |
    +------------------------------------------------------------------------------------+
    | TableID:                  5680f0711add43928389db3655d9183e                         |
    | IsArchived:               false                                                    |
    | PhysicalSize:             0                                                        |
    | FileNum:                  0                                                        |
    | StoredAs:                 AliOrc                                                   |
    | CompressionStrategy:      normal                                                   |
    | odps.timemachine.retention.days: 1                                                 |
    | encryption_enable:        false                                                    |
    | ClusterType:              hash                                                     |
    | BucketNum:                1024                                                     |
    | ClusterColumns:           [c]                                                      |
    | SortColumns:              [c ASC]                                                  |
    +------------------------------------------------------------------------------------+

示例8:查看Range聚簇非分区表信息

  • 创建测试表

    CREATE TABLE range_clustered_nonpar (
        a               STRING,
        b               STRING,
        c               BIGINT
    )
    RANGE CLUSTERED BY (c);
  • 查看创建的表详细信息

    DESC EXTENDED range_clustered_nonpar;
  • 返回结果

    聚簇属性将显示在Extended Info中。

    +------------------------------------------------------------------------------------+
    | Owner:                    ALIYUN$***_com                                           |
    | Project:                  testproject                                              |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2025-12-15 16:30:45                                      |
    | LastDDLTime:              2025-12-15 16:30:45                                      |
    | LastModifiedTime:         2025-12-15 16:30:45                                      |
    +------------------------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                                  |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field    | Type   | Label | ExtendedLabel | Nullable | DefaultValue | Comment      |
    +------------------------------------------------------------------------------------+
    | a        | string |       |               | true     | NULL         |              |
    | b        | string |       |               | true     | NULL         |              |
    | c        | bigint |       |               | true     | NULL         |              |
    +------------------------------------------------------------------------------------+
    | Extended Info:                                                                     |
    +------------------------------------------------------------------------------------+
    | TableID:                  bf01d946c4b24c0e9c54ccfe8750b7c2                         |
    | IsArchived:               false                                                    |
    | PhysicalSize:             0                                                        |
    | FileNum:                  0                                                        |
    | StoredAs:                 AliOrc                                                   |
    | CompressionStrategy:      normal                                                   |
    | odps.timemachine.retention.days: 1                                                 |
    | ColdStorageStatus:        N/A                                                      |
    | encryption_enable:        false                                                    |
    | ClusterType:              range                                                    |
    | BucketNum:                0                                                        |
    | ClusterColumns:           [c]                                                      |
    | StorageTier:              Standard                                                 |
    | StorageTierLastModifiedTime:  2025-12-15 16:30:45                                  |
    +------------------------------------------------------------------------------------+

示例9:查看Range聚簇分区表信息

  • 创建测试表

    CREATE TABLE range_clustered_par (
        a               STRING,
        b               STRING,
        c               BIGINT
    )
    PARTITIONED BY (
        dt              STRING
    )
    RANGE CLUSTERED BY (c);
  • 查看创建的表详细信息

    DESC EXTENDED range_clustered_par;
  • 返回结果

    聚簇属性将显示在Extended Info中。

    +------------------------------------------------------------------------------------+
    | Owner:                    ALIYUN$***_com                                           |
    | Project:                  testproject                                              |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2025-12-15 16:33:09                                      |
    | LastDDLTime:              2025-12-15 16:33:09                                      |
    | LastModifiedTime:         2025-12-15 16:33:09                                      |
    +------------------------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                                  |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field    | Type   | Label | ExtendedLabel | Nullable | DefaultValue | Comment      |
    +------------------------------------------------------------------------------------+
    | a        | string |       |               | true     | NULL         |              |
    | b        | string |       |               | true     | NULL         |              |
    | c        | bigint |       |               | true     | NULL         |              |
    +------------------------------------------------------------------------------------+
    | Partition Columns:                                                                 |
    +------------------------------------------------------------------------------------+
    | dt              | string     |                                                     |
    +------------------------------------------------------------------------------------+
    | Extended Info:                                                                     |
    +------------------------------------------------------------------------------------+
    | TableID:                  bdc4f6897691479ea9c315664f26fe39                         |
    | IsArchived:               false                                                    |
    | PhysicalSize:             0                                                        |
    | FileNum:                  0                                                        |
    | StoredAs:                 AliOrc                                                   |
    | CompressionStrategy:      normal                                                   |
    | odps.timemachine.retention.days: 1                                                 |
    | encryption_enable:        false                                                    |
    | ClusterType:              range                                                    |
    | BucketNum:                0                                                        |
    | ClusterColumns:           [c]                                                      |
    +------------------------------------------------------------------------------------+

示例10:查看非分区表是否为Transactional

说明

推荐使用MaxCompute客户端查看表是否为Transactional表,且客户端需要为0.35.4及以上版本。

其他工具可能会存在版本升级未就绪的问题,导致查询结果不显示Transactional信息。

  • 创建测试表

    CREATE TABLE tran_nonpar (
        id              BIGINT
    )
    TBLPROPERTIES ('transactional'='true');
  • 查看创建的表详细信息

    DESC EXTENDED tran_nonpar;
  • 返回结果

    Extended Info中显示Transactional属性。

    +------------------------------------------------------------------------------------+
    | Owner:                    ALIYUN$***_com                                           |
    | Project:                  testproject                                              |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2025-12-15 16:37:27                                      |
    | LastDDLTime:              2025-12-15 16:37:27                                      |
    | LastModifiedTime:         2025-12-15 16:37:27                                      |
    +------------------------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                                  |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field    | Type   | Label | ExtendedLabel | Nullable | DefaultValue | Comment      |
    +------------------------------------------------------------------------------------+
    | id       | bigint |       |               | true     | NULL         |              |
    +------------------------------------------------------------------------------------+
    | Extended Info:                                                                     |
    +------------------------------------------------------------------------------------+
    | TableID:                  43e9710c2b4c404780a7be9998afb23e                         |
    | IsArchived:               false                                                    |
    | PhysicalSize:             0                                                        |
    | FileNum:                  0                                                        |
    | StoredAs:                 AliOrc                                                   |
    | CompressionStrategy:      normal                                                   |
    | Transactional:            true                                                     |
    | IsolationMin:             NONSTRICT_SNAPSHOT_ISOLATION                             |
    | odps.timemachine.retention.days: 1                                                 |
    | ColdStorageStatus:        N/A                                                      |
    | encryption_enable:        false                                                    |
    | StorageTier:              Standard                                                 |
    | StorageTierLastModifiedTime:  2025-12-15 16:37:27                                  |
    +------------------------------------------------------------------------------------+

示例11:查看分区表是否为Transactional

说明

推荐使用MaxCompute客户端查看表是否为Transactional表,且客户端需要为0.35.4及以上版本。

其他工具可能会存在版本升级未就绪的问题,导致查询结果不显示Transactional信息。

  • 创建测试表

    CREATE TABLE tran_par (
        id              BIGINT
    )
    PARTITIONED BY (
        ds              STRING
    )
    TBLPROPERTIES ('transactional'='true');
  • 查看创建的表详细信息

    DESC EXTENDED tran_par;
  • 返回结果

    Extended Info中显示Transactional属性。

    +------------------------------------------------------------------------------------+
    | Owner:                    ALIYUN$***_com                                           |
    | Project:                  testproject                                              |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2025-12-15 16:42:26                                      |
    | LastDDLTime:              2025-12-15 16:42:26                                      |
    | LastModifiedTime:         2025-12-15 16:42:26                                      |
    +------------------------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                                  |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field    | Type   | Label | ExtendedLabel | Nullable | DefaultValue | Comment      |
    +------------------------------------------------------------------------------------+
    | id       | bigint |       |               | true     | NULL         |              |
    +------------------------------------------------------------------------------------+
    | Partition Columns:                                                                 |
    +------------------------------------------------------------------------------------+
    | ds              | string     |                                                     |
    +------------------------------------------------------------------------------------+
    | Extended Info:                                                                     |
    +------------------------------------------------------------------------------------+
    | TableID:                  d4dd59b15f7940bcad4cb5efdb42f242                         |
    | IsArchived:               false                                                    |
    | PhysicalSize:             0                                                        |
    | FileNum:                  0                                                        |
    | StoredAs:                 AliOrc                                                   |
    | CompressionStrategy:      normal                                                   |
    | Transactional:            true                                                     |
    | IsolationMin:             NONSTRICT_SNAPSHOT_ISOLATION                             |
    | odps.timemachine.retention.days: 1                                                 |
    | encryption_enable:        false                                                    |
    +------------------------------------------------------------------------------------+

示例12:查询物化视图mv的信息

  • 创建测试表

    -- 创建一个测试基础表。
    CREATE TABLE page_view_logs (
        page_id STRING,
        user_id STRING,
        view_timestamp BIGINT
    );
    
    -- 创建一个物化视图,计算每个页面的浏览次数 (PV)。
    CREATE MATERIALIZED VIEW mv AS
    SELECT
        page_id,
        COUNT(1) AS pv_count
    FROM
        page_view_logs
    GROUP BY
        page_id;
  • 查看物化视图详细信息

    DESC EXTENDED mv;
  • 返回结果

    +------------------------------------------------------------------------------------+
    | Owner:                    ALIYUN$***_com                                           |
    | Project:                  testproject                                              |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2025-12-15 16:47:51                                      |
    | LastDDLTime:              2025-12-15 16:47:51                                      |
    | LastModifiedTime:         2025-12-15 16:47:51                                      |
    +------------------------------------------------------------------------------------+
    | MaterializedView: YES                                                              |
    | ViewText: SELECT
        page_id,
        COUNT(1) AS pv_count
    FROM
        page_view_logs
    GROUP BY
        page_id |
    | Rewrite Enabled: true                                                              |
    | AutoRefresh Enabled: false                                                         |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field    | Type   | Label | ExtendedLabel | Nullable | DefaultValue | Comment      |
    +------------------------------------------------------------------------------------+
    | page_id  | string |       |               | true     | NULL         |              |
    | pv_count | bigint |       |               | true     | NULL         |              |
    +------------------------------------------------------------------------------------+
    | Extended Info:                                                                     |
    +------------------------------------------------------------------------------------+
    | IsOutdated:               false                                                    |
    | TableID:                  a8742f3751904ec3ade23a7ecc2a2b0b                         |
    | IsArchived:               false                                                    |
    | PhysicalSize:             0                                                        |
    | FileNum:                  0                                                        |
    | StoredAs:                 CFile                                                    |
    | CompressionStrategy:      normal                                                   |
    | odps.timemachine.retention.days: 1                                                        |
    | ColdStorageStatus:        N/A                                                      |
    | encryption_enable:        false                                                    |
    | StorageTier:              Standard                                                 |
    | StorageTierLastModifiedTime:  2025-12-15 16:47:51                                  |
    +------------------------------------------------------------------------------------+
    

示例14:查询分区表的分区信息

  • 创建测试表

    -- 创建一个测试表。
    CREATE TABLE IF NOT EXISTS test_table_partition (
        shop_name       STRING,
        customer_id     STRING,
        total_price     DOUBLE
    )
    PARTITIONED BY (
        sale_date       STRING,
        region          STRING
    );
    
    -- 创建分区。
    ALTER TABLE test_table_partition ADD IF NOT EXISTS 
      PARTITION (sale_date='201310', region='beijing');
      
    -- 使用INSERT INTO向指定分区追加数据。
    INSERT INTO TABLE test_table_partition PARTITION (sale_date='201310', region='beijing')
    VALUES
        ('Apple Store', 'user001', 8888.0),
        ('Nike Store', 'user002', 1200.5),
        ('Starbucks', 'user001', 45.0);
  • 查询分区表的分区信息。

    DESC test_table_partition PARTITION (sale_date='201310', region='beijing');
  • 返回结果

    +------------------------------------------------------------------------------------+
    | PartitionSize: 1163                                                                |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2025-12-15 16:54:16                                      |
    | LastDDLTime:              2025-12-15 16:54:16                                      |
    | LastModifiedTime:         2025-12-15 16:54:23                                      |
    +------------------------------------------------------------------------------------+

相关命令