- 建立以 (day,event_bucket) 分区的新表
CREATE TABLE rawdata.event_export_partitoin ( event_id INT, month_id INT, week_id INT, user_id BIGINT, distinct_id STRING, time TIMESTAMP, _offset BIGINT, p__app_version STRING, p__browser STRING, p__browser_version STRING, p__carrier STRING, p__city STRING, p__country STRING, p__device_id STRING, p__element_content STRING, p__element_id STRING, p__element_position STRING, p__element_type STRING, p__event_duration BIGINT, p__ip STRING, p__is_first_day BIGINT, p__is_first_time BIGINT, p__is_login_id BIGINT, p__kafka_offset BIGINT, p__lib STRING, p__lib_version STRING, p__manufacturer STRING, p__model STRING, p__network_type STRING, p__os STRING, p__os_version STRING, p__province STRING, p__referrer STRING, p__resume_from_background BIGINT, p__screen_height BIGINT, p__screen_name STRING, p__screen_width BIGINT, p__title STRING, p__track_signup_original_id STRING, p__url STRING, p__wifi BIGINT, p_productname STRING, p_productprice BIGINT, p_buttonname STRING, p_companyname STRING, p_count_i BIGINT, p_customname STRING, p_customtype STRING, p_data_flag STRING, p_entrance STRING, p_grade BIGINT, p_is_check BIGINT, p_is_first_day BIGINT, p_is_first_day_start BIGINT, p_is_first_time BIGINT, p_is_first_time_start BIGINT, p_is_success BIGINT, p_linkclassify STRING, p_linkname STRING, p_logintyle STRING, p_memberid BIGINT, p_mobile STRING, p_msg_id STRING, p_msg_title STRING, p_operationobject STRING, p_operationtype STRING, p_other_property STRING, p_programauthority STRING, p_programid BIGINT, p_programname STRING, p_programtype STRING, p_promotioncode STRING, p_realname STRING, p_referrer STRING, p_referrer_host STRING, p_resume_from_background BIGINT, p_schemaclassify1 STRING, p_schemaclassify2 STRING, p_school STRING, p_superkey STRING, p_superkey2 STRING, p_teamidentify STRING, p_teamname STRING, p_teamname_member STRING, p_test_boolean1 BIGINT, p_test_boolean2 BIGINT, p_test_boolean3 BIGINT, p_test_count BIGINT, p_test_number1 BIGINT, p_test_number2 BIGINT, p_test_number3 BIGINT, p_test_text1 STRING, p_test_text2 STRING, p_test_text3 STRING, p_title STRING, p_url STRING, p_url_path STRING, p_utm_campaign STRING, p_utm_content STRING, p_utm_medium STRING, p_utm_source STRING, p_utm_term STRING )partitioned by (day INT, event_bucket INT);
分区列 day , event_bucket 不出现在create table 后面的对列定义的列表中
- 将event_export 表中的数据insert进分区表
insert into table event_export_partition PARTITION(day,event_bucket) select event_id, month_id, week_id, user_id, distinct_id, time, _offset, p__app_version, p__browser, p__browser_version, p__carrier, p__city, p__country, p__device_id, p__element_content, p__element_id, p__element_position, p__element_type, p__event_duration, p__ip, p__is_first_day, p__is_first_time, p__is_login_id, p__kafka_offset, p__lib, p__lib_version, p__manufacturer, p__model, p__network_type, p__os, p__os_version, p__province, p__referrer, p__resume_from_background, p__screen_height, p__screen_name, p__screen_width, p__title, p__track_signup_original_id, p__url, p__wifi, p_productname, p_productprice, p_buttonname, p_companyname, p_count_i, p_customname, p_customtype, p_data_flag, p_entrance, p_grade, p_is_check, p_is_first_day, p_is_first_day_start, p_is_first_time, p_is_first_time_start, p_is_success, p_linkclassify, p_linkname, p_logintyle, p_memberid, p_mobile, p_msg_id, p_msg_title, p_operationobject, p_operationtype, p_other_property, p_programauthority, p_programid, p_programname, p_programtype, p_promotioncode, p_realname, p_referrer, p_referrer_host, p_resume_from_background, p_schemaclassify1, p_schemaclassify2, p_school, p_superkey, p_superkey2, p_teamidentify, p_teamname, p_teamname_member, p_test_boolean1, p_test_boolean2, p_test_boolean3, p_test_count, p_test_number1, p_test_number2, p_test_number3, p_test_text1, p_test_text2, p_test_text3, p_title, p_url, p_url_path, p_utm_campaign, p_utm_content, p_utm_medium, p_utm_source, p_utm_term ,day,event_bucket from event_export
对于动态分区,即未给PARTITION(day,event_export)赋默认值,则定义的分区字段必须在 SELECT *所返回列的最后,这样就会自动按列表的最后字段做分区
- 总共100天的数据被分成100 个partition
