| |
| """pyspark_004 database initialization: tele-sale corp domain JOIN + CASE WHEN""" |
| from pyspark.sql import SparkSession |
|
|
| spark = SparkSession.builder \ |
| .appName('dataclaw_eval_init_pyspark_004') \ |
| .enableHiveSupport() \ |
| .config('spark.sql.warehouse.dir', '/tmp/hive_warehouse') \ |
| .getOrCreate() |
|
|
| spark.sql('CREATE DATABASE IF NOT EXISTS internal_platform_db') |
|
|
| |
| spark.sql(''' |
| CREATE TABLE IF NOT EXISTS internal_platform_db.project_alpha_ods_tele_sale_clue_info_mysql_v3 ( |
| `corpid` BIGINT COMMENT 'corpid', |
| `kf_name` STRING COMMENT '销售姓名', |
| `source` BIGINT COMMENT '来源(多个)', |
| `clue_status` BIGINT COMMENT '线索状态', |
| `contact_status` BIGINT COMMENT '沟通状态', |
| `contact_vid` BIGINT COMMENT '联系人vid', |
| `register_vid` BIGINT COMMENT '登记联系vid', |
| `register_name` STRING COMMENT '登记联系姓名', |
| `register_content` STRING COMMENT '登记内容', |
| `register_by` STRING COMMENT '登记人员', |
| `last_service_content` STRING COMMENT '最后一次沟通记录', |
| `last_service_time` STRING COMMENT '最后一次服务时间', |
| `next_service_time` STRING COMMENT '下次服务时间', |
| `sign_time` STRING COMMENT '签入时间', |
| `create_time` STRING COMMENT '创建时间', |
| `delete_status` BIGINT COMMENT '删除状态', |
| `release_time` STRING COMMENT '释放时间', |
| `intention_product` STRING COMMENT '意向产品', |
| `service_type` STRING COMMENT '服务类型', |
| `new_source` BIGINT COMMENT '新线索类型', |
| `new_sign_time` STRING COMMENT '新线索签入时间', |
| `source_cnt` BIGINT COMMENT '线索命中次数', |
| `clue_type` BIGINT COMMENT '线索类型,0:普通销售团队 1:三非企业', |
| `imp_date` STRING COMMENT '日期分区(沙箱化为普通列)' |
| ) STORED AS ORCFILE |
| ''') |
|
|
| |
| spark.sql(''' |
| CREATE TABLE IF NOT EXISTS internal_platform_db.project_alpha_dws_ww_corpstat_usermail_v3 ( |
| `corpid` BIGINT COMMENT 'corpid', |
| `contact_alias_uniq` BIGINT, |
| `contact_bind_uniq` BIGINT, |
| `contact_alias_monthwakeup_uniq` BIGINT, |
| `contact_bind_monthwakeup_uniq` BIGINT, |
| `contact_alias_monthwakeup_ratio` DOUBLE, |
| `contact_bind_monthwakeup_ratio` DOUBLE, |
| `contact_bind_ratio` DOUBLE, |
| `top_domain` STRING COMMENT '最多人邮箱域名', |
| `domain_type` STRING, |
| `domain_isp` STRING COMMENT '邮箱服务商', |
| `domain_area` STRING, |
| `domain_alias_uniq` BIGINT, |
| `domain_bind_uniq` BIGINT, |
| `domain_alias_monthwakeup_uniq` BIGINT COMMENT '过滤条件 >=1', |
| `domain_bind_monthwakeup_uniq` BIGINT, |
| `domain_bind_monthtablogin_uniq` BIGINT, |
| `rk_alias` BIGINT, |
| `rk_bind` BIGINT, |
| `bind_att_uniq` BIGINT, |
| `bind_succ_uniq` BIGINT, |
| `bind_fail_uniq` BIGINT, |
| `bind_succ_ratio` DOUBLE, |
| `openstatus` BIGINT, |
| `is_blacklist` BIGINT, |
| `domain_num` BIGINT, |
| `domain_account_num` BIGINT, |
| `isp_type` STRING, |
| `all_member_uniq` BIGINT, |
| `month_wakeup_uniq` BIGINT, |
| `imp_date` STRING COMMENT '日期分区(沙箱化为普通列)' |
| ) STORED AS ORCFILE |
| ''') |
|
|
| |
| spark.sql(''' |
| INSERT INTO TABLE internal_platform_db.project_alpha_ods_tele_sale_clue_info_mysql_v3 |
| VALUES |
| (1001, 'sale_a', 1, 1, 1, 100, 200, 'name1', 'content1', 'admin', 'last1', '2026-05-01', '2026-05-20', '2026-01-01', '2026-01-01', 0, NULL, 'prod1', 'type1', 1, '2026-01-01', 2, 1, '20260513'), |
| (1002, 'sale_b', 2, 1, 1, 101, 201, 'name2', 'content2', 'admin', 'last2', '2026-05-02', '2026-05-21', '2026-01-02', '2026-01-02', 0, NULL, 'prod2', 'type2', 2, '2026-01-02', 3, 1, '20260513'), |
| (1003, 'sale_c', 3, 1, 1, 102, 202, 'name3', 'content3', 'admin', 'last3', '2026-05-03', '2026-05-22', '2026-01-03', '2026-01-03', 0, NULL, 'prod3', 'type3', 3, '2026-01-03', 1, 0, '20260513'), |
| (1001, 'sale_a', 1, 2, 2, 100, 200, 'name1', 'content1b', 'admin', 'last1b', '2026-05-04', '2026-05-23', '2026-01-04', '2026-01-04', 0, NULL, 'prod1', 'type1', 1, '2026-01-04', 2, 1, '20260513'), |
| (1004, 'sale_d', 4, 1, 1, 103, 203, 'name4', 'content4', 'admin', 'last4', '2026-05-05', '2026-05-24', '2026-01-05', '2026-01-05', 0, NULL, 'prod4', 'type4', 4, '2026-01-05', 5, 1, '20260513'), |
| (1005, 'sale_e', 5, 1, 1, 104, 204, 'name5', 'content5', 'admin', 'last5', '2026-05-06', '2026-05-25', '2026-01-06', '2026-01-06', 0, NULL, 'prod5', 'type5', 5, '2026-01-06', 1, 1, '20260513') |
| ''') |
|
|
| |
| spark.sql(''' |
| INSERT INTO TABLE internal_platform_db.project_alpha_dws_ww_corpstat_usermail_v3 |
| VALUES |
| (1001, 10, 5, 3, 2, 0.3, 0.2, 0.5, 'im.example.com', 'free', 'other_zijian', 'cn', 8, 4, 2, 1, 1, 1, 1, 5, 4, 1, 0.8, 1, 0, 3, 1, 'free', 50, 20, '20260513'), |
| (1001, 10, 5, 3, 2, 0.3, 0.2, 0.5, 'mail_n.example.com', 'free', 'mail_provider_n', 'cn', 6, 3, 1, 1, 1, 2, 2, 3, 2, 1, 0.67, 1, 0, 3, 1, 'free', 50, 20, '20260513'), |
| (1002, 20, 10, 5, 4, 0.25, 0.2, 0.5, 'mail_o.example.com', 'corp', 'outlook', 'us', 15, 8, 3, 2, 2, 1, 1, 10, 8, 2, 0.8, 1, 0, 2, 1, 'corp', 100, 40, '20260513'), |
| (1002, 20, 10, 5, 4, 0.25, 0.2, 0.5, 'cloud_a.example.com', 'corp', 'cloud_a', 'cn', 12, 6, 2, 1, 1, 2, 2, 8, 6, 2, 0.75, 1, 0, 2, 1, 'corp', 100, 40, '20260513'), |
| (1003, 30, 15, 8, 6, 0.27, 0.2, 0.5, 'mail_c.example.com', 'corp', 'coremail', 'cn', 20, 10, 5, 3, 3, 1, 1, 15, 12, 3, 0.8, 1, 0, 4, 2, 'corp', 200, 80, '20260513'), |
| (1004, 15, 7, 4, 3, 0.27, 0.2, 0.47, 'collabf.cn', 'corp', 'collabf', 'cn', 10, 5, 3, 2, 2, 1, 1, 7, 5, 2, 0.71, 1, 0, 2, 1, 'corp', 80, 30, '20260513'), |
| (1004, 15, 7, 4, 3, 0.27, 0.2, 0.47, 'biz.mail.example.com', 'corp', 'biz', 'cn', 8, 4, 1, 1, 1, 2, 2, 5, 4, 1, 0.8, 1, 0, 2, 1, 'corp', 80, 30, '20260513'), |
| (1005, 5, 2, 1, 1, 0.2, 0.2, 0.4, 'exchange.local', 'corp', 'exchange_local', 'cn', 4, 2, 1, 1, 1, 1, 1, 2, 2, 0, 1.0, 1, 0, 1, 0, 'corp', 30, 10, '20260513'), |
| (1005, 5, 2, 1, 1, 0.2, 0.2, 0.4, 'test.com', 'other', NULL, 'cn', 3, 1, 0, 0, 0, 2, 2, 1, 1, 0, 1.0, 0, 0, 1, 0, 'other', 30, 10, '20260513') |
| ''') |
|
|
| print('Database initialization complete') |
| spark.stop() |
|
|