Tabel merupakan unit penyimpanan data dasar di MaxCompute. Semua tugas pengembangan, analisis, dan O&M dalam gudang data berpusat pada data tabel. Dokumen ini menjelaskan operasi tabel umum, seperti membuat, menghapus, dan mengkueri tabel.
Alat eksekusi
Jalankan perintah dalam topik ini menggunakan alat berikut:
Operasi umum
Jenis
Fungsi
Peran
Membuat Tabel non-partisi, Tabel partisi, Tabel eksternal, atau Tabel terkluster.
Pengguna dengan izin
CreateTablepada suatu Proyek.Mengubah Pemilik suatu Tabel.
Pemilik Proyek
Menghapus Tabel non-partisi atau Tabel partisi.
Pengguna dengan izin
DROPpada suatu Tabel.Menampilkan informasi tentang Tabel Terkelola MaxCompute, Tampilan, atau Tabel Eksternal.
Pengguna dengan izin
Describepada metadata tabel.Menampilkan informasi partisi untuk Tabel Partisi tertentu.
Pengguna dengan izin
Describepada metadata tabel.Menampilkan semua tabel dan tampilan dalam suatu Proyek, atau yang sesuai aturan tertentu (ekspresi reguler didukung).
Pengguna dengan izin
Listpada suatu Proyek.Menampilkan semua partisi dalam suatu Tabel.
Pengguna dengan izin
Listpada suatu Proyek.
Buat tabel
Membuat tabel dalam proyek saat ini.
Batasan
Tingkat partisi maksimum: 6 (misalnya,
year/month/week/day/hour/minute).Jumlah partisi maksimum per tabel: 60.000 (default).
Untuk daftar lengkap batasan, lihat Batasan SQL MaxCompute.
Sintaksis
Tabel standar (partisi atau non-partisi)
CREATE [OR REPLACE] TABLE [IF NOT EXISTS] <table_name> ( <col_name> <data_type>, ... ) [COMMENT <table_comment>] [PARTITIONED BY (<col_name> <data_type> [COMMENT <col_comment>], ...)] [AUTO PARTITIONED BY (<auto_partition_expression> [AS <auto_partition_column_name>]) [TBLPROPERTIES('ingestion_time_partition'='true')] ];Clustered Table
CREATE TABLE [IF NOT EXISTS] <table_name> ( <col_name> <data_type>, ... ) [CLUSTERED BY | RANGE CLUSTERED BY (<col_name> [, <col_name>, ...]) [SORTED BY (<col_name> [ASC | DESC] [, <col_name> [ASC | DESC] ...])] INTO <number_of_buckets> BUCKETS];Tabel eksternal (Contoh: OSS)
Lihat Membuat tabel eksternal OSS.
CREATE EXTERNAL TABLE [IF NOT EXISTS] <mc_oss_extable_name> ( <col_name> <data_type>, ... ) STORED AS '<file_format>' [WITH SERDEPROPERTIES (options)] LOCATION '<oss_location>';Tabel transaksional dan Delta
Tabel transaksional: Mendukung UPDATE/DELETE.
CREATE [EXTERNAL] TABLE [IF NOT EXISTS] <table_name> ( <col_name> <data_type> [NOT NULL] [DEFAULT <default_value>] [COMMENT <col_comment>], ... [COMMENT <table_comment>] [TBLPROPERTIES ("transactional"="true")];Tabel Delta: Mendukung upsert, kueri inkremental, dan time travel.
CREATE [EXTERNAL] TABLE [IF NOT EXISTS] <table_name> ( <col_name> <data_type> [NOT NULL] [DEFAULT <default_value>] [COMMENT <col_comment>], ... [PRIMARY KEY (<pk_col_name>[, <pk_col_name2>, ...] )]) [COMMENT <table_comment>] [TBLPROPERTIES ("transactional"="true" [, "write.bucket.num" = "N", "acid.data.retain.hours"="hours"...])] [LIFECYCLE <days>];
Klausa CTAS dan LIKE
CTAS: Membuat tabel dan menyalin data. Properti partisi TIDAK disalin.
CREATE TABLE [IF NOT EXISTS] <table_name> [LIFECYCLE <days>] AS <select_statement>;Create Like: Menyalin skema tetapi tidak menyalin data.
CREATE TABLE [IF NOT EXISTS] <table_name> [LIFECYCLE <days>] LIKE <existing_table_name>;
Parameter
Parameter umum
Parameter | Wajib | Deskripsi | Keterangan |
OR REPLACE | Tidak | Mengganti tabel jika sudah ada. | Setara dengan menghapus tabel (jika ada) lalu membuatnya kembali. Catatan Tidak dapat digunakan bersama |
EXTERNAL | Tidak | Membuat tabel eksternal. | N/A |
IF NOT EXISTS | Tidak | Membuat tabel hanya jika belum ada. | Jika tabel sudah ada, operasi diabaikan. |
table_name | Ya | Nama tabel. | Batas panjang: 128 byte. Tidak peka huruf besar/kecil. Karakter yang diizinkan: huruf, angka, dan garis bawah (_). |
PRIMARY KEY(pk) | Tidak | Menentukan kolom kunci primer. | Hanya didukung untuk tabel Delta. Harus NOT NULL dan unik. |
col_name | Ya | Nama kolom. | Batas panjang: 128 byte. Tidak peka huruf besar/kecil. |
COMMENT | Tidak | Komentar untuk tabel atau kolom. | Panjang maksimum: 1.024 byte. |
data_type | Ya | Tipe data kolom. | Lihat Tipe data. |
NOT NULL | Tidak | Melarang nilai NULL dalam kolom. | Lihat Ubah properti tabel. |
DEFAULT | Tidak | Nilai default yang digunakan jika tidak ditentukan. | Fungsi dinamis seperti |
LIFECYCLE | Tidak | Periode retensi data dalam hari. | Bilangan bulat positif.
|
Parameter untuk tabel partisi
Tabel Partisi Standar
Parameter | Wajib | Deskripsi | Keterangan |
PARTITIONED BY | Ya | Menentukan kolom partisi. | Saling eksklusif dengan |
col_name | Ya | Nama kolom partisi. | Batas panjang: 128 byte. Tidak peka huruf besar/kecil. |
data_type | Ya | Tipe data kolom partisi. | MaxCompute V1.0: Hanya STRING. |
Tabel AUTO PARTITION
Parameter | Wajib | Deskripsi | Keterangan |
AUTO PARTITIONED BY | Ya | Menentukan logika partisi otomatis. | Saling eksklusif dengan |
Expression | Ya | Ekspresi untuk pembuatan kunci partisi. | Saat ini mendukung |
Parameter untuk tabel terkluster
Tabel Terkluster Hash
Parameter | Wajib | Deskripsi | Keterangan |
CLUSTERED BY | Ya | Menentukan kolom yang digunakan untuk pengelompokan hash. | Praktik terbaik: Gunakan kolom dengan kardinalitas tinggi atau kunci gabungan. |
SORTED BY | Ya | Menentukan urutan pengurutan dalam bucket. | Sebaiknya sesuai dengan kolom |
INTO N BUCKETS | Ya | Menentukan jumlah bucket. | Disarankan: Kelipatan pangkat 2 (misalnya, 512, 1024). Maksimum: 4096. |
Contoh
Buat tabel non-partisi
CREATE TABLE test1 (key STRING);Buat tabel partisi
CREATE TABLE IF NOT EXISTS sale_detail(
shop_name STRING,
customer_id STRING,
total_price DOUBLE)
PARTITIONED BY (sale_date STRING, region STRING);Buat tabel dengan menyalin (CTAS)
-- Buat tabel dan salin data (properti partisi hilang)
CREATE TABLE sale_detail_ctas1 LIFECYCLE 10 AS SELECT * FROM sale_detail;Ubah pemilik tabel
Batasan
Hanya pengguna dengan peran Pemilik Proyek atau Super_Administrator yang dapat menjalankan perintah ini.
Sintaksis
ALTER TABLE <table_name> CHANGEOWNER TO <new_owner>;Parameter
table_name: Wajib. Nama tabel yang akan diubah pemiliknya.
new_owner: Wajib. Akun pemilik baru.
Jika pemilik baru adalah pengguna Resource Access Management (RAM):
Pengguna RAM harus menjadi anggota Proyek yang berisi tabel tersebut.
Format:
RAM$<UID>:<ram_name>, dengan UID sebagai ID Akun Alibaba Cloud Anda dan ram_name sebagai Nama Tampilan pengguna RAM.
Contoh
Ubah pemilik tabel test1 menjadi
ALIYUN$xxx@aliyun.com.ALTER TABLE test1 CHANGEOWNER TO 'ALIYUN$xxx@aliyun.com';Ubah pemilik tabel test1 menjadi pengguna RAM bernama
ram_test.ALTER TABLE test1 CHANGEOWNER TO 'RAM$13xxxxxxxxxxx:ram_test';
Hapus tabel
Menghapus tabel dan datanya. Operasi ini tidak dapat dikembalikan.
Peringatan
Peringatan: Tabel yang dihapus tidak dapat dipulihkan kecuali fitur backup dan restore diaktifkan.
Sintaksis
DROP TABLE [IF EXISTS] <table_name>; Contoh
DROP TABLE IF EXISTS sale_detail; Tabel atau tampilan
Menampilkan informasi tentang Tabel Terkelola, Tampilan, Tampilan yang di-materialisasi, Tabel Eksternal, Tabel Terkluster, atau Tabel Transaksional di MaxCompute.
Sintaksis
-- Tampilkan informasi tentang tabel internal atau tampilan.
DESC <table_name|view_name> [PARTITION (<pt_spec>)];
-- Tampilkan informasi tentang tampilan yang di-materialisasi, tabel eksternal, tabel terkluster, atau tabel transaksional. Anda juga dapat menggunakan perintah ini untuk melihat informasi tambahan tentang tabel internal.
DESC extended <table_name|mv_name>; Parameter
Nama Parameter | Deskripsi |
table_name | Wajib. Nama tabel yang ingin dilihat. |
view_name | Wajib. Nama tampilan yang ingin dilihat. |
mv_name | Nama tampilan yang di-materialisasi yang ingin dikueri. |
pt_spec | Opsional. Partisi yang ingin dilihat dalam tabel partisi. Formatnya adalah |
extended | Sertakan parameter ini untuk menampilkan informasi tambahan untuk tampilan yang di-materialisasi, tabel eksternal, tabel terkluster, atau tabel transaksional. Anda juga dapat menggunakan parameter ini untuk melihat informasi tambahan untuk tabel internal, seperti properti non-null kolom. |
Nilai yang dikembalikan
Nama parameter | Deskripsi |
Owner | Akun pemilik tabel atau tampilan. |
Project | Proyek tempat tabel atau tampilan berada. |
TableComment | Komentar tabel atau tampilan. |
CreateTime | Waktu saat tabel atau tampilan dibuat. |
LastDDLTime | Waktu terakhir Data Definition Language (DDL) tabel atau tampilan dimodifikasi. |
LastModifiedTime | Waktu terakhir data dalam tabel atau tampilan dimodifikasi. |
LastAccessTime | Waktu terakhir data dalam tabel atau tampilan diakses. Waktu ini hanya sebagai referensi. Perbedaan hingga 24 jam dapat terjadi antara nilai ini dan waktu akses aktual. Jika data sering diakses, nilai LastAccessTime tidak diperbarui jika telah diperbarui dalam 24 jam terakhir. Hal ini mengurangi overhead performa akibat pembaruan yang sering. |
Lifecycle | Lifecycle dalam hari. |
InternalTable | Menunjukkan apakah objek tersebut merupakan tabel internal. Parameter ini hanya dikembalikan untuk objek tabel. |
VirtualView | Menunjukkan apakah objek tersebut merupakan tampilan. Parameter ini hanya dikembalikan untuk objek tampilan. |
Size | Ukuran tabel dalam byte. |
NativeColumns | Informasi kolom tabel atau tampilan. |
PartitionColumns | Informasi kolom kunci partisi. Parameter ini hanya dikembalikan untuk tabel partisi. |
Contoh
Ukuran yang dikembalikan oleh
DESC table_namemencakup data dalam Keranjang daur ulang.Untuk mengecualikan data dalam Keranjang daur ulang dari perhitungan ukuran, jalankan terlebih dahulu
PURGE TABLE table_name. Kemudian, jalankanDESC table_name.Jalankan
SHOW recyclebinuntuk melihat detail data dalam Keranjang daur ulang untuk proyek saat ini.
Contoh 1: Tampilkan tabel non-partisi
Buat tabel uji.
CREATE TABLE test_table ( key STRING );Tampilkan informasi tentang tabel test_table.
DESC test_table;Hasil yang dikembalikan.
+------------------------------------------------------------------------------------+ | 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 | | | +------------------------------------------------------------------------------------+
Contoh 2: Tampilkan tabel partisi
Buat tabel uji.
CREATE TABLE test_table_partition ( shop_name STRING, customer_id STRING, total_price DOUBLE ) PARTITIONED BY ( sale_date STRING, region STRING );Tampilkan informasi tentang tabel yang dibuat.
DESC test_table_partition;Hasil yang dikembalikan.
+------------------------------------------------------------------------------------+ | 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 | | +------------------------------------------------------------------------------------+
Contoh 3: Tampilkan informasi detail tabel partisi
Buat tabel uji.
CREATE TABLE IF NOT EXISTS test_table_partition ( shop_name STRING, customer_id STRING, total_price DOUBLE ) PARTITIONED BY ( sale_date STRING, region STRING );Tampilkan informasi tentang tabel yang dibuat.
DESC EXTENDED test_table_partition;Hasil yang dikembalikan.
+------------------------------------------------------------------------------------+ | 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 | +------------------------------------------------------------------------------------+
Contoh 4: Tampilkan tabel dengan lifecycle
Buat tabel uji.
CREATE TABLE sale_detail_ctas( shop_name STRING, customer_id STRING, total_price DOUBLE, sale_date STRING, region STRING ) LIFECYCLE 10;Tampilkan informasi detail tentang tabel yang dibuat.
DESC EXTENDED sale_detail_ctas;Hasil yang dikembalikan.
+------------------------------------------------------------------------------------+ | 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 | +------------------------------------------------------------------------------------
Contoh 5: Tampilkan tabel dengan berbagai tipe data
Buat tabel uji.
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) );Tampilkan informasi detail tentang tabel yang dibuat.
DESC test_newtype;Hasil yang dikembalikan.
+------------------------------------------------------------------------------------+ | 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) | | | +------------------------------------------------------------------------------------
Contoh 6: Tampilkan tabel terkluster hash non-partisi
Buat tabel uji.
CREATE TABLE hash_clustered_nonpar ( a STRING, b STRING, c BIGINT ) CLUSTERED BY (c) SORTED BY (c ASC) INTO 1024 BUCKETS;Tampilkan informasi detail tentang tabel yang dibuat.
DESC EXTENDED hash_clustered_nonpar;Hasil yang dikembalikan.
Properti kluster muncul di bagian 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 | +------------------------------------------------------------------------------------
Contoh 7: Tampilkan tabel terkluster hash partisi
Buat tabel uji.
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;Tampilkan informasi detail tentang tabel yang dibuat.
DESC EXTENDED hash_clustered_par;Hasil yang dikembalikan.
Properti kluster muncul di bagian 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] | +------------------------------------------------------------------------------------
Contoh 8: Tampilkan tabel terkluster range non-partisi
Buat tabel uji.
CREATE TABLE range_clustered_nonpar ( a STRING, b STRING, c BIGINT ) RANGE CLUSTERED BY (c);Tampilkan informasi detail tentang tabel yang dibuat.
DESC EXTENDED range_clustered_nonpar;Hasil yang dikembalikan.
Properti kluster muncul di bagian Extended Info.
+------------------------------------------------------------------------------------+ | Pemilik: ALIYUN$***_com | | Proyek: testproject | | Komentar Tabel: | +------------------------------------------------------------------------------------+ | Waktu Pembuatan: 2025-12-15 16:30:45 | | Waktu DDL Terakhir: 2025-12-15 16:30:45 | | Waktu Modifikasi Terakhir:2025-12-15 16:30:45 | +------------------------------------------------------------------------------------+ | Tabel Internal: YA | Ukuran: 0 | +------------------------------------------------------------------------------------+ | Kolom Asli: | +------------------------------------------------------------------------------------+ | Bidang | Tipe | Label | Label Tambahan | Dapat Bernilai Null | Nilai Bawaan | Komentar | +------------------------------------------------------------------------------------+ | a | string | | | true | NULL | | | b | string | | | true | NULL | | | c | bigint | | | true | NULL | | +------------------------------------------------------------------------------------+ | Informasi Tambahan: | +------------------------------------------------------------------------------------+ | ID Tabel: bf01d946c4b24c0e9c54ccfe8750b7c2 | | Telah Diarsipkan: false | | Ukuran Fisik: 0 | | Jumlah Berkas: 0 | | Disimpan Sebagai: AliOrc | | Strategi Kompresi: normal | | odps.timemachine.retention.days: 1 | | Status Penyimpanan Dingin: N/A | | enkripsi_diaktifkan: false | | Jenis Kluster: range | | Jumlah Bucket: 0 | | Kolom Kluster: [c] | | Jenis Penyimpanan: Standard | | Waktu Modifikasi Terakhir Jenis Penyimpanan: 2025-12-15 16:30:45 | +------------------------------------------------------------------------------------+
Contoh 9: Tampilkan tabel terkluster range partisi
Buat tabel uji.
CREATE TABLE range_clustered_par ( a STRING, b STRING, c BIGINT ) PARTITIONED BY ( dt STRING ) RANGE CLUSTERED BY (c);Tampilkan informasi detail tentang tabel yang dibuat.
DESC EXTENDED range_clustered_par;Hasil yang dikembalikan.
Properti kluster muncul di bagian 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] | +------------------------------------------------------------------------------------
Contoh 10: Periksa apakah tabel non-partisi bersifat transaksional
Gunakan Klien MaxCompute versi 0.35.4 atau lebih baru untuk memeriksa apakah suatu tabel merupakan tabel transaksional.
Alat lain mungkin tidak mendukung fitur ini jika belum ditingkatkan ke versi yang diperlukan, dan hasil kueri mungkin menghilangkan informasi transaksional.
Buat tabel uji.
CREATE TABLE tran_nonpar ( id BIGINT ) TBLPROPERTIES ('transactional'='true');Tampilkan informasi detail tentang tabel yang dibuat.
DESC EXTENDED tran_nonpar;Hasil yang dikembalikan.
Properti Transactional muncul di bagian Extended Info.
+------------------------------------------------------------------------------------+ | 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 | +------------------------------------------------------------------------------------+
Contoh 11: Periksa apakah tabel partisi bersifat transaksional
Gunakan Klien MaxCompute versi 0.35.4 atau lebih baru untuk memeriksa apakah suatu tabel merupakan tabel transaksional.
Alat lain mungkin tidak mendukung fitur ini jika belum ditingkatkan ke versi yang diperlukan, dan hasil kueri mungkin menghilangkan informasi transaksional.
Buat tabel uji.
CREATE TABLE tran_par ( id BIGINT ) PARTITIONED BY ( ds STRING ) TBLPROPERTIES ('transactional'='true');Tampilkan informasi detail tentang tabel yang dibuat.
DESC EXTENDED tran_par;Hasil yang dikembalikan.
Properti Transactional muncul di bagian Extended Info.
+------------------------------------------------------------------------------------+ | 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 | +------------------------------------------------------------------------------------
Contoh 12: Tampilkan tampilan yang di-materialisasi mv
Buat tabel uji.
-- Buat tabel dasar uji. CREATE TABLE page_view_logs ( page_id STRING, user_id STRING, view_timestamp BIGINT ); -- Buat tampilan yang di-materialisasi untuk menghitung jumlah tampilan halaman (PV) tiap halaman. CREATE MATERIALIZED VIEW mv AS SELECT page_id, COUNT(1) AS pv_count FROM page_view_logs GROUP BY page_id;Tampilkan informasi detail tentang tampilan yang di-materialisasi.
DESC EXTENDED mv;Hasil yang dikembalikan.
+------------------------------------------------------------------------------------+ | 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 | +------------------------------------------------------------------------------------+
Contoh 13: Tampilkan informasi partisi
Buat tabel uji.
-- Buat tabel uji. CREATE TABLE IF NOT EXISTS test_table_partition ( shop_name STRING, customer_id STRING, total_price DOUBLE ) PARTITIONED BY ( sale_date STRING, region STRING ); -- Buat partisi. ALTER TABLE test_table_partition ADD IF NOT EXISTS PARTITION (sale_date='201310', region='beijing'); -- Gunakan INSERT INTO untuk menambahkan data ke partisi yang ditentukan. 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);Kueri informasi partisi untuk tabel partisi.
DESC test_table_partition PARTITION (sale_date='201310', region='beijing');Hasil yang dikembalikan.
+------------------------------------------------------------------------------------+ | PartitionSize: 1163 | +------------------------------------------------------------------------------------+ | CreateTime: 2025-12-15 16:54:16 | | LastDDLTime: 2025-12-15 16:54:16 | | LastModifiedTime: 2025-12-15 16:54:23 | +------------------------------------------------------------------------------------
Tampilkan informasi partisi
Menampilkan informasi partisi tentang tabel partisi.
Sintaksis
desc <table_name> partition (<pt_spec>);Parameter
table_name: wajib. Nama tabel partisi yang informasi partisinya ingin dilihat.
pt_spec: wajib. Informasi tentang partisi yang ingin dilihat. Nilai parameter ini dalam format
partition_col1=col1_value1, partition_col2=col2_value1.... Jika tabel memiliki partisi multi-level, Anda harus menentukan nilai semua kolom kunci partisi.
Contoh
-- Kueri informasi tentang tabel partisi sale_detail. desc sale_detail partition (sale_date='201310',region='beijing');Hasil berikut dikembalikan:
+------------------------------------------------------------------------------------+ | PartitionSize: 2109112 | +------------------------------------------------------------------------------------+ | CreateTime: 2015-10-10 08:48:48 | | LastDDLTime: 2015-10-10 08:48:48 | | LastModifiedTime: 2015-10-11 01:33:35 | +------------------------------------------------------------------------------------+ OK
Tampilkan tabel dan tampilan dalam proyek
Menampilkan semua tabel dan tampilan atau tabel dan tampilan yang memenuhi aturan tertentu dalam suatu proyek.
Sintaksis
-- Tampilkan semua tabel dan tampilan dalam proyek. show tables; -- Tampilkan tabel atau tampilan yang namanya mengandung kata kunci chart dalam proyek. show tables like '<chart>';Contoh
-- Tampilkan tabel yang namanya mengandung kata kunci sale* dalam proyek. Tanda bintang (*) menunjukkan karakter apa pun. show tables like 'sale*';Hasil berikut dikembalikan:
ALIYUN$account_name:sale_detail ...... -- ALIYUN adalah prompt sistem, yang menunjukkan bahwa tabel dibuat menggunakan Akun Alibaba Cloud. Jika tabel dibuat oleh pengguna RAM, prompt sistemnya adalah RAM.
Tampilkan partisi
Menampilkan semua partisi suatu tabel. Jika tabel tidak ada atau tabel tersebut merupakan tabel non-partisi, kesalahan akan dikembalikan.
Sintaksis
show partitions <table_name>;Parameter
table_name: wajib. Nama tabel partisi yang informasi partisinya ingin dilihat.
Contoh
-- Tampilkan semua partisi tabel sale_detail. show partitions sale_detail;Hasil berikut dikembalikan:
sale_date=201310/region=beijing sale_date=201312/region=shenzhen sale_date=201312/region=xian sale_date=2014/region=shenzhen OK
Dokumentasi terkait
Untuk memodifikasi skema tabel, seperti menambah kolom, menghapus kolom, atau mengubah tipe data kolom, lihat Operasi partisi.
Untuk menyalin data tabel ke tabel lain, lihat CLONE TABLE.
Untuk memperbarui atau menghapus data dalam tabel transaksional, lihat Perbarui atau hapus data (UPDATE | DELETE).