Datasets:
metadata
id: offline-compute_PrestoSQL_prestosql_010
name: IOC MTTD指标计算
category: offline-compute/PrestoSQL
timeout_seconds: 900
modality: pure-text
engine: prestosql
Prompt
任务目标:从API指标表和威胁情报IOC表中,通过JSON解析提取IOC值,与IOC表关联计算MTTD(平均检测时间)指标,写入输出表。
输入表:
internal_platform_db.t_app_ti_entity_api_metrics_prod_hi_prestosql_010(API指标表)timestampBIGINT — 时间戳usernameSTRING — 用户名appidBIGINT — 应用IDpathSTRING — 路径requestSTRING — 请求体(JSON)responseSTRING — 响应体dsBIGINT — 分区字段
internal_platform_db.t_sh_threat_intel_lab_breakingti_soc_endpoint_security_format_output_prod_prestosql_010(威胁情报IOC表)ioctypeSTRING — IOC类型iocSTRING — IOC值portSTRING — 端口producerSTRING — 生产者stampSTRING — 时间戳categorySTRING — 分类familySTRING — 家族apt_orgSTRING — APT组织weaponSTRING — 武器useforSTRING — 用途ttpsSTRING — TTPsconfidenceINT — 置信度contextSTRING — 上下文intelligence_investigationSTRING — 情报调查match_subdomainsINT — 匹配子域名bdeleteINT — 删除标记deleted_timeSTRING — 删除时间first_occur_timeSTRING — 首次出现时间last_occur_timeSTRING — 最后出现时间dsBIGINT — 分区字段
计算逻辑:
- 从API指标表提取: json_extract_scalar(request, '$.entity_value') AS ioc_value, 按ioc_value分组取MIN(timestamp) AS earliest_timestamp, 过滤ds=20260608
- 从IOC表过滤: ioctype='DOMAIN' AND bdelete=0, 过滤ds=20260608
- JOIN条件: ioc = ioc_value
- time_diff_days = GREATEST(0, (unix_timestamp(first_occur_time) - earliest_timestamp) / 86400.0)
输出要求:
- 目标表:
internal_platform_db.t_app_breaking_ti_mttd_metric_cand_prestosql_010 - 输出字段及顺序:
IOCSTRING,IOCTYPESTRING,PORTSTRING,first_occur_timeSTRING,earliest_timestampBIGINT,familySTRING,match_subdomainsINT,time_diff_daysDOUBLE,dsBIGINT - ds: 固定值 20260608
- 注意Presto中用json_extract_scalar代替get_json_object,用to_unixtime代替unix_timestamp(需配合FROM_UNIXTIME相关的转换)
- 如果目标表不存在,请先建表再写入数据
- 请使用Presto/Trino SQL语法,不要使用Hive/Spark SQL方言
环境与执行说明:
- Presto已启动,通过Hive catalog连接
- 执行SQL:
presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql - 写出result.sql后,必须自己执行验证它能成功运行并产出正确数据