全部產品
Search
文件中心

MaxCompute:DESC TABLE/VIEW

更新時間:Dec 16, 2025

查看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                                      |
    +------------------------------------------------------------------------------------+

相關命令