#!/usr/bin/env python3 """pyspark_012 database initialization: create tables + load seed data""" from pyspark.sql import SparkSession spark = SparkSession.builder \ .appName('dataclaw_eval_init_pyspark_012') \ .enableHiveSupport() \ .config('spark.sql.warehouse.dir', '/tmp/hive_warehouse') \ .getOrCreate() spark.sql('CREATE DATABASE IF NOT EXISTS internal_platform_db') # Create input table 1: priority info spark.sql(''' CREATE TABLE IF NOT EXISTS internal_platform_db.sec_app_hy_top_500_sites_tag_v1_pyspark_100 ( `host` STRING, `fld` STRING, `priority` STRING, `is_host` STRING ) STORED AS ORC ''') spark.sql(''' INSERT INTO TABLE internal_platform_db.sec_app_hy_top_500_sites_tag_v1_pyspark_100 VALUES ('www.example.com', 'example.com', 'P1', '1'), ('news.test.org', 'test.org', 'P2', '0'), ('blog.demo.net', 'demo.net', 'P3', '1') ''') # Create input table 2: daily parse results spark.sql(''' CREATE TABLE IF NOT EXISTS internal_platform_db.ai_engine_classify_parse_result_daily_pyspark_100 ( `cos_path` STRING, `url` STRING, `cos_url` STRING, `language` STRING, `web_type` STRING, `ori_title` STRING, `content` STRING, `publish_time` STRING, `site_name` STRING, `ana_title` STRING, `cont_title` STRING, `author_src` STRING, `html_md` STRING, `if_contain_dirty_char` STRING, `tag` STRING, `host` STRING, `fld` STRING, `is_error` STRING, `error_step` STRING, `error_info` STRING, `meta_data` STRING, `classify_info` STRING, `parse_html` STRING, `crawl_time` STRING ) PARTITIONED BY (`date_key` STRING) STORED AS ORC ''') spark.sql(''' INSERT INTO TABLE internal_platform_db.ai_engine_classify_parse_result_daily_pyspark_100 PARTITION (date_key='20260510') VALUES ('cos1','http://www.example.com/p1','cos_u1','zh','内容页','t1','c1','2026-05-10','site1','at1','ct1','auth1','html1','0','tag1','www.example.com','example.com','0',NULL,NULL,'meta1','cls1','{"content":"This is a long enough content for testing purposes here"}','2026-05-10'), ('cos2','http://www.example.com/p2','cos_u2','zh','索引页','t2','c2','2026-05-10','site1','at2','ct2','auth2','html2','0','tag2','www.example.com','example.com','0',NULL,NULL,'meta2','cls2','{"content":"short"}','2026-05-10'), ('cos3','http://www.example.com/p3','cos_u3','zh','内容页','t3','c3','2026-05-10','site1','at3','ct3','auth3','html3','0','tag3','www.example.com','example.com','1','2','err info 3','meta3','cls3','{"content":""}','2026-05-10'), ('cos4','http://news.test.org/p1','cos_u4','en','内容页','t4','c4','2026-05-10','site2','at4','ct4','auth4','html4','0','tag4','news.test.org','test.org','0',NULL,NULL,'meta4','cls4','{"content":"Another long content that is definitely more than fifty characters total"}','2026-05-10'), ('cos5','http://news.test.org/p2','cos_u5','en','索引页','t5','c5','2026-05-10','site2','at5','ct5','auth5','html5','0','tag5','news.test.org','test.org','1','1','err info 5','meta5','cls5','{"content":""}','2026-05-10') ''') spark.sql(''' INSERT INTO TABLE internal_platform_db.ai_engine_classify_parse_result_daily_pyspark_100 PARTITION (date_key='20260512') VALUES ('cos6','http://blog.demo.net/p1','cos_u6','zh','内容页','t6','c6','2026-05-12','site3','at6','ct6','auth6','html6','0','tag6','blog.demo.net','demo.net','0',NULL,NULL,'meta6','cls6','{"content":"Blog post content that is long enough to pass the fifty char threshold easily"}','2026-05-12'), ('cos7','http://blog.demo.net/p2','cos_u7','zh','内容页','t7','c7','2026-05-12','site3','at7','ct7','auth7','html7','0','tag7','blog.demo.net','demo.net','1','3','err info 7','meta7','cls7','{"content":"x"}','2026-05-12'), ('cos8','http://www.example.com/p4','cos_u8','zh','索引页','t8','c8','2026-05-12','site1','at8','ct8','auth8','html8','0','tag8','www.example.com','example.com','0',NULL,NULL,'meta8','cls8','{"content":"ok content more than fifty chars to be safe and avoid short classification"}','2026-05-12') ''') print('Database initialization complete') spark.stop()