Gunakan pernyataan LOAD untuk memuat data dari penyimpanan eksternal—seperti Hologres, Object Storage Service (OSS), Amazon Redshift, dan BigQuery—ke tabel atau partisi MaxCompute.
Ikhtisar
MaxCompute menggunakan perintah LOAD OVERWRITE atau LOAD INTO untuk mengimpor data dalam format CSV atau format open-source lainnya dari penyimpanan eksternal—seperti Hologres, Object Storage Service (OSS), Amazon Redshift, dan BigQuery—ke tabel atau partisi MaxCompute.
Anda harus terlebih dahulu mengimpor data dari Amazon Redshift dan BigQuery ke OSS sebelum dapat memuatnya ke MaxCompute.
MaxCompute menggunakan partisi dinamis untuk memuat data ke tabel partisi.
Perintah
LOAD INTOmenambahkan data ke tabel atau partisi, sedangkan perintahLOAD OVERWRITEterlebih dahulu mengosongkan tabel atau partisi sebelum menyisipkan data baru.
Batasan
Persyaratan izin
Izin MaxCompute
Izin CreateTable dan Alter: Diperlukan untuk membuat tabel atau memodifikasi data tabel dalam proyek MaxCompute. Untuk petunjuknya, lihat Izin MaxCompute.
Izin penyimpanan eksternal
Izin OSS: Anda harus memberikan izin kepada MaxCompute untuk mengakses OSS (membaca dan melihat daftar objek). Untuk keamanan yang lebih baik, gunakan mode STS untuk otorisasi. Untuk informasi selengkapnya, lihat Otorisasi akses dalam mode STS.
Izin Hologres: Untuk memberikan otorisasi akses MaxCompute ke Hologres, buat peran RAM, berikan izin yang diperlukan, lalu tambahkan peran tersebut ke instans Hologres. Untuk detailnya, lihat Buat tabel eksternal Hologres (mode STS).
Batasan lainnya
Perintah LOAD tidak mendukung parameter allowlist/denylist.
Penyimpanan eksternal dan proyek MaxCompute tujuan harus berada di wilayah yang sama.
Saat memuat data dari OSS:
Skema tabel partisi tujuan (tidak termasuk kolom partisi) harus sesuai dengan skema data eksternal. Skema data eksternal tidak boleh mencakup kolom partisi.
Saat memuat data dari Hologres:
Anda tidak dapat memuat data dari tabel partisi Hologres ke MaxCompute.
MaxCompute tidak dapat memuat data dari tabel eksternal Hologres yang menggunakan mode otorisasi dual signature.
Muat data
OSS dan Hologres
Muat data dari OSS atau Hologres
Sintaks perintah
{LOAD OVERWRITE|INTO} TABLE <table_name> [PARTITION (<pt_spec>)]
FROM LOCATION <external_location>
STORED BY <StorageHandler>
[WITH SERDEPROPERTIES (<Options>)];Parameter
OSS
Hologres
Contoh
OSS
Contoh ini menunjukkan cara memuat data menggunakan extractor bawaan (StorageHandler). Contoh ini mengasumsikan bahwa MaxCompute dan OSS dimiliki oleh Akun Alibaba Cloud yang sama dan menunjukkan cara memuat data dari file vehicle.csv ke MaxCompute melalui jaringan internal Alibaba Cloud.
Simpan file vehicle.csv ke direktori
mc-test/data_location/dalam bucket OSS di wilayahoss-cn-hangzhou, lalu buat path direktori OSS. Untuk informasi selengkapnya tentang cara membuat bucket OSS, lihat Buat bucket.Path direktori OSS dibuat dari informasi bucket, wilayah, dan endpoint sebagai berikut:
oss://oss-cn-hangzhou-internal.aliyuncs.com/mc-test/data_location/Masuk ke Klien MaxCompute (odpscmd) untuk membuat tabel tujuan
ambulance_data_csv_load. Contoh perintah:CREATE TABLE ambulance_data_csv_load ( vehicleId INT, recordId INT, patientId INT, calls INT, locationLatitude DOUBLE, locationLongitude DOUBLE, recordTime STRING, direction STRING );Jalankan perintah
load overwriteuntuk memuat filevehicle.csvdari OSS ke tabel tujuan. Contoh perintah:LOAD OVERWRITE TABLE ambulance_data_csv_load FROM LOCATION 'oss://oss-cn-hangzhou-internal.aliyuncs.com/mc-test/data_location/' STORED BY 'com.aliyun.odps.CsvStorageHandler' WITH SERDEPROPERTIES ( -- ARN dari AliyunODPSDefaultRole. Anda dapat memperolehnya di halaman manajemen peran RAM. 'odps.properties.rolearn'='acs:ram::xxxxx:role/aliyunodpsdefaultrole', 'odps.text.option.delimiter'=',' );Untuk melihat ARN suatu peran, lihat Lihat peran RAM.
Verifikasi data dalam tabel tujuan
ambulance_data_csv_load. Contoh perintah:-- Aktifkan pemindaian tabel penuh. Pengaturan ini hanya berlaku untuk sesi saat ini. set odps.sql.allow.fullscan=true; SELECT * FROM ambulance_data_csv_load; -- Hasil berikut dikembalikan: +------------+------------+------------+------------+------------------+-------------------+------------+------------+ | vehicleid | recordid | patientid | calls | locationlatitude | locationlongitude | recordtime | direction | +------------+------------+------------+------------+------------------+-------------------+------------+------------+ | 1 | 1 | 51 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | S | | 1 | 2 | 13 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | NE | | 1 | 3 | 48 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | NE | | 1 | 4 | 30 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | W | | 1 | 5 | 47 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | S | | 1 | 6 | 9 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | S | | 1 | 7 | 53 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | N | | 1 | 8 | 63 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | SW | | 1 | 9 | 4 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | NE | | 1 | 10 | 31 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | N | +------------+------------+------------+------------+------------------+-------------------+------------+------------+
Hologres
Skenario
Instans dan database Hologres telah dibuat, serta tabel telah dibuat dalam database tersebut.
Tabel eksternal Hologres telah dibuat di MaxCompute. Anda dapat mengkueri data dalam tabel Hologres menggunakan tabel eksternal tersebut.
-- Kueri tabel eksternal Hologres: SELECT * FROM holo_ext; -- Hasil berikut dikembalikan: +------------+------+ | id | name | +------------+------+ | 1 | abc | | 2 | ereg | +------------+------+Contoh berikut menunjukkan cara menggunakan perintah LOAD untuk memuat data dari tabel Hologres ini ke tabel internal MaxCompute.
Buat tabel internal MaxCompute.
-- Buat tabel internal. CREATE TABLE from_holo(id BIGINT, name STRING);Gunakan perintah LOAD untuk memuat data ke MaxCompute.
-- Muat data dari tabel Hologres ke tabel internal MaxCompute. LOAD INTO TABLE from_holo FROM LOCATION 'jdbc:postgresql://hgprecn-cn-wwo3ft0l****-cn-beijing-internal.hologres.aliyuncs.com:80/<YOUR_HOLO_DB_NAME>?application_name=MaxCompute¤tSchema=public&useSSL=false&table=<YOUR_HOLOGRES_TABLE_NAME>/' STORED BY 'com.aliyun.odps.jdbc.JdbcStorageHandler' WITH SERDEPROPERTIES ( 'odps.properties.rolearn'='acs:ram::18927322887*****:role/hologresrole', 'mcfed.mapreduce.jdbc.driver.class'='org.postgresql.Driver', 'odps.federation.jdbc.target.db.type'='holo' );
Kueri tabel untuk melihat hasilnya.
SELECT * FROM from_holo; -- Hasil berikut dikembalikan: +------------+------+ | id | name | +------------+------+ | 2 | ereg | | 1 | abc | +------------+------+
Format open-source lainnya
Muat data dalam format open-source lainnya
Ukuran file tunggal yang akan dimuat tidak boleh melebihi 3 GB. Jika file terlalu besar, pisahkan terlebih dahulu sebelum memuat.
Sintaks perintah
{LOAD OVERWRITE|INTO} TABLE <table_name> [PARTITION (<pt_spec>)]
FROM LOCATION <external_location>
[ROW FORMAT SERDE '<serde_class>'
[WITH SERDEPROPERTIES (<Options>)]
]
STORED AS <file_format>;Parameter
Contoh
Akun yang sama
Kepemilikan akun yang sama
Contoh ini menunjukkan cara memuat data dari file vehicle.textfile ke MaxCompute melalui jaringan internal Alibaba Cloud.
Jika MaxCompute dan OSS dimiliki oleh Akun Alibaba Cloud yang berbeda, lihat Otorisasi dalam mode STS.
Simpan file vehicle.textfile ke direktori
mc-test/data_location/dalam bucket OSS di wilayahoss-cn-hangzhou, lalu buat path direktori OSS. Untuk informasi selengkapnya tentang cara membuat bucket OSS, lihat Buat bucket.Path direktori OSS dibuat dari informasi bucket, wilayah, dan endpoint sebagai berikut:
oss://oss-cn-hangzhou-internal.aliyuncs.com/mc-test/data_location/Masuk ke Klien MaxCompute (odpscmd) untuk membuat tabel tujuan
ambulance_data_textfile_load_pt. Contoh perintah:CREATE TABLE ambulance_data_textfile_load_pt ( vehicleId STRING, recordId STRING, patientId STRING, calls STRING, locationLatitude STRING, locationLongitude STRING, recordTime STRING, direction STRING ) PARTITIONED BY ( ds STRING );Jalankan perintah
load overwriteuntuk memuat filevehicle.textfiledari OSS ke tabel tujuan. Contoh perintah:LOAD OVERWRITE TABLE ambulance_data_textfile_load_pt PARTITION(ds='20200910') FROM LOCATION 'oss://oss-cn-hangzhou-internal.aliyuncs.com/mc-test/data_location/' ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' WITH SERDEPROPERTIES ('field.delim' = ',') STORED AS TEXTFILE;Verifikasi data dalam tabel tujuan ambulance_data_textfile_load_pt. Contoh perintah:
-- Aktifkan pemindaian tabel penuh. Pengaturan ini hanya berlaku untuk sesi saat ini. SET odps.sql.allow.fullscan=true; SELECT * FROM ambulance_data_textfile_load_pt; -- Hasil berikut dikembalikan: +-----------+----------+-----------+-------+------------------+-------------------+----------------+-----------+----------+ | vehicleid | recordid | patientid | calls | locationlatitude | locationlongitude | recordtime | direction | ds | +-----------+----------+-----------+-------+------------------+-------------------+----------------+-----------+----------+ | 1 | 1 | 51 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | S | 20200910 | | 1 | 2 | 13 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | NE | 20200910 | | 1 | 3 | 48 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | NE | 20200910 | | 1 | 4 | 30 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | W | 20200910 | | 1 | 5 | 47 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | S | 20200910 | | 1 | 6 | 9 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | S | 20200910 | | 1 | 7 | 53 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | N | 20200910 | | 1 | 8 | 63 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | SW | 20200910 | | 1 | 9 | 4 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | NE | 20200910 | | 1 | 10 | 31 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | N | 20200910 | +-----------+----------+-----------+-------+------------------+-------------------+----------------+-----------+----------+
Partisi dinamis
Muat data menggunakan partisi dinamis
Anda dapat menggunakan partisi dinamis untuk memuat data ketika subdirektori OSS Anda dinamai sesuai dengan pasangan kunci-nilai partisi, seperti ds=20200909/.
Simpan file vehicle1.csv dan vehicle2.csv ke direktori
mc-test/data_location/ds=20200909/danmc-test/data_location/ds=20200910/di bucket OSS wilayahoss-cn-hangzhou, lalu buat path direktori OSS. Untuk informasi selengkapnya tentang cara membuat bucket OSS, lihat Buat bucket.Path direktori OSS dibuat dari informasi bucket, wilayah, dan endpoint sebagai berikut:
oss://oss-cn-hangzhou-internal.aliyuncs.com/mc-test/data_location/ds=20200909/' oss://oss-cn-hangzhou-internal.aliyuncs.com/mc-test/data_location/ds=20200910/'Login ke Klien MaxCompute (odpscmd) untuk membuat tabel tujuan
ambulance_data_csv_load_dynpt. Contoh perintah:CREATE TABLE ambulance_data_csv_load_dynpt ( vehicleId STRING, recordId STRING, patientId STRING, calls STRING, locationLatitude STRING, locationLongitude STRING, recordTime STRING, direction STRING ) PARTITIONED BY ( ds STRING );Jalankan perintah
load overwriteuntuk memuat file dari OSS ke tabel tujuan. Contoh perintah:LOAD OVERWRITE TABLE ambulance_data_csv_load_dynpt PARTITION(ds) FROM LOCATION 'oss://oss-cn-hangzhou-internal.aliyuncs.com/mc-test/data_location/' ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde' STORED AS TEXTFILE;Verifikasi data dalam tabel tujuan
ambulance_data_csv_load_dynpt. Contoh perintah:-- Aktifkan pemindaian tabel penuh. Pengaturan ini hanya berlaku untuk sesi saat ini. SET odps.sql.allow.fullscan=true; SELECT * FROM ambulance_data_csv_load_dynpt; -- Hasil berikut dikembalikan: +------------+------------+------------+------------+------------------+-------------------+----------------+------------+------------+ | vehicleid | recordid | patientid | calls | locationlatitude | locationlongitude | recordtime | direction | ds | +------------+------------+------------+------------+------------------+-------------------+----------------+------------+------------+ | 1 | 7 | 53 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | N | 20200909 | | 1 | 8 | 63 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | SW | 20200909 | | 1 | 9 | 4 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | NE | 20200909 | | 1 | 10 | 31 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | N | 20200909 | | 1 | 1 | 51 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | S | 20200910 | | 1 | 2 | 13 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | NE | 20200910 | | 1 | 3 | 48 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | NE | 20200910 | | 1 | 4 | 30 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | W | 20200910 | | 1 | 5 | 47 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | S | 20200910 | | 1 | 6 | 9 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | S | 20200910 | +------------+------------+------------+------------+------------------+-------------------+----------------+------------+------------+
Penagihan
Perintah LOAD memuat data eksternal ke gudang data. Meskipun Anda tidak dikenai biaya atas volume data yang diimpor dalam model pay-as-you-go atau atas tugas individual dalam model langganan, semua tugas LOAD mengonsumsi sumber daya komputasi dari kelompok sumber daya mereka.
Referensi
Untuk mengekspor data dari proyek MaxCompute ke penyimpanan eksternal, seperti OSS atau Hologres, agar dapat digunakan oleh mesin komputasi lain, lihat UNLOAD.
Impor data ke MaxCompute
Data dari Amazon Redshift dan BigQuery harus ditempatkan sementara di OSS sebelum Anda dapat memuatnya ke MaxCompute.
Impor data OSS
Saat Anda memuat data ke tabel partisi MaxCompute, skemanya (tidak termasuk kolom partisi) harus sesuai dengan skema data eksternal. Skema data eksternal tidak boleh mencakup kolom partisi.
Format teks (CSV dan TSV)
Gunakan StorageHandler bawaan untuk memuat data dalam format CSV atau TSV.
Sintaks
LOAD {OVERWRITE|INTO} TABLE <table_name> [PARTITION (<pt_spec>)]
FROM LOCATION <oss_location>
STORED BY <StorageHandler>
[WITH SERDEPROPERTIES ('<property_name>'='<property_value>',...)];Parameter
Parameter | Deskripsi |
| Path ke objek sumber di OSS. Formatnya adalah |
| Menentukan handler penyimpanan bawaan:
|
| Menentukan properti untuk SerDe (Serializer/Deserializer):
|
Contoh
Contoh 1: Muat data dari file CSV ke MaxCompute
Contoh ini menunjukkan cara memuat data dari file vehicle.csv yang disimpan di OSS ke tabel MaxCompute. File vehicle.csv berisi data berikut:
1,1,51,1,46.81006,-92.08174,9/14/2014 0:00,S
1,2,13,1,46.81006,-92.08174,9/14/2014 0:00,NE
1,3,48,1,46.81006,-92.08174,9/14/2014 0:00,NE
1,4,30,1,46.81006,-92.08174,9/14/2014 0:00,W
1,5,47,1,46.81006,-92.08174,9/14/2014 0:00,S
1,6,9,1,46.81006,-92.08174,9/14/2014 0:00,S
1,7,53,1,46.81006,-92.08174,9/14/2014 0:00,N
1,8,63,1,46.81006,-92.08174,9/14/2014 0:00,SW
1,9,4,1,46.81006,-92.08174,9/14/2014 0:00,NE
1,10,31,1,46.81006,-92.08174,9/14/2014 0:00,NProsedur:
Di OSS: Masuk ke Konsol OSS. Simpan file
vehicle.csvke direktorimc-load/data_location/dalam bucket di wilayahoss-cn-hangzhou. Untuk detail pembuatan bucket, lihat Buat bucket. Buat path OSS berdasarkan bucket, wilayah, dan endpoint sebagai berikut:oss://oss-cn-hangzhou-internal.aliyuncs.com/mc-load/data_location/Di MaxCompute: Login ke Klien MaxCompute, buat tabel tujuan, dan jalankan pernyataan
LOAD.-- Buat tabel tujuan. CREATE TABLE IF NOT EXISTS ambulance_data_csv_load ( vehicleId INT, recordId INT, patientId INT, calls INT, locationLatitute DOUBLE, locationLongtitue DOUBLE, recordTime STRING, direction STRING ); -- Jalankan pernyataan LOAD. LOAD OVERWRITE TABLE ambulance_data_csv_load FROM LOCATION 'oss://oss-cn-hangzhou-internal.aliyuncs.com/mc-load/data_location/' STORED BY 'com.aliyun.odps.CsvStorageHandler' WITH SERDEPROPERTIES ( 'odps.properties.rolearn'='acs:ram::123456789:role/AliyunODPSDefaultRole', 'odps.text.option.delimiter'=',' );Verifikasi hasil: Kueri tabel tujuan.
-- Aktifkan pemindaian tabel penuh (berlaku hanya untuk sesi saat ini). SET odps.sql.allow.fullscan=true; SELECT * FROM ambulance_data_csv_load;Hasil:
+------------+------------+------------+------------+------------------+-------------------+------------+------------+ | vehicleid | recordid | patientid | calls | locationlatitute | locationlongtitue | recordtime | direction | +------------+------------+------------+------------+------------------+-------------------+------------+------------+ | 1 | 1 | 51 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | S | | 1 | 2 | 13 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | NE | +------------+------------+------------+------------+------------------+-------------------+------------+------------+
Contoh 2: Muat data ke tabel partisi menggunakan partisi dinamis
Contoh ini menunjukkan cara memuat data dari file vehicle1.csv dan vehicle2.csv yang disimpan di OSS ke partisi yang sesuai dalam tabel MaxCompute. File vehicle1.csv dan vehicle2.csv berisi data berikut:
--vehicle1.csv
1,1,51,1,46.81006,-92.08174,9/14/2014 0:00,S
1,2,13,1,46.81006,-92.08174,9/14/2014 0:00,NE
1,3,48,1,46.81006,-92.08174,9/14/2014 0:00,NE
1,4,30,1,46.81006,-92.08174,9/14/2014 0:00,W
1,5,47,1,46.81006,-92.08174,9/14/2014 0:00,S
1,6,9,1,46.81006,-92.08174,9/14/2014 0:00,S
--vehicle2.csv
1,7,53,1,46.81006,-92.08174,9/14/2014 0:00,N
1,8,63,1,46.81006,-92.08174,9/14/2014 0:00,SW
1,9,4,1,46.81006,-92.08174,9/14/2014 0:00,NE
1,10,31,1,46.81006,-92.08174,9/14/2014 0:00,NProsedur:
Di OSS: Masuk ke Konsol OSS. Simpan file
vehicle2.csvke direktorimc-load/data_location/ds=20200909/dan filevehicle1.csvke direktorimc-load/data_location/ds=20200910/dalam bucket di wilayahoss-cn-hangzhou. Untuk informasi selengkapnya tentang cara membuat bucket, lihat Buat bucket. Buat path OSS berdasarkan bucket, wilayah, dan endpoint sebagai berikut:oss://oss-cn-hangzhou-internal.aliyuncs.com/mc-load/data_location/ds=20200909/' oss://oss-cn-hangzhou-internal.aliyuncs.com/mc-load/data_location/ds=20200910/'Di MaxCompute: Login ke Klien MaxCompute, buat tabel tujuan, dan jalankan pernyataan
LOAD.-- Buat tabel tujuan. create table ambulance_data_csv_load_dynpt ( vehicleId STRING, recordId STRING, patientId STRING, calls STRING, locationLatitute STRING, locationLongtitue STRING, recordTime STRING, direction STRING) partitioned by (ds STRING); -- Jalankan pernyataan LOAD. load overwrite table ambulance_data_csv_load_dynpt partition(ds) from location 'oss://oss-cn-hangzhou-internal.aliyuncs.com/mc-load/data_location/' row format serde 'org.apache.hadoop.hive.serde2.OpenCSVSerde' stored as textfile;Verifikasi hasil: Lihat data yang diimpor dalam tabel tujuan.
set odps.sql.allow.fullscan=true; select * from ambulance_data_csv_load_dynpt;Hasil:
+------------+------------+------------+------------+------------------+-------------------+------------+------------+------------+ | vehicleid | recordid | patientid | calls | locationlatitute | locationlongtitue | recordtime | direction | ds | +------------+------------+------------+------------+------------------+-------------------+------------+------------+------------+ | 1 | 7 | 53 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | N | 20200909 | | 1 | 8 | 63 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | SW | 20200909 | | 1 | 9 | 4 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | NE | 20200909 | | 1 | 10 | 31 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | N | 20200909 | | 1 | 1 | 51 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | S | 20200910 | | 1 | 2 | 13 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | NE | 20200910 | | 1 | 3 | 48 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | NE | 20200910 | | 1 | 4 | 30 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | W | 20200910 | | 1 | 5 | 47 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | S | 20200910 | | 1 | 6 | 9 | 1 | 46.81006 | -92.08174 | 9/14/2014 0:00 | S | 20200910 | +------------+------------+------------+------------+------------------+-------------------+------------+------------+------------+
Format open-source
Anda dapat memuat data dari berbagai format open-source, termasuk Parquet, ORC, JSON, Avro, RCFile, SequenceFile, dan TextFile.
Sintaks
LOAD {OVERWRITE|INTO} TABLE <table_name> [PARTITION (<pt_spec>)]
FROM LOCATION <oss_location>
ROW FORMAT SERDE '<serde_class>'
[WITH SERDEPROPERTIES ('<property_name>'='<property_value>',...)]
STORED AS <file_format>;Parameter utama
Parameter | Deskripsi |
| Path ke objek sumber di OSS. Formatnya adalah |
| Format file. Format yang didukung meliputi |
| Kelas SerDe. Misalnya, untuk file Parquet, gunakan |
Contoh penggunaan
Contoh ini menunjukkan cara memuat data dari file vehicle.textfile yang disimpan di Object Storage Service (OSS) ke MaxCompute. File vehicle.textfile berisi data berikut:
1,1,51,1,46.81006,-92.08174,9/14/2014 0:00,S
1,2,13,1,46.81006,-92.08174,9/14/2014 0:00,NE
1,3,48,1,46.81006,-92.08174,9/14/2014 0:00,NE
1,4,30,1,46.81006,-92.08174,9/14/2014 0:00,W
1,5,47,1,46.81006,-92.08174,9/14/2014 0:00,S
1,6,9,1,46.81006,-92.08174,9/14/2014 0:00,S
1,7,53,1,46.81006,-92.08174,9/14/2014 0:00,N
1,8,63,1,46.81006,-92.08174,9/14/2014 0:00,SW
1,9,4,1,46.81006,-92.08174,9/14/2014 0:00,NE
1,10,31,1,46.81006,-92.08174,9/14/2014 0:00,NProsedur:
Di OSS: Masuk ke Konsol OSS. Simpan file
vehicle.textfileke direktorimc-load/data_location/dalam bucket di wilayahoss-cn-hangzhou. Untuk informasi selengkapnya tentang cara membuat bucket, lihat Buat bucket. Buat path OSS berdasarkan bucket, wilayah, dan endpoint sebagai berikut:oss://oss-cn-hangzhou-internal.aliyuncs.com/mc-load/data_location/Di MaxCompute: Login ke Klien MaxCompute, buat tabel tujuan, dan jalankan pernyataan
LOAD.-- Buat tabel tujuan. CREATE TABLE IF NOT EXISTS ambulance_data_textfile_load_pt ( vehicleId STRING, recordId STRING, patientId STRING, calls STRING, locationLatitute STRING, locationLongtitue STRING, recordTime STRING, direction STRING ) PARTITIONED BY (ds STRING); -- Jalankan pernyataan LOAD. LOAD OVERWRITE TABLE ambulance_data_textfile_load_pt PARTITION(ds='20200910') FROM LOCATION 'oss://oss-cn-hangzhou-internal.aliyuncs.com/mc-load/data_location/' ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' STORED AS TEXTFILE;Verifikasi hasil: Kueri tabel tujuan untuk memverifikasi data yang diimpor.
SET odps.sql.allow.fullscan=true; SELECT * FROM ambulance_data_textfile_load_pt;Hasil:
+------------+------------+------------+------------+------------------+-------------------+------------+------------+------------+ | vehicleid | recordid | patientid | calls | locationlatitute | locationlongtitue | recordtime | direction | ds | +------------+------------+------------+------------+------------------+-------------------+------------+------------+------------+ | 1,1,51,1,46.81006,-92.08174,9/14/2014 0:00,S | NULL | NULL | NULL | NULL | NULL | NULL | NULL | 20200910 | | 1,2,13,1,46.81006,-92.08174,9/14/2014 0:00,NE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | 20200910 | | 1,3,48,1,46.81006,-92.08174,9/14/2014 0:00,NE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | 20200910 | | 1,4,30,1,46.81006,-92.08174,9/14/2014 0:00,W | NULL | NULL | NULL | NULL | NULL | NULL | NULL | 20200910 | | 1,5,47,1,46.81006,-92.08174,9/14/2014 0:00,S | NULL | NULL | NULL | NULL | NULL | NULL | NULL | 20200910 | | 1,6,9,1,46.81006,-92.08174,9/14/2014 0:00,S | NULL | NULL | NULL | NULL | NULL | NULL | NULL | 20200910 | | 1,7,53,1,46.81006,-92.08174,9/14/2014 0:00,N | NULL | NULL | NULL | NULL | NULL | NULL | NULL | 20200910 | | 1,8,63,1,46.81006,-92.08174,9/14/2014 0:00,SW | NULL | NULL | NULL | NULL | NULL | NULL | NULL | 20200910 | | 1,9,4,1,46.81006,-92.08174,9/14/2014 0:00,NE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | 20200910 | | 1,10,31,1,46.81006,-92.08174,9/14/2014 0:00,N | NULL | NULL | NULL | NULL | NULL | NULL | NULL | 20200910 | +------------+------------+------------+------------+------------------+-------------------+------------+------------+------------+
Impor data Hologres
Anda dapat memuat data langsung dari tabel eksternal Hologres ke tabel internal MaxCompute.
Otorisasi dual-signature: Tidak didukung.
Tabel partisi: Anda tidak dapat memuat data dari tabel partisi Hologres.
Sintaks
LOAD {OVERWRITE|INTO} TABLE <table_name> [PARTITION (<pt_spec>)]
FROM LOCATION <hologres_location>
STORED BY <StorageHandler>
[WITH SERDEPROPERTIES ('<property_name>'='<property_value>',...)];Parameter utama
Parameter | Deskripsi |
| String koneksi JDBC untuk tabel sumber Hologres. Formatnya adalah: |
| Menentukan handler penyimpanan bawaan. Parameter ini harus diatur ke |
| Harus mencakup properti berikut:
|
Contoh penggunaan
Contoh ini menunjukkan cara memuat data dari tabel holo_2_mc di Hologres ke MaxCompute. Tabel sumber berisi data berikut:
id | name
---|-----
1 | abc
2 | eregProsedur:
Di Hologres: Buat tabel sumber
holo_2_mc, lalu muat data ke dalamnya.Di MaxCompute: Login ke Klien MaxCompute, buat tabel tujuan, dan jalankan pernyataan
LOAD.-- Buat tabel tujuan. CREATE TABLE IF NOT EXISTS mf_from_holo ( id BIGINT, name STRING ); -- Jalankan pernyataan LOAD. LOAD INTO TABLE mf_from_holo FROM LOCATION 'jdbc:postgresql://hgprecn-cn-xxx-cn-beijing-internal.hologres.aliyuncs.com:80/mf_db?application_name=MaxCompute¤tSchema=public&useSSL=false&table=mf_holo/' STORED BY 'com.aliyun.odps.jdbc.JdbcStorageHandler' WITH SERDEPROPERTIES ( 'odps.properties.rolearn'='acs:ram::189273xxx:role/hologressrole', 'mcfed.mapreduce.jdbc.driver.class'='org.postgresql.Driver', 'odps.federation.jdbc.target.db.type'='holo' );Verifikasi hasil: Kueri tabel MaxCompute tujuan.
SELECT * FROM mf_from_holo;Hasil:
+------------+------+ | id | name | +------------+------+ | 1 | abc | | 2 | ereg | +------------+------+