Datasets:
Upload 7 files
Browse files- hf_dataset/README.md +94 -0
- hf_dataset/flinksql.jsonl +20 -0
- hf_dataset/hivesql.jsonl +0 -0
- hf_dataset/mysql.jsonl +0 -0
- hf_dataset/prestosql.jsonl +12 -0
- hf_dataset/pyspark.jsonl +0 -0
- hf_dataset/tasks.jsonl +0 -0
hf_dataset/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
- zh
|
| 6 |
+
tags:
|
| 7 |
+
- data-engineering
|
| 8 |
+
- benchmark
|
| 9 |
+
- agent
|
| 10 |
+
- sql
|
| 11 |
+
- text2sql
|
| 12 |
+
- pyspark
|
| 13 |
+
- flink
|
| 14 |
+
- llm-evaluation
|
| 15 |
+
size_categories:
|
| 16 |
+
- n<1K
|
| 17 |
+
task_categories:
|
| 18 |
+
- text-generation
|
| 19 |
+
configs:
|
| 20 |
+
- config_name: default
|
| 21 |
+
data_files:
|
| 22 |
+
- split: train
|
| 23 |
+
path: tasks.jsonl
|
| 24 |
+
- config_name: hivesql
|
| 25 |
+
data_files:
|
| 26 |
+
- split: train
|
| 27 |
+
path: hivesql.jsonl
|
| 28 |
+
- config_name: mysql
|
| 29 |
+
data_files:
|
| 30 |
+
- split: train
|
| 31 |
+
path: mysql.jsonl
|
| 32 |
+
- config_name: prestosql
|
| 33 |
+
data_files:
|
| 34 |
+
- split: train
|
| 35 |
+
path: prestosql.jsonl
|
| 36 |
+
- config_name: pyspark
|
| 37 |
+
data_files:
|
| 38 |
+
- split: train
|
| 39 |
+
path: pyspark.jsonl
|
| 40 |
+
- config_name: flinksql
|
| 41 |
+
data_files:
|
| 42 |
+
- split: train
|
| 43 |
+
path: flinksql.jsonl
|
| 44 |
+
---
|
| 45 |
+
|
| 46 |
+
# DataClawEval
|
| 47 |
+
|
| 48 |
+
An executable benchmark for end-to-end data-engineering agents in industrial environments.
|
| 49 |
+
|
| 50 |
+
100 production-grounded tasks across five execution engines: **PySpark, MySQL, HiveSQL,
|
| 51 |
+
PrestoSQL/Trino, and FlinkSQL** (batch + streaming), balanced between 50 English and 50
|
| 52 |
+
Chinese task prompts.
|
| 53 |
+
|
| 54 |
+
- Paper: [DataClawEval: A Benchmark for Data Engineering Agents in Real Industrial Harness](https://arxiv.org/abs/2607.28033)
|
| 55 |
+
- Code & full task assets (init scripts, graders, Docker harness): [GitHub](https://github.com/)
|
| 56 |
+
|
| 57 |
+
## Dataset Structure
|
| 58 |
+
|
| 59 |
+
Each row is one task:
|
| 60 |
+
|
| 61 |
+
| Column | Description |
|
| 62 |
+
|--------|-------------|
|
| 63 |
+
| `task_id` | Task directory name, e.g. `hivesql_001_en` |
|
| 64 |
+
| `id` | Canonical task id, e.g. `offline-compute_HiveSQL_hivesql_001` |
|
| 65 |
+
| `name` | Short task title |
|
| 66 |
+
| `workload` | `offline-compute` (batch) or `online-compute` (streaming) |
|
| 67 |
+
| `engine` | `HiveSQL` / `MySQL` / `PrestoSQL` / `PySpark` / `FlinkSQL` |
|
| 68 |
+
| `category` | `<workload>/<engine>` |
|
| 69 |
+
| `language` | `en` or `zh` |
|
| 70 |
+
| `modality` | Task modality, e.g. `pure-text` |
|
| 71 |
+
| `timeout_seconds` | Per-task execution time limit |
|
| 72 |
+
| `prompt` | Full natural-language task instruction (Markdown) |
|
| 73 |
+
| `ground_truth` | Reference implementation (SQL or PySpark) |
|
| 74 |
+
| `expected_csv` | Expected output table (batch tasks; empty for streaming) |
|
| 75 |
+
| `grade_spec_csv` | Grading rubric: dimensions, weights, and descriptions |
|
| 76 |
+
| `path` | Task directory path in the source repo |
|
| 77 |
+
|
| 78 |
+
## Configs
|
| 79 |
+
|
| 80 |
+
- `default` — all 100 tasks
|
| 81 |
+
- `hivesql` (28), `mysql` (20), `pyspark` (20), `flinksql` (20), `prestosql` (12) — per-engine subsets
|
| 82 |
+
|
| 83 |
+
## Loading
|
| 84 |
+
|
| 85 |
+
```python
|
| 86 |
+
from datasets import load_dataset
|
| 87 |
+
|
| 88 |
+
ds = load_dataset("<your-namespace>/dataclaweval", "default")
|
| 89 |
+
ds = load_dataset("<your-namespace>/dataclaweval", "flinksql")
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
## Citation
|
| 93 |
+
|
| 94 |
+
See `CITATION.cff` in the source repository.
|
hf_dataset/flinksql.jsonl
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{"task_id": "flinksql_001_en", "id": "online-compute_FlinkSQL_flinksql_001", "name": "Order Stream and Payment Stream Interval Join", "workload": "online-compute", "engine": "FlinkSQL", "category": "online-compute/FlinkSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 600, "prompt": "## Prompt\nI need you to write a Flink SQL that uses the built-in datagen connector to simulate an order stream and a payment stream, performing an Interval Join on `order_id`, and writing matched records directly to the console.\n\n**Business Background and Objective**: Simulate an order stream and a payment stream using two datagen built-in tables, each generating 100 million records. The `order_id` and `user_id` in the order stream range from 1 to 1,000,000, and the `order_id` in the payment stream also ranges from 1 to 1,000,000. Both tables use `LOCALTIMESTAMP` as the event time and set a 5-second watermark delay.\n\nPerform an Interval Join on the two tables using `order_id`, matching only records where the payment time falls within 5 minutes after the order time. Upon a successful match, output the original fields directly to the console table, including `order_id`, `user_id`, `pay_amount`, the order time, and the payment time.\n\n**Source Table Definitions**:\n- `orders_source` (order stream, datagen connector):\n - `order_id INT`: Order ID, randomly generated in the range 1–1,000,000\n - `user_id INT`: User ID, randomly generated in the range 1–1,000,000\n - `order_time`: Uses `LOCALTIMESTAMP` to generate event time, with a WATERMARK delay of 5 seconds\n - Generation rate: `rows-per-second = 1000`\n\n- `payments_source` (payment stream, datagen connector):\n - `order_id INT`: Order ID, randomly generated in the range 1–1,000,000\n - `pay_amount DOUBLE`: Payment amount, randomly generated in the range 1–100,000\n - `pay_time`: Uses `LOCALTIMESTAMP` to generate event time, with a WATERMARK delay of 5 seconds\n - Generation rate: `rows-per-second = 1000`\n\n**Output Table Definition**:\n- `console_output` (print connector):\n - `order_id INT`\n - `user_id INT`\n - `pay_amount DOUBLE`\n - `order_time TIMESTAMP(3)`\n - `pay_time TIMESTAMP(3)`\n\n**Join Logic**:\n- Join condition: `orders_source.order_id = payments_source.order_id`\n- Time window: `payments_source.pay_time BETWEEN orders_source.order_time AND orders_source.order_time + INTERVAL '5' MINUTE`\n- Note: When writing to the sink, you must handle the dual rowtime attribute conflict by applying `CAST(pay_time AS TIMESTAMP(3))` to downgrade `pay_time` to a plain timestamp.\n\n**Output Requirements**:\n- Use `INSERT INTO console_output` to output the matched results.\n- Output field order: `order_id`, `user_id`, `pay_amount`, `order_time`, `pay_time`", "ground_truth": "-- online_001: 订单流 + 支付流 Interval Join\n-- 每个源生成 1 亿条数据 @ 1000 rows/sec\n\n-- 1. 订单流 datagen 源表\nCREATE TABLE orders_source (\n order_id INT,\n user_id INT,\n order_time AS LOCALTIMESTAMP,\n WATERMARK FOR order_time AS order_time - INTERVAL '5' SECOND\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '1000',\n 'fields.order_id.kind' = 'random',\n 'fields.order_id.min' = '1',\n 'fields.order_id.max' = '1000000',\n 'fields.user_id.kind' = 'random',\n 'fields.user_id.min' = '1',\n 'fields.user_id.max' = '1000000'\n);\n\n-- 2. 支付流 datagen 源表\nCREATE TABLE payments_source (\n order_id INT,\n pay_amount DOUBLE,\n pay_time AS LOCALTIMESTAMP,\n WATERMARK FOR pay_time AS pay_time - INTERVAL '5' SECOND\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '1000',\n 'fields.order_id.kind' = 'random',\n 'fields.order_id.min' = '1',\n 'fields.order_id.max' = '1000000',\n 'fields.pay_amount.kind' = 'random',\n 'fields.pay_amount.min' = '1',\n 'fields.pay_amount.max' = '100000'\n);\n\n-- 3. Console 输出表\nCREATE TABLE console_output (\n order_id INT,\n user_id INT,\n pay_amount DOUBLE,\n order_time TIMESTAMP(3),\n pay_time TIMESTAMP(3)\n) WITH (\n 'connector' = 'print'\n);\n\n-- 4. Interval Join: 匹配支付时间在订单时间后 5 分钟内的记录\nINSERT INTO console_output\nSELECT\n o.order_id,\n o.user_id,\n p.pay_amount,\n o.order_time,\n CAST(p.pay_time AS TIMESTAMP(3)) AS pay_time\nFROM orders_source o\nJOIN payments_source p\n ON o.order_id = p.order_id\nWHERE\n p.pay_time BETWEEN o.order_time AND o.order_time + INTERVAL '5' MINUTE;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/online-compute/FlinkSQL/flinksql_001_en"}
|
| 2 |
+
{"task_id": "flinksql_002_en", "id": "online-compute_FlinkSQL_flinksql_002", "name": "Order-Payment Interval Join + Windowed Aggregation", "workload": "online-compute", "engine": "FlinkSQL", "category": "online-compute/FlinkSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 600, "prompt": "## Prompt\nI need you to write a Flink SQL that uses two datagen built-in tables to simulate an order stream and a payment stream, performs an Interval Join on `order_id`, and then aggregates the order count and total payment amount over a 10-minute tumbling window, outputting the results to the console.\n\n**Business Background and Objective**: Simulate an order stream and a payment stream using two datagen built-in tables, each generating 100 million records. The `order_id` and `user_id` in the order stream range from 1 to 1,000,000, and the `order_id` in the payment stream also ranges from 1 to 1,000,000. Both tables use `LOCALTIMESTAMP` as the event time and set a 5-second watermark delay.\n\nPerform an Interval Join on the two tables using `order_id`, matching only records where the payment time falls within 10 minutes before or after the order time. Then, aggregate the successfully matched records over a 10-minute tumbling window to compute the order count and total payment amount per window, and finally output the results to the console table.\n\n**Source Table Definitions**:\n- `orders_source` (order stream, datagen connector):\n - `order_id INT`: Order ID, randomly generated in the range 1–1,000,000\n - `user_id INT`: User ID, randomly generated in the range 1–1,000,000\n - `event_time`: Uses `LOCALTIMESTAMP` to generate event time, with a WATERMARK delay of 5 seconds\n - Generation rate: `rows-per-second = 1000`\n\n- `payments_source` (payment stream, datagen connector):\n - `order_id INT`: Order ID, randomly generated in the range 1–1,000,000\n - `pay_amount DOUBLE`: Payment amount, randomly generated in the range 1–100,000\n - `event_time`: Uses `LOCALTIMESTAMP` to generate event time, with a WATERMARK delay of 5 seconds\n - Generation rate: `rows-per-second = 1000`\n\n**Output Table Definition**:\n- `console_output` (print connector):\n - `window_start VARCHAR`: Window start time\n - `window_end VARCHAR`: Window end time\n - `order_count BIGINT`: Order count within the window\n - `total_pay_amount DOUBLE`: Total payment amount within the window\n\n**Join + Aggregation Logic**:\n- Interval Join condition: `orders_source.order_id = payments_source.order_id`\n- Time window: `payments_source.event_time BETWEEN orders_source.event_time - INTERVAL '10' MINUTE AND orders_source.event_time + INTERVAL '10' MINUTE`\n- Tumbling window: `TUMBLE` 10 minutes\n- Aggregation metrics: `COUNT(*) AS order_count`, `SUM(pay_amount) AS total_pay_amount`\n- Convert window times to `VARCHAR` for output\n\n**Output Requirements**:\n- Use `INSERT INTO console_output` to output the results.\n- Output field order: `window_start`, `window_end`, `order_count`, `total_pay_amount`", "ground_truth": "-- online_002: 订单支付 Interval Join + Tumble 窗口聚合\n-- 每个源生成 1 亿条数据 @ 1000 rows/sec\n\n-- 1. 订单流 datagen 源表\nCREATE TABLE orders_source (\n order_id INT,\n user_id INT,\n event_time AS LOCALTIMESTAMP,\n WATERMARK FOR event_time AS event_time - INTERVAL '5' SECOND\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '1000',\n 'fields.order_id.kind' = 'random',\n 'fields.order_id.min' = '1',\n 'fields.order_id.max' = '1000000',\n 'fields.user_id.kind' = 'random',\n 'fields.user_id.min' = '1',\n 'fields.user_id.max' = '1000000'\n);\n\n-- 2. 支付流 datagen 源表\nCREATE TABLE payments_source (\n order_id INT,\n pay_amount DOUBLE,\n event_time AS LOCALTIMESTAMP,\n WATERMARK FOR event_time AS event_time - INTERVAL '5' SECOND\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '1000',\n 'fields.order_id.kind' = 'random',\n 'fields.order_id.min' = '1',\n 'fields.order_id.max' = '1000000',\n 'fields.pay_amount.kind' = 'random',\n 'fields.pay_amount.min' = '1',\n 'fields.pay_amount.max' = '100000'\n);\n\n-- 3. Console 输出表\nCREATE TABLE console_output (\n window_start VARCHAR,\n window_end VARCHAR,\n order_count BIGINT,\n total_pay_amount DOUBLE\n) WITH (\n 'connector' = 'print'\n);\n\n-- 4. Interval Join + Tumble 10min 窗口聚合\nINSERT INTO console_output\nSELECT\n CAST(TUMBLE_START(o.event_time, INTERVAL '10' MINUTE) AS VARCHAR) AS window_start,\n CAST(TUMBLE_END(o.event_time, INTERVAL '10' MINUTE) AS VARCHAR) AS window_end,\n COUNT(*) AS order_count,\n SUM(p.pay_amount) AS total_pay_amount\nFROM orders_source o\nJOIN payments_source p\n ON o.order_id = p.order_id\n AND p.event_time BETWEEN o.event_time - INTERVAL '10' MINUTE\n AND o.event_time + INTERVAL '10' MINUTE\nGROUP BY TUMBLE(o.event_time, INTERVAL '10' MINUTE);", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/online-compute/FlinkSQL/flinksql_002_en"}
|
| 3 |
+
{"task_id": "flinksql_003_en", "id": "online-compute_FlinkSQL_flinksql_003", "name": "Word Frequency Tumbling Window Statistics", "workload": "online-compute", "engine": "FlinkSQL", "category": "online-compute/FlinkSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 600, "prompt": "## Prompt\nI need you to write a Flink SQL that uses a datagen built-in table to simulate a word frequency data stream, groups by `word` and opens a 1-minute tumbling window to count the occurrences of each word, and outputs the results to the console.\n\n**Business Background and Objective**: Simulate a word frequency data stream using a datagen built-in table, generating 1 billion records in the `word` field. Use `LOCALTIMESTAMP` as the event time and set a 5-second watermark delay. Group by `word` and count the occurrences of each word over a 1-minute tumbling window, then output `word` and `cnt` to the console table.\n\n**Source Table Definition**:\n- `word_source` (word frequency stream, datagen connector):\n - `word VARCHAR`: Word, randomly generated (value range 1–1000 to simulate distinct words)\n - `event_time`: Uses `LOCALTIMESTAMP` to generate event time, with a WATERMARK delay of 5 seconds\n - Generation rate: `rows-per-second = 1000`\n\n**Output Table Definition**:\n- `console_output` (print connector):\n - `word VARCHAR`: Word\n - `cnt BIGINT`: Number of occurrences of the word within the current window\n\n**Aggregation Logic**:\n- Group by `word`, using a 1-minute tumbling window\n- Aggregation metric: `COUNT(*) AS cnt`\n- The window is defined by the `TUMBLE` function\n\n**Output Requirements**:\n- Use `INSERT INTO console_output` to output the results.\n- Output field order: `word`, `cnt`", "ground_truth": "-- online_003: 词频滚动窗口统计\n-- 单源生成 10 亿条数据 @ 1000 rows/sec\n\n-- 1. 词频流 datagen 源表\nCREATE TABLE word_source (\n word VARCHAR,\n event_time AS LOCALTIMESTAMP,\n WATERMARK FOR event_time AS event_time - INTERVAL '5' SECOND\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '1000',\n 'fields.word.kind' = 'random',\n 'fields.word.length' = '5'\n);\n\n-- 2. Console 输出表\nCREATE TABLE console_output (\n word VARCHAR,\n cnt BIGINT\n) WITH (\n 'connector' = 'print'\n);\n\n-- 3. Tumble 1min 窗口词频统计\nINSERT INTO console_output\nSELECT\n word,\n COUNT(*) AS cnt\nFROM word_source\nGROUP BY TUMBLE(event_time, INTERVAL '1' MINUTE), word;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/online-compute/FlinkSQL/flinksql_003_en"}
|
| 4 |
+
{"task_id": "flinksql_004_en", "id": "online-compute_FlinkSQL_flinksql_004", "name": "Dual Window Aggregation (Tumble + Hop)", "workload": "online-compute", "engine": "FlinkSQL", "category": "online-compute/FlinkSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 600, "prompt": "## Prompt\nI need you to write a Flink SQL that uses a datagen built-in table to generate order events, and computes the sales volume and order count per product using both a tumbling window and a sliding window, outputting the results to two separate console tables.\n\n**Business Background and Objective**: Generate order events (`order_id BIGINT`, `product_id INT`, `quantity INT`) using a datagen built-in table. Use `LOCALTIMESTAMP` as the event time and set a 5-second watermark delay.\n\nCompute statistics using two window types:\n1. **1-minute tumbling window**: Compute the sales volume `SUM(quantity) AS sales` and order count `COUNT(*) AS order_cnt` per product.\n2. **Sliding window** (slides every 30 seconds, covering the past 1 minute): Compute the sales volume `SUM(quantity) AS sales` and order count `COUNT(*) AS order_cnt` per product.\n\nPrint the results of both window types to two separate console tables, with each record carrying a window type identifier `window_type`.\n\n**Source Table Definition**:\n- `orders_source` (order event stream, datagen connector):\n - `order_id BIGINT`: Order ID, randomly generated in the range 1–1,000,000\n - `product_id INT`: Product ID, randomly generated in the range 1–10,000\n - `quantity INT`: Quantity, randomly generated in the range 1–10\n - `event_time`: Uses `LOCALTIMESTAMP` to generate event time, with a WATERMARK delay of 5 seconds\n - Generation rate: `rows-per-second = 50`\n\n**Output Table Definitions**:\n- `console_tumble` (print connector, tumbling window results):\n - `window_type STRING`: Window type identifier, fixed as `'TUMBLE'`\n - `window_start TIMESTAMP(3)`: Window start time\n - `window_end TIMESTAMP(3)`: Window end time\n - `product_id INT`: Product ID\n - `sales INT`: Sales volume of the product within the window\n - `order_cnt BIGINT`: Order count of the product within the window\n\n- `console_hop` (print connector, sliding window results):\n - `window_type STRING`: Window type identifier, fixed as `'HOP'`\n - `window_start TIMESTAMP(3)`: Window start time\n - `window_end TIMESTAMP(3)`: Window end time\n - `product_id INT`: Product ID\n - `sales INT`: Sales volume of the product within the window\n - `order_cnt BIGINT`: Order count of the product within the window\n\n**Aggregation Logic**:\n- Tumbling window: `GROUP BY TUMBLE(event_time, INTERVAL '1' MINUTE), product_id`\n- Sliding window: `GROUP BY HOP(event_time, INTERVAL '30' SECOND, INTERVAL '1' MINUTE), product_id`\n- Aggregation metrics: `SUM(quantity) AS sales`, `COUNT(*) AS order_cnt`\n- Both window times and the window type must be explicitly output\n\n**Output Requirements**:\n- Use two `INSERT INTO` statements to output to `console_tumble` and `console_hop` respectively.\n- Output field order: `window_type`, `window_start`, `window_end`, `product_id`, `sales`, `order_cnt`", "ground_truth": "-- online_004: 双窗口聚合 (Tumble + Hop)\n-- 单源生成 @ 50 rows/sec\n\n-- 1. 订单事件 datagen 源表\nCREATE TABLE orders_source (\n order_id BIGINT,\n product_id INT,\n quantity INT,\n event_time AS LOCALTIMESTAMP,\n WATERMARK FOR event_time AS event_time - INTERVAL '5' SECOND\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '50',\n 'fields.order_id.kind' = 'random',\n 'fields.order_id.min' = '1',\n 'fields.order_id.max' = '1000000',\n 'fields.product_id.kind' = 'random',\n 'fields.product_id.min' = '1',\n 'fields.product_id.max' = '10000',\n 'fields.quantity.kind' = 'random',\n 'fields.quantity.min' = '1',\n 'fields.quantity.max' = '10'\n);\n\n-- 2. Console 输出表 (Tumble 滚动窗口)\nCREATE TABLE console_tumble (\n window_type STRING,\n window_start TIMESTAMP(3),\n window_end TIMESTAMP(3),\n product_id INT,\n sales INT,\n order_cnt BIGINT\n) WITH (\n 'connector' = 'print'\n);\n\n-- 3. Console 输出表 (Hop 滑动窗口)\nCREATE TABLE console_hop (\n window_type STRING,\n window_start TIMESTAMP(3),\n window_end TIMESTAMP(3),\n product_id INT,\n sales INT,\n order_cnt BIGINT\n) WITH (\n 'connector' = 'print'\n);\n\n-- 4a. Tumble 1min 滚动窗口:SUM 销量 + COUNT 订单数\nINSERT INTO console_tumble\nSELECT\n 'TUMBLE' AS window_type,\n TUMBLE_START(event_time, INTERVAL '1' MINUTE) AS window_start,\n TUMBLE_END(event_time, INTERVAL '1' MINUTE) AS window_end,\n product_id,\n CAST(SUM(quantity) AS INT) AS sales,\n COUNT(*) AS order_cnt\nFROM orders_source\nGROUP BY TUMBLE(event_time, INTERVAL '1' MINUTE), product_id;\n\n-- 4b. Hop 滑动窗口 (30s slide, 1min size):SUM 销量 + COUNT 订单数\nINSERT INTO console_hop\nSELECT\n 'HOP' AS window_type,\n HOP_START(event_time, INTERVAL '30' SECOND, INTERVAL '1' MINUTE) AS window_start,\n HOP_END(event_time, INTERVAL '30' SECOND, INTERVAL '1' MINUTE) AS window_end,\n product_id,\n CAST(SUM(quantity) AS INT) AS sales,\n COUNT(*) AS order_cnt\nFROM orders_source\nGROUP BY HOP(event_time, INTERVAL '30' SECOND, INTERVAL '1' MINUTE), product_id;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/online-compute/FlinkSQL/flinksql_004_en"}
|
| 5 |
+
{"task_id": "flinksql_005", "id": "online-compute_FlinkSQL_flinksql_005", "name": "滚动窗口 TopN 商品排行", "workload": "online-compute", "engine": "FlinkSQL", "category": "online-compute/FlinkSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 600, "prompt": "## Prompt\n我需要你写一段 Flink SQL,用 datagen 内置表模拟电商订单,按 10 秒滚动窗口做 Top-N 商品排行,输出销售额最高的前 3 个商品到 console。\n\n**业务背景与目标**:用 datagen 内置表生成电商订单(字段 order_id / product_id / amount),每秒生成约 10 条。以 LOCALTIMESTAMP 作为事件时间,设置 5 秒的 Watermark 延迟。\n\n按 10 秒滚动窗口做 Top-N 排行:每个窗口内统计每个商品的销售额 SUM(amount) 和订单数 COUNT(*),按销售额降序取前三名,打印到 console。\n\n**源表定义**:\n- `orders_source`(订单流,datagen 连接器):\n - order_id BIGINT:订单 ID,随机取值 1~1000000\n - product_id INT:商品 ID,随机取值 1~1000\n - amount DOUBLE:订单金额,随机取值 1~10000\n - event_time:使用 LOCALTIMESTAMP 生成事件时间,设置 WATERMARK 延迟 5 秒\n - 生成速率:rows-per-second = 10\n\n**输出表定义**:\n- `console_output`(print 连接器):\n - window_start TIMESTAMP(3):窗口起始时间\n - product_id INT:商品 ID\n - sales DOUBLE:该窗口内销售额\n - order_cnt BIGINT:该窗口内订单数\n - rn BIGINT:排名序号\n\n**TopN 逻辑**:\n- 使用 10 秒滚动窗口聚合:SUM(amount) AS sales, COUNT(*) AS order_cnt\n- 在窗口内使用 ROW_NUMBER() 按销售额降序排名\n- 只输出排名前 3 的记录(rn <= 3)\n\n**输出要求**:\n- 使用 INSERT INTO console_output 将 Top 3 结果输出\n- 输出字段顺序:window_start, product_id, sales, order_cnt, rn", "ground_truth": "-- online_005: 滚动窗口 TopN 商品排行\n-- 单源生成 @ 10 rows/sec, Tumble 10s + ROW_NUMBER Top3\n\n-- 1. 订单流 datagen 源表\nCREATE TABLE orders_source (\n order_id BIGINT,\n product_id INT,\n amount DOUBLE,\n event_time AS LOCALTIMESTAMP,\n WATERMARK FOR event_time AS event_time - INTERVAL '5' SECOND\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '10',\n 'fields.order_id.kind' = 'random',\n 'fields.order_id.min' = '1',\n 'fields.order_id.max' = '1000000',\n 'fields.product_id.kind' = 'random',\n 'fields.product_id.min' = '1',\n 'fields.product_id.max' = '1000',\n 'fields.amount.kind' = 'random',\n 'fields.amount.min' = '1',\n 'fields.amount.max' = '10000'\n);\n\n-- 2. Console 输出表\nCREATE TABLE console_output (\n window_start TIMESTAMP(3),\n product_id INT,\n sales DOUBLE,\n order_cnt BIGINT,\n rn BIGINT\n) WITH (\n 'connector' = 'print'\n);\n\n-- 3. Tumble 10s 窗口聚合 + ROW_NUMBER Top 3\nINSERT INTO console_output\nSELECT\n window_start,\n product_id,\n sales,\n order_cnt,\n rn\nFROM (\n SELECT\n TUMBLE_START(event_time, INTERVAL '10' SECOND) AS window_start,\n product_id,\n SUM(amount) AS sales,\n COUNT(*) AS order_cnt,\n ROW_NUMBER() OVER (\n PARTITION BY TUMBLE_START(event_time, INTERVAL '10' SECOND)\n ORDER BY SUM(amount) DESC\n ) AS rn\n FROM orders_source\n GROUP BY TUMBLE(event_time, INTERVAL '10' SECOND), product_id\n)\nWHERE rn <= 3;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/online-compute/FlinkSQL/flinksql_005"}
|
| 6 |
+
{"task_id": "flinksql_006", "id": "online-compute_FlinkSQL_flinksql_006", "name": "异常事件过滤 + 窗口 TopN", "workload": "online-compute", "engine": "FlinkSQL", "category": "online-compute/FlinkSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 600, "prompt": "## Prompt\n我需要你写一段 Flink SQL,用 datagen 内置表造设备事件流,过滤出异常事件后按省份做窗口 TopN 排名,输出到 console。\n\n**业务背景与目标**:用内置 datagen 表生成设备事件数据,字段包括 device_id(int)、event_type(int)、province(string)、ts(timestamp),每秒 80 条,event_type 取值 1-10,province 长度 4 字符,用 ts 字段作为事件时间开 1 分钟滚动窗口(watermark 延迟 5 秒),先过滤 event_type=3 的异常事件,然后按省份分组统计每分钟的异常事件数,按异常数降序排名取 Top-5,输出字段包括窗口开始时间、省份、异常事件数、排名,打印到 console。\n\n**源表定义**:\n- `device_source`(设备事件流,datagen 连接器):\n - device_id INT:设备 ID,随机生成\n - event_type INT:事件类型,随机取值 1~10\n - province VARCHAR:省份,随机生成,长度 4 字符\n - event_time:使用 LOCALTIMESTAMP 生成事件时间,设置 WATERMARK 延迟 5 秒\n - 生成速率:rows-per-second = 80\n\n**输出表定义**:\n- `console_output`(print 连接器):\n - window_start TIMESTAMP:窗口开始时间\n - province VARCHAR:省份\n - abnormal_cnt BIGINT:异常事件数\n - `rank` BIGINT:排名(注意 rank 是关键字,需要用反引号包裹)\n\n**查询逻辑**:\n- 过滤:WHERE event_type = 3(异常事件)\n- 窗口:TUMBLE(event_time, INTERVAL '1' MINUTE) 滚动窗口\n- 聚合:按 province 和窗口分组,COUNT(*) 统计异常事件数\n- 排名:ROW_NUMBER() OVER (PARTITION BY window_start ORDER BY abnormal_cnt DESC) AS `rank`\n- Top-N:WHERE `rank` <= 5\n\n**输出要求**:\n- 使用 INSERT INTO console_output 输出结果\n- 输出字段顺序:window_start, province, abnormal_cnt, `rank`", "ground_truth": "-- flinksql_006: 异常事件过滤 + 窗口 TopN\n-- datagen 生成设备事件流 @ 80 rows/sec, event_type=3 过滤后 Tumble 1min Top-5\n\n-- 1. 设备事件流 datagen 源表\nCREATE TABLE device_source (\n device_id INT,\n event_type INT,\n province VARCHAR,\n event_time AS LOCALTIMESTAMP,\n WATERMARK FOR event_time AS event_time - INTERVAL '5' SECOND\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '80',\n 'fields.event_type.kind' = 'random',\n 'fields.event_type.min' = '1',\n 'fields.event_type.max' = '10',\n 'fields.province.kind' = 'random',\n 'fields.province.length' = '4'\n);\n\n-- 2. Console 输出表\nCREATE TABLE console_output (\n window_start TIMESTAMP,\n province VARCHAR,\n abnormal_cnt BIGINT,\n `rank` BIGINT\n) WITH (\n 'connector' = 'print'\n);\n\n-- 3. 过滤异常事件(event_type=3) → Tumble 窗口 → Top-5\nINSERT INTO console_output\nSELECT\n window_start,\n province,\n abnormal_cnt,\n `rank`\nFROM (\n SELECT\n TUMBLE_START(event_time, INTERVAL '1' MINUTE) AS window_start,\n province,\n COUNT(*) AS abnormal_cnt,\n ROW_NUMBER() OVER (PARTITION BY TUMBLE_START(event_time, INTERVAL '1' MINUTE) ORDER BY COUNT(*) DESC) AS `rank`\n FROM device_source\n WHERE event_type = 3\n GROUP BY TUMBLE(event_time, INTERVAL '1' MINUTE), province\n)\nWHERE `rank` <= 5;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/online-compute/FlinkSQL/flinksql_006"}
|
| 7 |
+
{"task_id": "flinksql_007", "id": "online-compute_FlinkSQL_flinksql_007", "name": "用户行为滚动窗口统计", "workload": "online-compute", "engine": "FlinkSQL", "category": "online-compute/FlinkSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 600, "prompt": "## Prompt\n我需要你写一段 Flink SQL,用 datagen 内置表造用户行为流,开滚动窗口统计每个用户的 action 数,结果写到 console。\n\n**业务背景与目标**:用 datagen 内置数据源表模拟用户行为数据流��每秒生成 50 条记录,包含三个字段:userId(用户ID,字符串,长度6)、action(动作类型,字符串,长度8)、ftime(事件时间,timestamp 类型)。请基于这个 datagen 表,按事件时间做 1 分钟滚动窗口聚合,统计每个用户在每个 1 分钟窗口内的 action 总次数,并把结果(用户ID、动作次数、窗口起始时间)写入到内置控制台表中输出。事件时间字段 ftime 使用 LOCALTIMESTAMP 作为 computed column 并设置 watermark 延迟 5 秒。\n\n**源表定义**:\n- `user_source`(用户行为流,datagen 连接器):\n - userId VARCHAR:用户 ID,随机生成,长度 6 字符\n - action VARCHAR:动作类型,随机生成,长度 8 字符\n - ftime:使用 LOCALTIMESTAMP 生成事件时间,设置 WATERMARK 延迟 5 秒\n - 生成速率:rows-per-second = 50\n\n**输出表定义**:\n- `console_output`(print 连接器):\n - user_id VARCHAR:用户 ID\n - action_count BIGINT:动作次数\n - window_start TIMESTAMP:窗口起始时间\n\n**查询逻辑**:\n- 窗口:TUMBLE(ftime, INTERVAL '1' MINUTE) 滚动窗口\n- 聚合:按 userId 分组,COUNT(*) 统计 action 总次数\n- 输出:窗口起始时间 + 用户 ID + 动作次数\n\n**输出要求**:\n- 使用 INSERT INTO console_output 输出结果\n- 输出字段顺序:user_id, action_count, window_start", "ground_truth": "-- flinksql_007: 用户行为滚动窗口统计\n-- datagen 生成用户行为流 @ 50 rows/sec, Tumble 1min 窗口聚合\n\n-- 1. 用户行为流 datagen 源表\nCREATE TABLE user_source (\n userId VARCHAR,\n action VARCHAR,\n ftime AS LOCALTIMESTAMP,\n WATERMARK FOR ftime AS ftime - INTERVAL '5' SECOND\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '50',\n 'fields.userId.length' = '6',\n 'fields.action.length' = '8'\n);\n\n-- 2. Console 输出表\nCREATE TABLE console_output (\n user_id VARCHAR,\n action_count BIGINT,\n window_start TIMESTAMP\n) WITH (\n 'connector' = 'print'\n);\n\n-- 3. Tumble 1min 窗口聚合: 统计每个用户每分钟的 action 次数\nINSERT INTO console_output\nSELECT\n userId AS user_id,\n COUNT(*) AS action_count,\n TUMBLE_START(ftime, INTERVAL '1' MINUTE) AS window_start\nFROM user_source\nGROUP BY TUMBLE(ftime, INTERVAL '1' MINUTE), userId;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/online-compute/FlinkSQL/flinksql_007"}
|
| 8 |
+
{"task_id": "flinksql_008_en", "id": "online-compute_FlinkSQL_flinksql_008", "name": "Session Window User Behavior Aggregation", "workload": "online-compute", "engine": "FlinkSQL", "category": "online-compute/FlinkSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 600, "prompt": "## Prompt\nI need you to write a Flink SQL that uses a datagen built-in table to simulate a user behavior stream, performs session window aggregation to compute behavioral metrics per user within each session, and outputs the results to the console.\n\n**Business Background and Objective**: Simulate a user behavior data stream using a datagen built-in table that generates 50 records per second, containing four fields: `userId` (user ID, string of length 6), `action` (action type, string of length 8), `action_time` (action occurrence time, timestamp), and `ftime` (event time, timestamp). Based on this datagen table, using `ftime` as the event time (with a 5-second watermark delay), perform a 30-minute session window (`SESSION`) aggregation grouped by `userId`. Compute the following metrics for each user within each session window: session start time, session end time, total action count, number of distinct action types, and the last action time (the maximum value of `action_time`). Output the results to a built-in console table.\n\n**Source Table Definition**:\n- `user_source` (user behavior stream, datagen connector):\n - `userId VARCHAR`: User ID, randomly generated, 6 characters in length\n - `action VARCHAR`: Action type, randomly generated, 8 characters in length\n - `action_time TIMESTAMP(3)`: Action occurrence time\n - `ftime`: Uses `LOCALTIMESTAMP` to generate event time, with a WATERMARK delay of 5 seconds\n - Generation rate: `rows-per-second = 50`\n\n**Output Table Definition**:\n- `console_output` (print connector):\n - `user_id VARCHAR`: User ID\n - `session_start TIMESTAMP`: Session start time\n - `session_end TIMESTAMP`: Session end time\n - `action_count BIGINT`: Total action count\n - `unique_actions BIGINT`: Number of distinct action types\n - `last_action_time TIMESTAMP`: Last action time\n\n**Query Logic**:\n- Window: `SESSION(ftime, INTERVAL '30' MINUTE)` session window\n- Grouping: Group by `userId` and the session window\n- Aggregation: `COUNT(*)` for total action count, `COUNT(DISTINCT action)` for distinct action type count, `MAX(action_time)` for last action time\n- Window functions: Use `SESSION_START` / `SESSION_END` to obtain the window start and end times\n\n**Output Requirements**:\n- Use `INSERT INTO console_output` to output the results.\n- Output field order: `user_id`, `session_start`, `session_end`, `action_count`, `unique_actions`, `last_action_time`", "ground_truth": "-- flinksql_008: 会话窗口用户行为聚合\n-- datagen 生成用户行为流 @ 50 rows/sec, SESSION 30min 窗口聚合\n\n-- 1. 用户行为流 datagen 源表\nCREATE TABLE user_source (\n userId VARCHAR,\n action VARCHAR,\n action_time TIMESTAMP(3),\n ftime AS LOCALTIMESTAMP,\n WATERMARK FOR ftime AS ftime - INTERVAL '5' SECOND\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '50',\n 'fields.userId.length' = '6',\n 'fields.action.length' = '8'\n);\n\n-- 2. Console 输出表\nCREATE TABLE console_output (\n user_id VARCHAR,\n session_start TIMESTAMP,\n session_end TIMESTAMP,\n action_count BIGINT,\n unique_actions BIGINT,\n last_action_time TIMESTAMP\n) WITH (\n 'connector' = 'print'\n);\n\n-- 3. SESSION 30min 窗口聚合: 统计每个用户每段会话的行为指标\nINSERT INTO console_output\nSELECT\n userId AS user_id,\n SESSION_START(ftime, INTERVAL '30' MINUTE) AS session_start,\n SESSION_END(ftime, INTERVAL '30' MINUTE) AS session_end,\n COUNT(*) AS action_count,\n COUNT(DISTINCT action) AS unique_actions,\n MAX(action_time) AS last_action_time\nFROM user_source\nGROUP BY SESSION(ftime, INTERVAL '30' MINUTE), userId;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/online-compute/FlinkSQL/flinksql_008_en"}
|
| 9 |
+
{"task_id": "flinksql_009_en", "id": "online-compute_FlinkSQL_flinksql_009", "name": "Tumbling Window PV/UV Statistics", "workload": "online-compute", "engine": "FlinkSQL", "category": "online-compute/FlinkSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 600, "prompt": "## Prompt\nI need you to write a Flink SQL that uses a datagen built-in table to simulate a user click stream, computes PV and UV per page over a window, and writes the results to the console.\n\n**Business Background and Objective**: Simulate a user click stream using a datagen built-in table (`user_id` ranging from 1–1000, `page_id` ranging from 1–50, 10,000 records per second). Compute the PV (`COUNT(*)`) and UV (`COUNT(DISTINCT user_id)`) per page over a 1-minute tumbling window. Output the results (window start, window end, `page_id`, `pv`, `uv`) to the console.\n\n**Source Table Definition**:\n- `click_source` (user click stream, datagen connector):\n - `user_id INT`: User ID, randomly generated in the range 1–1000\n - `page_id INT`: Page ID, randomly generated in the range 1–50\n - `event_time`: Uses `LOCALTIMESTAMP` to generate event time, with a WATERMARK delay of 5 seconds\n - Generation rate: `rows-per-second = 10000`\n\n**Output Table Definition**:\n- `console_output` (print connector):\n - `window_start TIMESTAMP`: Window start time\n - `window_end TIMESTAMP`: Window end time\n - `page_id INT`: Page ID\n - `pv BIGINT`: Page views (PV)\n - `uv BIGINT`: Unique visitors (UV)\n\n**Query Logic**:\n- Window: `TUMBLE(event_time, INTERVAL '1' MINUTE)` tumbling window\n- Grouping: Group by `page_id` and the window\n- PV: `COUNT(*)` to compute page views\n- UV: `COUNT(DISTINCT user_id)` to compute unique visitors\n- Window functions: Use `TUMBLE_START` / `TUMBLE_END` to obtain the window start and end times\n\n**Output Requirements**:\n- Use `INSERT INTO console_output` to output the results.\n- Output field order: `window_start`, `window_end`, `page_id`, `pv`, `uv`", "ground_truth": "-- flinksql_009: 滚动窗口 PV/UV 统计\n-- datagen 生成用户点击流 @ 10000 rows/sec, Tumble 1min PV/UV\n\n-- 1. 用户点击流 datagen 源表\nCREATE TABLE click_source (\n user_id INT,\n page_id INT,\n event_time AS LOCALTIMESTAMP,\n WATERMARK FOR event_time AS event_time - INTERVAL '5' SECOND\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '10000',\n 'fields.user_id.kind' = 'random',\n 'fields.user_id.min' = '1',\n 'fields.user_id.max' = '1000',\n 'fields.page_id.kind' = 'random',\n 'fields.page_id.min' = '1',\n 'fields.page_id.max' = '50'\n);\n\n-- 2. Console 输出表\nCREATE TABLE console_output (\n window_start TIMESTAMP,\n window_end TIMESTAMP,\n page_id INT,\n pv BIGINT,\n uv BIGINT\n) WITH (\n 'connector' = 'print'\n);\n\n-- 3. Tumble 1min 窗口聚合: 按页面统计 PV 和 UV\nINSERT INTO console_output\nSELECT\n TUMBLE_START(event_time, INTERVAL '1' MINUTE) AS window_start,\n TUMBLE_END(event_time, INTERVAL '1' MINUTE) AS window_end,\n page_id,\n COUNT(*) AS pv,\n COUNT(DISTINCT user_id) AS uv\nFROM click_source\nGROUP BY TUMBLE(event_time, INTERVAL '1' MINUTE), page_id;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/online-compute/FlinkSQL/flinksql_009_en"}
|
| 10 |
+
{"task_id": "flinksql_010", "id": "online-compute_FlinkSQL_flinksql_010", "name": "滑动窗口(HOP)店铺统计", "workload": "online-compute", "engine": "FlinkSQL", "category": "online-compute/FlinkSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 600, "prompt": "## Prompt\n我需要你写一段 Flink SQL,用 datagen 模拟订单流,��店铺做滑动窗口统计订单金额和数量,写入 console。\n\n**业务背景与目标**:用 datagen 模拟订单流(order_id 取值 1~1000000、shop_id 取值 1~100、amount 取值 0~1000,每秒 5000 条),按 1 分钟步长、5 分钟窗口大小做 HOP 滑动窗口统计每个店铺的订单总额(SUM)、订单数(COUNT)和平均金额(AVG),写入 console。\n\n**源表定义**:\n- `order_source`(订单流,datagen 连接器):\n - order_id BIGINT:订单 ID,随机取值 1~1000000\n - shop_id INT:店铺 ID,随机取值 1~100\n - amount DOUBLE:订单金额,随机取值 0~1000\n - event_time:使用 LOCALTIMESTAMP 生成事件时间,设置 WATERMARK 延迟 10 秒\n - 生成速率:rows-per-second = 5000\n\n**输出表定义**:\n- `console_output`(print 连接器):\n - window_start TIMESTAMP:窗口开始时间\n - window_end TIMESTAMP:窗口结束时间\n - shop_id INT:店铺 ID\n - total_amount DOUBLE:订单总额\n - order_cnt BIGINT:订单数量\n - avg_amount DOUBLE:平均订单金额\n\n**查询逻辑**:\n- 窗口:HOP(event_time, INTERVAL '1' MINUTE, INTERVAL '5' MINUTE) 滑动窗口\n - 步长(slide):1 分钟\n - 窗口大小(size):5 分钟\n- 分组:按 shop_id 和窗口分组\n- 聚合:SUM(amount) 订单总额,COUNT(*) 订单数,AVG(amount) 平均金额\n- 窗口函数:HOP_START / HOP_END 获取窗口起止时间\n\n**输出要求**:\n- 使用 INSERT INTO console_output 输出结果\n- 输出字段顺序:window_start, window_end, shop_id, total_amount, order_cnt, avg_amount", "ground_truth": "-- flinksql_010: 滑动窗口(HOP)店铺统计\n-- datagen 生成订单流 @ 5000 rows/sec, HOP 1min slide 5min window\n\n-- 1. 订单流 datagen 源表\nCREATE TABLE order_source (\n order_id BIGINT,\n shop_id INT,\n amount DOUBLE,\n event_time AS LOCALTIMESTAMP,\n WATERMARK FOR event_time AS event_time - INTERVAL '10' SECOND\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '5000',\n 'fields.order_id.kind' = 'random',\n 'fields.order_id.min' = '1',\n 'fields.order_id.max' = '1000000',\n 'fields.shop_id.kind' = 'random',\n 'fields.shop_id.min' = '1',\n 'fields.shop_id.max' = '100',\n 'fields.amount.kind' = 'random',\n 'fields.amount.min' = '0',\n 'fields.amount.max' = '1000'\n);\n\n-- 2. Console 输出表\nCREATE TABLE console_output (\n window_start TIMESTAMP,\n window_end TIMESTAMP,\n shop_id INT,\n total_amount DOUBLE,\n order_cnt BIGINT,\n avg_amount DOUBLE\n) WITH (\n 'connector' = 'print'\n);\n\n-- 3. HOP 滑动窗口聚合: 按店铺统计订单总额、数量和平均金额\nINSERT INTO console_output\nSELECT\n HOP_START(event_time, INTERVAL '1' MINUTE, INTERVAL '5' MINUTE) AS window_start,\n HOP_END(event_time, INTERVAL '1' MINUTE, INTERVAL '5' MINUTE) AS window_end,\n shop_id,\n SUM(amount) AS total_amount,\n COUNT(*) AS order_cnt,\n AVG(amount) AS avg_amount\nFROM order_source\nGROUP BY HOP(event_time, INTERVAL '1' MINUTE, INTERVAL '5' MINUTE), shop_id;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/online-compute/FlinkSQL/flinksql_010"}
|
| 11 |
+
{"task_id": "flinksql_011_en", "id": "online-compute_FlinkSQL_flinksql_011", "name": "Tumbling Window Product TopN Ranking", "workload": "online-compute", "engine": "FlinkSQL", "category": "online-compute/FlinkSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 600, "prompt": "## Prompt\nI need you to write a Flink SQL that uses the built-in datagen connector to simulate an order data source, aggregates product sales over a 10-minute tumbling window, and then uses the `ROW_NUMBER` window function to retrieve the top 5 products by sales within each window, outputting the results to the console.\n\n**Business Background and Objective**: Simulate an order stream using a datagen built-in table, generating massive order data. Group by a 10-minute tumbling window to compute the total sales amount and order count per product within each window, and finally use `ROW_NUMBER` ranking to retrieve the top 5 products by sales amount within each window.\n\n**Source Table Definition**:\n- `order_source` (order stream, datagen connector):\n - `order_id BIGINT`: Order ID, randomly generated in the range 1–10,000,000\n - `product_id INT`: Product ID, randomly generated in the range 1–200\n - `amount DOUBLE`: Order amount, randomly generated in the range 0–500\n - `event_time`: Uses `LOCALTIMESTAMP` to generate event time, with a WATERMARK delay of 5 seconds\n - Generation rate: `rows-per-second = 8000`\n\n**Output Table Definition**:\n- `console_output` (print connector):\n - `window_start TIMESTAMP(3)`: Tumbling window start time\n - `product_id INT`: Product ID\n - `sales DOUBLE`: Total sales amount of the product within the window\n - `order_cnt BIGINT`: Number of orders for the product within the window\n - `rn BIGINT`: Sales ranking within the window\n\n**SQL Logic**:\n- Apply `TUMBLE(event_time, INTERVAL '10' MINUTE)` tumbling window on `order_source`\n- Group by `window_start`, `window_end`, `product_id`\n- Aggregate `SUM(amount) AS sales` and `COUNT(*) AS order_cnt`\n- Use `ROW_NUMBER() OVER (PARTITION BY window_start, window_end ORDER BY sales DESC) AS rn`\n- Outer query filter: `WHERE rn <= 5`\n- Final SELECT: `window_start`, `product_id`, `sales`, `order_cnt`, `rn`\n\n**Output Requirements**:\n- Use `INSERT INTO console_output` to output the results.\n- Output field order: `window_start`, `product_id`, `sales`, `order_cnt`, `rn`", "ground_truth": "-- flinksql_011: 滚动窗口商品 TopN 排行\n-- 10-min TUMBLE + SUM(amount) + COUNT(*) + ROW_NUMBER Top-5\n\n-- 1. 订单源 datagen 表\nCREATE TABLE order_source (\n order_id BIGINT,\n product_id INT,\n amount DOUBLE,\n event_time AS LOCALTIMESTAMP,\n WATERMARK FOR event_time AS event_time - INTERVAL '5' SECOND\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '8000',\n 'fields.order_id.kind' = 'random',\n 'fields.order_id.min' = '1',\n 'fields.order_id.max' = '10000000',\n 'fields.product_id.kind' = 'random',\n 'fields.product_id.min' = '1',\n 'fields.product_id.max' = '200',\n 'fields.amount.kind' = 'random',\n 'fields.amount.min' = '0',\n 'fields.amount.max' = '500'\n);\n\n-- 2. Console 输出表\nCREATE TABLE console_output (\n window_start TIMESTAMP(3),\n product_id INT,\n sales DOUBLE,\n order_cnt BIGINT,\n rn BIGINT\n) WITH (\n 'connector' = 'print'\n);\n\n-- 3. TUMBLE 窗口聚合 + ROW_NUMBER Top-5\nINSERT INTO console_output\nSELECT\n window_start,\n product_id,\n sales,\n order_cnt,\n rn\nFROM (\n SELECT\n window_start,\n window_end,\n product_id,\n sales,\n order_cnt,\n ROW_NUMBER() OVER (\n PARTITION BY window_start, window_end\n ORDER BY sales DESC\n ) AS rn\n FROM (\n SELECT\n TUMBLE_START(event_time, INTERVAL '10' MINUTE) AS window_start,\n TUMBLE_END(event_time, INTERVAL '10' MINUTE) AS window_end,\n product_id,\n SUM(amount) AS sales,\n COUNT(*) AS order_cnt\n FROM order_source\n GROUP BY\n TUMBLE(event_time, INTERVAL '10' MINUTE),\n product_id\n )\n)\nWHERE rn <= 5;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/online-compute/FlinkSQL/flinksql_011_en"}
|
| 12 |
+
{"task_id": "flinksql_012_en", "id": "online-compute_FlinkSQL_flinksql_012", "name": "Session Window User Behavior Statistics", "workload": "online-compute", "engine": "FlinkSQL", "category": "online-compute/FlinkSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 600, "prompt": "## Prompt\nI need you to write a Flink SQL that uses the built-in datagen connector to simulate a user behavior data source, computes per-user behavioral statistics over a 30-minute session window (`SESSION`), and outputs the results to the console.\n\n**Business Background and Objective**: Simulate a user behavior stream using a datagen built-in table. Group by a 30-minute session window to compute the total action count (`COUNT`) and the number of distinct action types (`COUNT DISTINCT`) per user within each session window. Output the results to the console.\n\n**Source Table Definition**:\n- `user_actions` (user behavior stream, datagen connector):\n - `user_id INT`: User ID, randomly generated in the range 1–5000\n - `action_id INT`: Action type ID, randomly generated in the range 1–10\n - `event_time`: Uses `LOCALTIMESTAMP` to generate event time, with a WATERMARK delay of 5 seconds\n - Generation rate: `rows-per-second = 2000`\n\n**Output Table Definition**:\n- `console_output` (print connector):\n - `user_id INT`: User ID\n - `session_start TIMESTAMP(3)`: Session window start time\n - `session_end TIMESTAMP(3)`: Session window end time\n - `action_count BIGINT`: Total action count\n - `unique_actions BIGINT`: Number of distinct action types\n\n**SQL Logic**:\n- Apply `SESSION(event_time, INTERVAL '30' MINUTE)` session window on `user_actions`\n- Group by `SESSION(event_time, INTERVAL '30' MINUTE)` and `user_id`\n- Aggregate `COUNT(*) AS action_count` and `COUNT(DISTINCT action_id) AS unique_actions`\n- Use `SESSION_START` and `SESSION_END` functions to obtain the window start and end times\n\n**Output Requirements**:\n- Use `INSERT INTO console_output` to output the results.\n- Output field order: `user_id`, `session_start`, `session_end`, `action_count`, `unique_actions`", "ground_truth": "-- flinksql_012: 会话窗口用户行为统计\n-- 30-min SESSION + COUNT + COUNT DISTINCT\n\n-- 1. 用户行为 datagen 源表\nCREATE TABLE user_actions (\n user_id INT,\n action_id INT,\n event_time AS LOCALTIMESTAMP,\n WATERMARK FOR event_time AS event_time - INTERVAL '5' SECOND\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '2000',\n 'fields.user_id.kind' = 'random',\n 'fields.user_id.min' = '1',\n 'fields.user_id.max' = '5000',\n 'fields.action_id.kind' = 'random',\n 'fields.action_id.min' = '1',\n 'fields.action_id.max' = '10'\n);\n\n-- 2. Console 输出表\nCREATE TABLE console_output (\n user_id INT,\n session_start TIMESTAMP(3),\n session_end TIMESTAMP(3),\n action_count BIGINT,\n unique_actions BIGINT\n) WITH (\n 'connector' = 'print'\n);\n\n-- 3. SESSION 窗口聚合\nINSERT INTO console_output\nSELECT\n user_id,\n SESSION_START(event_time, INTERVAL '30' MINUTE) AS session_start,\n SESSION_END(event_time, INTERVAL '30' MINUTE) AS session_end,\n COUNT(*) AS action_count,\n COUNT(DISTINCT action_id) AS unique_actions\nFROM user_actions\nGROUP BY\n SESSION(event_time, INTERVAL '30' MINUTE),\n user_id;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/online-compute/FlinkSQL/flinksql_012_en"}
|
| 13 |
+
{"task_id": "flinksql_013", "id": "online-compute_FlinkSQL_flinksql_013", "name": "累积窗口日活统计 (Cumulate UV)", "workload": "online-compute", "engine": "FlinkSQL", "category": "online-compute/FlinkSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 600, "prompt": "## Prompt\n我需要你写一段 Flink SQL,用 datagen 内置连接器模拟用户登录数据源,通过累积窗口(CUMULATE)统计日活 UV 和登录次数,输出到 console。\n\n**业务背景与目标**:用 datagen 内置表模拟用户登录流水。使用 CUMULATE TVF 累积窗口,窗口步长 1 分钟、最大窗口 1 天,统计每个累积窗口内的独立用户数(UV)和登录总次数,输出到 console。\n\n**源表定义**:\n- `user_source`(用户登录流,datagen 连接器):\n - user_id INT:用户 ID,随机取值 1~100000\n - device_id INT:设备 ID,随机取值 1~5\n - event_time:使用 LOCALTIMESTAMP 生成事件时间,设置 WATERMARK 延迟 5 秒\n - 生成速率:rows-per-second = 3000\n\n**输出表定义**:\n- `console_output`(print 连接器):\n - window_start TIMESTAMP(3):累积窗口起始时间\n - window_end TIMESTAMP(3):累积窗口结束时间\n - uv BIGINT:独立用户数(去重 user_id)\n - login_cnt BIGINT:登录总次数\n\n**SQL 逻辑**:\n- 使用 CUMULATE TVF:TABLE(CUMULATE(TABLE user_source, DESCRIPTOR(event_time), INTERVAL '1' MINUTE, INTERVAL '1' DAY))\n- 按 window_start 和 window_end 分组\n- 聚合 COUNT(DISTINCT user_id) AS uv 和 COUNT(*) AS login_cnt\n\n**输出要求**:\n- 使用 INSERT INTO console_output 将结果输出\n- 输出字段顺序:window_start, window_end, uv, login_cnt", "ground_truth": "-- flinksql_013: 累积窗口日活统计 (Cumulate UV)\n-- CUMULATE(1min step, 1day max) + COUNT DISTINCT + COUNT\n\n-- 1. 用户登录 datagen 源表\nCREATE TABLE user_source (\n user_id INT,\n device_id INT,\n event_time AS LOCALTIMESTAMP,\n WATERMARK FOR event_time AS event_time - INTERVAL '5' SECOND\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '3000',\n 'fields.user_id.kind' = 'random',\n 'fields.user_id.min' = '1',\n 'fields.user_id.max' = '100000',\n 'fields.device_id.kind' = 'random',\n 'fields.device_id.min' = '1',\n 'fields.device_id.max' = '5'\n);\n\n-- 2. Console 输出表\nCREATE TABLE console_output (\n window_start TIMESTAMP(3),\n window_end TIMESTAMP(3),\n uv BIGINT,\n login_cnt BIGINT\n) WITH (\n 'connector' = 'print'\n);\n\n-- 3. CUMULATE TVF 窗口聚合\nINSERT INTO console_output\nSELECT\n window_start,\n window_end,\n COUNT(DISTINCT user_id) AS uv,\n COUNT(*) AS login_cnt\nFROM TABLE(\n CUMULATE(\n TABLE user_source,\n DESCRIPTOR(event_time),\n INTERVAL '1' MINUTE,\n INTERVAL '1' DAY\n )\n)\nGROUP BY window_start, window_end;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/online-compute/FlinkSQL/flinksql_013"}
|
| 14 |
+
{"task_id": "flinksql_014", "id": "online-compute_FlinkSQL_flinksql_014", "name": "Interval Join + 窗口聚合 (订单支付)", "workload": "online-compute", "engine": "FlinkSQL", "category": "online-compute/FlinkSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 600, "prompt": "## Prompt\n我需要你写一段 Flink SQL,用两个 datagen 内置连接器模拟订单流和支付流,先按 order_id 做 Interval Join 匹配订单与支付,再对匹配结果做 10 分钟滚动窗口聚合统计,输出到 console。\n\n**业务背景与目标**:用两张 datagen 内置表分别模拟订单流和支付流。先按 order_id 做 Interval Join(支付时间在订单时间前后 10 分钟内),对匹配上的记录按 10 分钟滚动窗口聚合,统计每个窗口内的订单数和支付总额,输出到 console。\n\n**源表定义**:\n- `orders_source`(订单流,datagen 连接器):\n - order_id INT:订单 ID,随机取值 1~1000000\n - user_id INT:用户 ID,随机取值 1~100000\n - order_time:使用 LOCALTIMESTAMP 生成事件时间,设置 WATERMARK 延迟 60 秒\n - 生成速率:rows-per-second = 10000\n\n- `payments_source`(支付流,datagen 连接器):\n - order_id INT:订单 ID,随机取值 1~1000000\n - pay_amount DOUBLE:支付金额,随机取值 0~5000\n - pay_time:使用 LOCALTIMESTAMP 生成事件时间,设置 WATERMARK 延迟 60 秒\n - 生成速率:rows-per-second = 10000\n\n**输出表定义**:\n- `console_output`(print 连接器):\n - window_start VARCHAR:滚动窗口起始时间\n - window_end VARCHAR:滚动窗口结束时间\n - order_count BIGINT:窗口内匹配订单数\n - total_pay DOUBLE:窗口内支付总额\n\n**SQL 逻辑**:\n- 第一步:orders_source 与 payments_source 做 Interval Join\n - 关联条件:o.order_id = p.order_id\n - 时间窗口:p.pay_time BETWEEN o.order_time - INTERVAL '10' MINUTE AND o.order_time + INTERVAL '10' MINUTE\n - 注意:对 pay_time 做 CAST(pay_time AS TIMESTAMP(3)) 降为普通时间戳\n- 第二步:对 Join 结果做 10 分钟 TUMBLE 滚动窗口聚合\n - 使用 TUMBLE 按 o.order_time 作为事件时间\n - 聚合 COUNT(*) AS order_count 和 SUM(p.pay_amount) AS total_pay\n - 使用 TUMBLE_START 和 TUMBLE_END(CAST 为 VARCHAR)\n\n**输出要求**:\n- 使用 INSERT INTO console_output 将结果输出\n- 输出字段顺序:window_start, window_end, order_count, total_pay", "ground_truth": "-- flinksql_014: Interval Join + 10-min TUMBLE 窗口聚合 (订单支付)\n-- 双源 Interval Join → TUMBLE 聚合 → COUNT + SUM\n\n-- 1. 订单流 datagen 源表\nCREATE TABLE orders_source (\n order_id INT,\n user_id INT,\n order_time AS LOCALTIMESTAMP,\n WATERMARK FOR order_time AS order_time - INTERVAL '60' SECOND\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '10000',\n 'fields.order_id.kind' = 'random',\n 'fields.order_id.min' = '1',\n 'fields.order_id.max' = '1000000',\n 'fields.user_id.kind' = 'random',\n 'fields.user_id.min' = '1',\n 'fields.user_id.max' = '100000'\n);\n\n-- 2. 支付流 datagen 源表\nCREATE TABLE payments_source (\n order_id INT,\n pay_amount DOUBLE,\n pay_time AS LOCALTIMESTAMP,\n WATERMARK FOR pay_time AS pay_time - INTERVAL '60' SECOND\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '10000',\n 'fields.order_id.kind' = 'random',\n 'fields.order_id.min' = '1',\n 'fields.order_id.max' = '1000000',\n 'fields.pay_amount.kind' = 'random',\n 'fields.pay_amount.min' = '0',\n 'fields.pay_amount.max' = '5000'\n);\n\n-- 3. Console 输出表\nCREATE TABLE console_output (\n window_start VARCHAR,\n window_end VARCHAR,\n order_count BIGINT,\n total_pay DOUBLE\n) WITH (\n 'connector' = 'print'\n);\n\n-- 4. Interval Join + TUMBLE 窗口聚合\nINSERT INTO console_output\nSELECT\n CAST(TUMBLE_START(o.order_time, INTERVAL '10' MINUTE) AS VARCHAR) AS window_start,\n CAST(TUMBLE_END(o.order_time, INTERVAL '10' MINUTE) AS VARCHAR) AS window_end,\n COUNT(*) AS order_count,\n SUM(p.pay_amount) AS total_pay\nFROM orders_source o\nJOIN payments_source p\n ON o.order_id = p.order_id\nWHERE\n p.pay_time BETWEEN o.order_time - INTERVAL '10' MINUTE\n AND o.order_time + INTERVAL '10' MINUTE\nGROUP BY\n TUMBLE(o.order_time, INTERVAL '10' MINUTE);", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/online-compute/FlinkSQL/flinksql_014"}
|
| 15 |
+
{"task_id": "flinksql_015", "id": "online-compute_FlinkSQL_flinksql_015", "name": "Regular Join 曝光点击关联", "workload": "online-compute", "engine": "FlinkSQL", "category": "online-compute/FlinkSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 600, "prompt": "## Prompt\n我需要你写一段 Flink SQL,用两个 datagen 内置连接器分别模拟广告曝光流和广告点击流,通过 Regular Join(常规内连接)关联曝光与点击,输出到 console。\n\n**业务背景与目标**:用两张 datagen 内置表分别模拟广告曝光和广告点击数据。Regular Join 不需要事件时间或 Watermark,直接按 user_id 和 ad_id 做内连接,将同一用户对同一广告的曝光和点击关联起来输出。\n\n**源表定义**:\n- `impression_source`(曝光流,datagen 连接器):\n - imp_id BIGINT:曝光 ID,随机取值 1~10000000\n - user_id INT:用户 ID,随机取值 1~100000\n - ad_id INT:广告 ID,随机取值 1~500\n - 生成速率:rows-per-second = 5000\n - 注意:Regular Join 不需要定义 event_time 或 WATERMARK\n\n- `click_source`(点击流,datagen 连接器):\n - click_id BIGINT:点击 ID,随机取值 1~10000000\n - user_id INT:用户 ID,随机取值 1~100000\n - ad_id INT:广告 ID,随机取值 1~500\n - 生成速率:rows-per-second = 1000\n - 注意:Regular Join 不需要定义 event_time 或 WATERMARK\n\n**输出表定义**:\n- `console_output`(print 连接器):\n - user_id INT:用户 ID\n - ad_id INT:广告 ID\n - imp_id BIGINT:曝光 ID\n - click_id BIGINT:点击 ID\n\n**Join 逻辑**:\n- 使用 INNER JOIN 关联曝光流和点击流\n- 关联条件:i.user_id = c.user_id AND i.ad_id = c.ad_id\n- 这是一个 Regular Join,不需要 Interval Join 的时间窗口条件\n- 注意:Regular Join 的 state 会持续增长,在生产环境需注意 TTL 配置\n\n**输出要求**:\n- 使用 INSERT INTO console_output 将匹配结果输出\n- 输出字段顺序:user_id, ad_id, imp_id, click_id", "ground_truth": "-- flinksql_015: Regular Join (广告曝光 + 点击)\n-- 双源无 WATERMARK + INNER JOIN on user_id AND ad_id\n\n-- 1. 曝光流 datagen 源表 (无 event_time, 无 WATERMARK)\nCREATE TABLE impression_source (\n imp_id BIGINT,\n user_id INT,\n ad_id INT\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '5000',\n 'fields.imp_id.kind' = 'random',\n 'fields.imp_id.min' = '1',\n 'fields.imp_id.max' = '10000000',\n 'fields.user_id.kind' = 'random',\n 'fields.user_id.min' = '1',\n 'fields.user_id.max' = '100000',\n 'fields.ad_id.kind' = 'random',\n 'fields.ad_id.min' = '1',\n 'fields.ad_id.max' = '500'\n);\n\n-- 2. 点击流 datagen 源表 (无 event_time, 无 WATERMARK)\nCREATE TABLE click_source (\n click_id BIGINT,\n user_id INT,\n ad_id INT\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '1000',\n 'fields.click_id.kind' = 'random',\n 'fields.click_id.min' = '1',\n 'fields.click_id.max' = '10000000',\n 'fields.user_id.kind' = 'random',\n 'fields.user_id.min' = '1',\n 'fields.user_id.max' = '100000',\n 'fields.ad_id.kind' = 'random',\n 'fields.ad_id.min' = '1',\n 'fields.ad_id.max' = '500'\n);\n\n-- 3. Console 输出表\nCREATE TABLE console_output (\n user_id INT,\n ad_id INT,\n imp_id BIGINT,\n click_id BIGINT\n) WITH (\n 'connector' = 'print'\n);\n\n-- 4. Regular Join: 按 user_id + ad_id 关联曝光和点击\nINSERT INTO console_output\nSELECT\n i.user_id,\n i.ad_id,\n i.imp_id,\n c.click_id\nFROM impression_source i\nINNER JOIN click_source c\n ON i.user_id = c.user_id\n AND i.ad_id = c.ad_id;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/online-compute/FlinkSQL/flinksql_015"}
|
| 16 |
+
{"task_id": "flinksql_016", "id": "online-compute_FlinkSQL_flinksql_016", "name": "滚动窗口多维聚合 (GROUPING SETS)", "workload": "online-compute", "engine": "FlinkSQL", "category": "online-compute/FlinkSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 600, "prompt": "## Prompt\n我需要你写一段 Flink SQL,用 datagen 内置连接器模拟事件流,按 1 分钟滚动窗口做 GROUPING SETS 多维聚合,结果打到 console。\n\n**业务背景与目标**:用 datagen 内置表生成设备事件流,共 5000 行/秒。字段包括 os_id(操作系统 ID,1~3)、device_id(设备 ID,1~20)、city_id(城市 ID,1~100)。使用 LOCALTIMESTAMP 作为事件时间,设置 5 秒 Watermark 延迟。\n\n按 1 分钟 TUMBLE 滚动窗口,使用 GROUPING SETS 进行多维分组聚合,分组组合包括:(os_id, device_id)、(city_id)、以及全局汇总()。统计每个维度组合的事件数 COUNT(*),输出到 console 表。\n\n**源表定义**:\n- `event_source`(datagen 连接器):\n - os_id INT:操作系统 ID,随机取值 1~3\n - device_id INT:设备 ID,随机取值 1~20\n - city_id INT:城市 ID,随机取值 1~100\n - event_time:使用 LOCALTIMESTAMP 生成事件时间,设置 WATERMARK 延迟 5 秒\n - 生成速率:rows-per-second = 5000\n\n**输出表定义**:\n- `console_output`(print 连接器):\n - window_start TIMESTAMP(3):窗口起始时间\n - os_id INT:操作系统 ID(聚合维度可为 NULL)\n - device_id INT:设备 ID(聚合维度可为 NULL)\n - city_id INT:城市 ID(聚合维度可为 NULL)\n - event_cnt BIGINT:事件计数\n\n**聚合逻辑**:\n- 滚动窗口:TUMBLE 1 分钟\n- 分组方式:GROUPING SETS ((os_id, device_id), (city_id), ())\n- 聚合指标:COUNT(*) AS event_cnt\n- 窗口起始时间用 TUMBLE_START 计算\n\n**输出要求**:\n- 使用 INSERT INTO console_output 将结果输出\n- 输出字段顺序:window_start, os_id, device_id, city_id, event_cnt", "ground_truth": "-- flinksql_016: 滚动窗口多维聚合 (GROUPING SETS) — TVF syntax\n-- 生成 5000 行/秒的设备事件流\n\n-- 1. 设备事件流 datagen 源表\nCREATE TABLE event_source (\n os_id INT,\n device_id INT,\n city_id INT,\n event_time AS LOCALTIMESTAMP,\n WATERMARK FOR event_time AS event_time - INTERVAL '5' SECOND\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '5000',\n 'fields.os_id.kind' = 'random',\n 'fields.os_id.min' = '1',\n 'fields.os_id.max' = '3',\n 'fields.device_id.kind' = 'random',\n 'fields.device_id.min' = '1',\n 'fields.device_id.max' = '20',\n 'fields.city_id.kind' = 'random',\n 'fields.city_id.min' = '1',\n 'fields.city_id.max' = '100'\n);\n\n-- 2. Console 输出表\nCREATE TABLE console_output (\n window_start TIMESTAMP(3),\n os_id INT,\n device_id INT,\n city_id INT,\n event_cnt BIGINT\n) WITH (\n 'connector' = 'print'\n);\n\n-- 3. TUMBLE TVF 1min + GROUPING SETS 多维聚合\nINSERT INTO console_output\nSELECT\n window_start,\n os_id,\n device_id,\n city_id,\n COUNT(*) AS event_cnt\nFROM TABLE(\n TUMBLE(TABLE event_source, DESCRIPTOR(event_time), INTERVAL '1' MINUTE)\n)\nGROUP BY window_start, window_end,\n GROUPING SETS ((os_id, device_id), (city_id), ());", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/online-compute/FlinkSQL/flinksql_016"}
|
| 17 |
+
{"task_id": "flinksql_017_en", "id": "online-compute_FlinkSQL_flinksql_017", "name": "Row-Level TopN (Windowless)", "workload": "online-compute", "engine": "FlinkSQL", "category": "online-compute/FlinkSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 600, "prompt": "## Prompt\nI need you to write a Flink SQL that uses the built-in datagen connector to simulate a spending stream, retrieves the top 3 records by spending amount grouped by `country_id` without any window, and outputs the results directly to the console.\n\n**Business Background and Objective**: Generate user spending records using a datagen built-in table at a rate of 1000 rows per second. Fields include `country_id` (country ID, 1–30), `user_id` (user ID, 1–100,000), and `cost_money` (spending amount, 0–10,000). No event time or watermark is required, since no window operations are involved.\n\nUse the `ROW_NUMBER()` window function, partitioned by `country_id` and sorted by `cost_money` in descending order, keeping only the top 3 records per partition (`row_num <= 3`), and output the results directly to the console table. This is a continuous TopN query where each country's top 3 dynamically updates as new data flows in.\n\n**Source Table Definition**:\n- `spend_source` (datagen connector):\n - `country_id INT`: Country ID, randomly generated in the range 1–30\n - `user_id INT`: User ID, randomly generated in the range 1–100,000\n - `cost_money DOUBLE`: Spending amount, randomly generated in the range 0–10,000\n - Generation rate: `rows-per-second = 1000`\n\n**Output Table Definition**:\n- `console_output` (print connector):\n - `country_id INT`: Country ID\n - `user_id INT`: User ID\n - `cost_money DOUBLE`: Spending amount\n - `row_num BIGINT`: Row number\n\n**TopN Logic**:\n- Use `ROW_NUMBER() OVER (PARTITION BY country_id ORDER BY cost_money DESC)` to generate row numbers\n- Apply `WHERE row_num <= 3` to keep the top 3 per country\n- No window operation is required; no event time or watermark needs to be defined\n\n**Output Requirements**:\n- Use `INSERT INTO console_output` to output the results.\n- Output field order: `country_id`, `user_id`, `cost_money`, `row_num`", "ground_truth": "-- flinksql_017: 行级 TopN (无窗口)\n-- 生成 1000 行/秒的用户消费流\n\n-- 1. 用户消费流 datagen 源表(无事件时间/Watermark)\nCREATE TABLE spend_source (\n country_id INT,\n user_id INT,\n cost_money DOUBLE\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '1000',\n 'fields.country_id.kind' = 'random',\n 'fields.country_id.min' = '1',\n 'fields.country_id.max' = '30',\n 'fields.user_id.kind' = 'random',\n 'fields.user_id.min' = '1',\n 'fields.user_id.max' = '100000',\n 'fields.cost_money.kind' = 'random',\n 'fields.cost_money.min' = '0',\n 'fields.cost_money.max' = '10000'\n);\n\n-- 2. Console 输出表\nCREATE TABLE console_output (\n country_id INT,\n user_id INT,\n cost_money DOUBLE,\n row_num BIGINT\n) WITH (\n 'connector' = 'print'\n);\n\n-- 3. 行级 TopN: 每个 country_id 取 cost_money 最高的前 3 条\nINSERT INTO console_output\nSELECT\n country_id,\n user_id,\n cost_money,\n row_num\nFROM (\n SELECT\n country_id,\n user_id,\n cost_money,\n ROW_NUMBER() OVER (\n PARTITION BY country_id\n ORDER BY cost_money DESC\n ) AS row_num\n FROM spend_source\n) t\nWHERE row_num <= 3;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/online-compute/FlinkSQL/flinksql_017_en"}
|
| 18 |
+
{"task_id": "flinksql_018_en", "id": "online-compute_FlinkSQL_flinksql_018", "name": "Dual Output (Detail + Windowed Aggregation)", "workload": "online-compute", "engine": "FlinkSQL", "category": "online-compute/FlinkSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 600, "prompt": "## Prompt\nI need you to write a Flink SQL that uses the built-in datagen connector to simulate an order stream, simultaneously outputting detail records to `console1` and windowed aggregation results over a 1-minute tumbling window to `console2`.\n\n**Business Background and Objective**: Generate an order event stream using a datagen built-in table at a rate of 2000 rows per second. Fields include `order_id` (order ID), `user_id` (user ID, 1–10,000), and `amount` (order amount, 0–1000). Use `LOCALTIMESTAMP` as the event time and set a 5-second watermark delay.\n\nThe same source data must be simultaneously output to two sinks:\n- `console1`: Detail passthrough, directly outputting the original fields\n- `console2`: Aggregation over a 1-minute `TUMBLE` tumbling window, grouped by `user_id` to compute the order count and total amount\n\n**Source Table Definition**:\n- `order_source` (datagen connector):\n - `order_id BIGINT`: Order ID, randomly generated\n - `user_id INT`: User ID, randomly generated in the range 1–10,000\n - `amount DOUBLE`: Order amount, randomly generated in the range 0–1000\n - `event_time`: Uses `LOCALTIMESTAMP` to generate event time, with a WATERMARK delay of 5 seconds\n - Generation rate: `rows-per-second = 2000`\n\n**Output Table 1 Definition**:\n- `console1` (print connector, detail output):\n - `order_id BIGINT`\n - `user_id INT`\n - `amount DOUBLE`\n\n**Output Table 2 Definition**:\n- `console2` (print connector, aggregation output):\n - `window_start TIMESTAMP(3)`: Window start time\n - `user_id INT`: User ID\n - `order_cnt BIGINT`: Order count within the window\n - `total_amount DOUBLE`: Total order amount within the window\n\n**Aggregation Logic**:\n- Detail output: Direct passthrough from `order_source`\n- Aggregation output: `TUMBLE` 1-minute tumbling window, `GROUP BY user_id`\n- Aggregation metrics: `COUNT(*) AS order_cnt`, `SUM(amount) AS total_amount`\n\n**Output Requirements**:\n- Use two `INSERT INTO` statements to write to `console1` and `console2` respectively.\n- `console1` output field order: `order_id`, `user_id`, `amount`\n- `console2` output field order: `window_start`, `user_id`, `order_cnt`, `total_amount`", "ground_truth": "-- flinksql_018: 双输出 (明细 + 窗口聚合)\n-- 生成 2000 行/秒的订单事件流\n\n-- 1. 订单事件流 datagen 源表\nCREATE TABLE order_source (\n order_id BIGINT,\n user_id INT,\n amount DOUBLE,\n event_time AS LOCALTIMESTAMP,\n WATERMARK FOR event_time AS event_time - INTERVAL '5' SECOND\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '2000',\n 'fields.order_id.kind' = 'random',\n 'fields.order_id.min' = '1',\n 'fields.order_id.max' = '1000000000',\n 'fields.user_id.kind' = 'random',\n 'fields.user_id.min' = '1',\n 'fields.user_id.max' = '10000',\n 'fields.amount.kind' = 'random',\n 'fields.amount.min' = '0',\n 'fields.amount.max' = '1000'\n);\n\n-- 2. Console1: 明细透传输出表\nCREATE TABLE console1 (\n order_id BIGINT,\n user_id INT,\n amount DOUBLE\n) WITH (\n 'connector' = 'print'\n);\n\n-- 3. Console2: 窗口聚合输出表\nCREATE TABLE console2 (\n window_start TIMESTAMP(3),\n user_id INT,\n order_cnt BIGINT,\n total_amount DOUBLE\n) WITH (\n 'connector' = 'print'\n);\n\n-- 4. 明细透传:直接输出原始字段\nINSERT INTO console1\nSELECT\n order_id,\n user_id,\n amount\nFROM order_source;\n\n-- 5. 窗口聚合:TUMBLE 1min 按 user_id 分组统计\nINSERT INTO console2\nSELECT\n TUMBLE_START(event_time, INTERVAL '1' MINUTE) AS window_start,\n user_id,\n COUNT(*) AS order_cnt,\n SUM(amount) AS total_amount\nFROM order_source\nGROUP BY TUMBLE(event_time, INTERVAL '1' MINUTE), user_id;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/online-compute/FlinkSQL/flinksql_018_en"}
|
| 19 |
+
{"task_id": "flinksql_019", "id": "online-compute_FlinkSQL_flinksql_019", "name": "全局分组 + 过滤统计", "workload": "online-compute", "engine": "FlinkSQL", "category": "online-compute/FlinkSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 600, "prompt": "## Prompt\n我需要你写一段 Flink SQL,用 datagen 内置连接器模拟交易流,按状态过滤后全局分组统计,结果打到 console。\n\n**业务背景与目标**:用 datagen 内置表生成交易事件流,共 3000 行/秒。字段包括 trade_id(交易 ID)、type(交易类型,1~5)、status(状态,0~2)、amount(交易金额,0~5000)。\n\n注意:`type` 和 `status` 是 SQL 保留字,需要使用反引号包裹(例如 `` `type` ``、`` `status` ``)。\n\n先按 status = 1 过滤,再按 type 分组统计交易笔数和交易金额总和,最后输出到 console 表。因为不涉及窗口操作,无需定义事件时间和 Watermark。\n\n**源表定义**:\n- `trade_source`(datagen 连接器):\n - trade_id BIGINT:交易 ID,随机取值\n - `` `type` `` INT:交易类型,随机取值 1~5\n - `` `status` `` INT:状态,随机取值 0~2\n - amount DOUBLE:交易金额,随机取值 0~5000\n - 生成速率:rows-per-second = 3000\n\n**输出表定义**:\n- `console_output`(print 连接器):\n - `` `type` `` INT:交易类型\n - trade_cnt BIGINT:交易笔数\n - total_amount DOUBLE:交易金额总和\n\n**过滤与聚合逻辑**:\n- 过滤条件:`` `status` `` = 1(仅统计状态为 1 的交易)\n- 分组:按 `` `type` `` 分组\n- 聚合指标:COUNT(*) AS trade_cnt, SUM(amount) AS total_amount\n\n**输出要求**:\n- 使用 INSERT INTO console_output 将结果输出\n- 输出字段顺序:`` `type` ``, trade_cnt, total_amount", "ground_truth": "-- flinksql_019: 全局分组 + 过滤统计\n-- 生成 3000 行/秒的交易事件流,使用反引号包裹保留字\n\n-- 1. 交易事件流 datagen 源表(无事件时间/Watermark)\nCREATE TABLE trade_source (\n trade_id BIGINT,\n `type` INT,\n `status` INT,\n amount DOUBLE\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '3000',\n 'fields.trade_id.kind' = 'random',\n 'fields.trade_id.min' = '1',\n 'fields.trade_id.max' = '1000000000',\n 'fields.type.kind' = 'random',\n 'fields.type.min' = '1',\n 'fields.type.max' = '5',\n 'fields.status.kind' = 'random',\n 'fields.status.min' = '0',\n 'fields.status.max' = '2',\n 'fields.amount.kind' = 'random',\n 'fields.amount.min' = '0',\n 'fields.amount.max' = '5000'\n);\n\n-- 2. Console 输出表\nCREATE TABLE console_output (\n `type` INT,\n trade_cnt BIGINT,\n total_amount DOUBLE\n) WITH (\n 'connector' = 'print'\n);\n\n-- 3. 过滤 status=1 + 按 type 分组统计\nINSERT INTO console_output\nSELECT\n `type`,\n COUNT(*) AS trade_cnt,\n SUM(amount) AS total_amount\nFROM trade_source\nWHERE `status` = 1\nGROUP BY `type`;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/online-compute/FlinkSQL/flinksql_019"}
|
| 20 |
+
{"task_id": "flinksql_020", "id": "online-compute_FlinkSQL_flinksql_020", "name": "窗口去重 (TVF Dedup)", "workload": "online-compute", "engine": "FlinkSQL", "category": "online-compute/FlinkSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 600, "prompt": "## Prompt\n我需要你写一段 Flink SQL,用 datagen 内置连接器模拟事件流,使用 TUMBLE TVF 窗口表值函数 + ROW_NUMBER 做窗口去重,每个窗口内每个用户只保留最早的一条事件。\n\n**业务背景与目标**:用 datagen 内置表生成用户事件流,共 5000 行/秒。字段包括 user_id(用户 ID,1~10000)、event_id(事件 ID)、event_type(事件类型,1~8)。使用 LOCALTIMESTAMP 作为事件时间,设置 10 秒 Watermark 延迟。\n\n使用 TUMBLE 表值函数(TABLE(TUMBLE(...)))将事件分配到 5 分钟滚动窗口,然后在每个(window_start, user_id)分区内,按事件时间升序使用 ROW_NUMBER() 编号,只保留每个窗口每个用户的第一条事件(rn = 1),最后输出到 console。\n\n**源表定义**:\n- `event_source`(datagen 连接器):\n - user_id INT:用户 ID,随机取值 1~10000\n - event_id BIGINT:事件 ID,随机取值\n - event_type INT:事件类型,随机取值 1~8\n - event_time:使用 LOCALTIMESTAMP 生成事件时间,设置 WATERMARK 延迟 10 秒\n - 生成速率:rows-per-second = 5000\n\n**输出表定义**:\n- `console_output`(print 连接器):\n - window_start TIMESTAMP(3):窗口起始时间\n - window_end TIMESTAMP(3):窗口结束时间\n - user_id INT:用户 ID\n - event_id BIGINT:事件 ID\n - event_type INT:事件类型\n\n**去重逻辑**:\n- 窗口:TUMBLE TVF 5 分钟滚动窗口\n- 排序:ROW_NUMBER() OVER (PARTITION BY window_start, user_id ORDER BY event_time ASC)\n- 过滤:WHERE rn = 1 保留每个窗口每个用户的第一条事件\n- 窗口时间字段可从 TVF 的 window_start 和 window_end 获得\n\n**输出要求**:\n- 使用 INSERT INTO console_output 将结果输出\n- 输出字段顺序:window_start, window_end, user_id, event_id, event_type", "ground_truth": "-- flinksql_020: 窗口去重 (TVF Dedup)\n-- TUMBLE TVF + ROW_NUMBER 按窗口去重,保留每个窗口每个用户的第一条\n\n-- 1. 用户事件流 datagen 源表\nCREATE TABLE event_source (\n user_id INT,\n event_id BIGINT,\n event_type INT,\n event_time AS LOCALTIMESTAMP,\n WATERMARK FOR event_time AS event_time - INTERVAL '10' SECOND\n) WITH (\n 'connector' = 'datagen',\n 'rows-per-second' = '5000',\n 'fields.user_id.kind' = 'random',\n 'fields.user_id.min' = '1',\n 'fields.user_id.max' = '10000',\n 'fields.event_id.kind' = 'random',\n 'fields.event_id.min' = '1',\n 'fields.event_id.max' = '1000000000',\n 'fields.event_type.kind' = 'random',\n 'fields.event_type.min' = '1',\n 'fields.event_type.max' = '8'\n);\n\n-- 2. Console 输出表\nCREATE TABLE console_output (\n window_start TIMESTAMP(3),\n window_end TIMESTAMP(3),\n user_id INT,\n event_id BIGINT,\n event_type INT\n) WITH (\n 'connector' = 'print'\n);\n\n-- 3. TUMBLE TVF + ROW_NUMBER 窗口去重\nINSERT INTO console_output\nSELECT\n window_start,\n window_end,\n user_id,\n event_id,\n event_type\nFROM (\n SELECT\n window_start,\n window_end,\n user_id,\n event_id,\n event_type,\n ROW_NUMBER() OVER (\n PARTITION BY window_start, user_id\n ORDER BY event_time ASC\n ) AS rn\n FROM TABLE(\n TUMBLE(TABLE event_source, DESCRIPTOR(event_time), INTERVAL '5' MINUTE)\n )\n) t\nWHERE rn = 1;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/online-compute/FlinkSQL/flinksql_020"}
|
hf_dataset/hivesql.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
hf_dataset/mysql.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
hf_dataset/prestosql.jsonl
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{"task_id": "prestosql_001", "id": "offline-compute_PrestoSQL_prestosql_001", "name": "安全扫描实例明细分析", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n任务目标:从安全扫描 span 信息和资源分配信息关联产出安全扫描实例运行明细表。\n\n输入:\n- internal_platform_db.t_security_scan_span_prestosql_001\n- internal_platform_db.t_security_resource_info_prestosql_001\n\n处理规则:\n- 两表关联查询,关联条件需基于表结构确定\n- 具体过滤条件和字段选择需基于表结构确定\n\n输出要求:\n- 输出表:internal_platform_db.t_security_scan_instance_detail_cand_prestosql_001\n- 输出字段需基于目标表结构确定\n\n写入要求:\n- 写入目标表\n\n请将最终 Presto/Trino SQL 写入 result.sql 并执行。", "ground_truth": "INSERT INTO internal_platform_db.t_security_scan_instance_detail_prestosql_001\nWITH base_trace AS (\n SELECT trace_id\n FROM internal_platform_db.t_security_scan_span_prestosql_001\n WHERE databus_imp_date >= '2026060600'\n AND databus_imp_date <= '2026060800'\n AND span_name IN ('scan.completed', 'scan.failed')\n GROUP BY trace_id\n HAVING\n COUNT(CASE WHEN span_name = 'scan.failed' THEN 1 END) > 0\n AND\n COUNT(CASE WHEN span_name = 'scan.completed' THEN 1 END) = 0\n),\ncombined_spans AS (\n SELECT\n trace_id,\n span_name,\n start_time,\n end_time,\n security_project_id,\n security_task_id,\n scan_type,\n status_code\n FROM internal_platform_db.t_security_scan_span_prestosql_001\n WHERE databus_imp_date >= '2026060600'\n AND databus_imp_date <= '2026060800'\n AND trace_id IN (SELECT trace_id FROM base_trace)\n AND span_name IN ('scan.failed', 'scan.start', 'scan.execute', 'scan.cleanup', 'resource.allocate')\n\n UNION ALL\n\n SELECT\n trace_id,\n 'scan.completed' AS span_name,\n MAX(CASE WHEN span_name = 'scan.start' THEN start_time END) AS start_time,\n MAX(CASE WHEN span_name = 'scan.failed' THEN end_time END) AS end_time,\n MAX(CASE WHEN span_name = 'scan.failed' THEN security_project_id END) AS security_project_id,\n MAX(CASE WHEN span_name = 'scan.failed' THEN security_task_id END) AS security_task_id,\n MAX(CASE WHEN span_name = 'scan.failed' THEN scan_type END) AS scan_type,\n 2 AS status_code\n FROM internal_platform_db.t_security_scan_span_prestosql_001\n WHERE databus_imp_date >= '2026060600'\n AND databus_imp_date <= '2026060800'\n AND trace_id IN (SELECT trace_id FROM base_trace)\n AND span_name IN ('scan.start', 'scan.failed')\n GROUP BY trace_id\n),\nbase_data_time_fixed AS (\n SELECT\n trace_id,\n span_name,\n CASE\n WHEN span_name = 'scan.failed'\n THEN MIN(CASE WHEN span_name IN ('scan.execute', 'scan.failed') THEN start_time END)\n OVER(PARTITION BY trace_id)\n ELSE start_time\n END AS start_time,\n end_time,\n security_project_id,\n security_task_id,\n scan_type,\n status_code\n FROM combined_spans\n),\nbase_data AS (\n SELECT\n trace_id,\n span_name,\n start_time,\n end_time,\n security_project_id,\n security_task_id,\n scan_type,\n status_code,\n from_unixtime(CAST(start_time AS BIGINT) / 1000) AS start_date,\n from_unixtime(CAST(end_time AS BIGINT) / 1000) AS end_date,\n date_diff('day', from_unixtime(CAST(start_time AS BIGINT) / 1000), from_unixtime(CAST(end_time AS BIGINT) / 1000)) AS diff_days,\n CAST(CAST(start_time AS BIGINT) / 86400000 AS BIGINT) * 86400000 AS start_day_midnight_ms\n FROM base_data_time_fixed\n),\npos_series AS (\n SELECT 0 AS pos UNION ALL SELECT 1 AS pos UNION ALL SELECT 2 AS pos UNION ALL SELECT 3 AS pos\n),\ndaily_split_spans AS (\n SELECT\n b.trace_id,\n b.span_name,\n b.security_project_id,\n b.security_task_id,\n b.scan_type,\n b.status_code,\n b.start_date,\n b.end_date,\n b.diff_days,\n date_add('day', s.pos, b.start_date) AS calc_date,\n CASE WHEN s.pos = 0 THEN b.start_time\n ELSE CAST(b.start_day_midnight_ms + s.pos * 86400000 AS VARCHAR)\n END AS start_time,\n CASE WHEN s.pos = b.diff_days THEN b.end_time\n ELSE CAST(b.start_day_midnight_ms + (s.pos + 1) * 86400000 - 1 AS VARCHAR)\n END AS end_time,\n b.start_time AS span_start_time,\n b.end_time AS span_end_time\n FROM base_data b\n INNER JOIN pos_series s ON s.pos <= b.diff_days\n),\ntrace_time_metrics AS (\n SELECT\n t.trace_id,\n t.calc_date,\n MAX(t.security_project_id) AS security_project_id,\n MAX(t.security_task_id) AS security_task_id,\n MAX(t.scan_type) AS scan_type,\n MAX(MAX(CASE WHEN t.span_name = 'scan.completed' THEN t.status_code END)) OVER(PARTITION BY t.trace_id) AS status_code,\n CAST(ROUND((MAX(CASE WHEN t.span_name = 'scan.execute' THEN CAST(t.end_time AS BIGINT) END) -\n MIN(CASE WHEN t.span_name = 'scan.execute' THEN CAST(t.start_time AS BIGINT) END)) / 1000.0) AS INT) AS scan_run_time,\n CAST(ROUND((MAX(CASE WHEN t.span_name IN ('scan.execute', 'scan.cleanup') THEN CAST(t.end_time AS BIGINT) END) -\n MIN(CASE WHEN t.span_name IN ('scan.execute', 'scan.cleanup') THEN CAST(t.start_time AS BIGINT) END)) / 1000.0) AS INT) AS code_run_time,\n CAST(ROUND((MAX(CASE WHEN t.span_name = 'resource.allocate' THEN CAST(t.end_time AS BIGINT) END) -\n MIN(CASE WHEN t.span_name = 'resource.allocate' THEN CAST(t.start_time AS BIGINT) END)) / 1000.0) AS INT) AS resource_wait_time\n FROM daily_split_spans t\n GROUP BY t.trace_id, t.calc_date\n)\nSELECT\n date_format(t1.calc_date, '%Y-%m-%d') AS p_date,\n t1.trace_id,\n t1.security_project_id,\n t1.security_task_id,\n t1.scan_type,\n t1.status_code,\n t1.scan_run_time,\n t1.code_run_time,\n t1.resource_wait_time,\n t2.resource_id,\n CAST(t2.is_dedicated AS BOOLEAN) AS is_dedicated,\n t2.apply_for_cpu_count\nFROM trace_time_metrics t1\nLEFT JOIN (\n SELECT\n trace_id,\n MAX(resource_id) AS resource_id,\n MAX(is_dedicated) AS is_dedicated,\n MAX(cpu_cores) AS apply_for_cpu_count\n FROM internal_platform_db.t_security_resource_info_prestosql_001\n WHERE databus_imp_date >= '2026060600'\n AND databus_imp_date <= '2026060800'\n GROUP BY trace_id\n) t2 ON t1.trace_id = t2.trace_id\n;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_001"}
|
| 2 |
+
{"task_id": "prestosql_002_en", "id": "offline-compute_PrestoSQL_prestosql_002", "name": "Ad ASA Attribution Migration", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n**Task Objective**: From the ad attribution raw logs, filter valid records of two attribution types (ad_attribution and huawei), aggregate the log count and deduplicated user count by version and media dimensions, and write the results to the output table.\n\n**Input Table**:\n- `internal_platform_db.t_sh_event_log_v2_06000061157_prestosql_002` (ad attribution raw logs)\n - `ftime` STRING — time\n - `extinfo` STRING — extended information\n - `ad_version` STRING — ad version (ad_attribution/huawei)\n - `guid` STRING — user identifier\n - `ch` STRING — channel\n - `first_date` STRING — first date\n - `last_date` STRING — last date\n - `click_date` STRING — click date\n - `attribution` STRING — attribution flag\n - `conversion_date` STRING — conversion date\n - `conversion_type` STRING — conversion type\n - `creativeset_id` STRING — creative set ID\n - `org_id` STRING — organization ID\n - `campaign_id` STRING — campaign ID\n - `adgroup_id` STRING — ad group ID\n - `keyword_id` STRING — keyword ID\n - `country_oregion` STRING — country/region\n - `enter_ag_time` STRING — ad group entry time\n - `installed_finish_time` STRING — installation completion time\n - `start_download_time` STRING — download start time\n - `sub_channel` STRING — sub-channel\n - `callback` STRING — callback information\n - `task_id` STRING — task ID\n - `sub_task_id` STRING — sub-task ID\n - `rta_id` STRING — RTA identifier\n - `device_id` STRING — device_id identifier\n - `ext_info1` STRING — extended information 1\n - `ext_info2` STRING — extended information 2\n - `caid` STRING — CAID\n - `claim_type` STRING — claim type\n - `ai_assistant_device_id` STRING — YB device_id\n - `ds` STRING — partition field\n\n**Filter Conditions**:\n- `ds = '2026060919'`\n- Valid record condition: `(ad_version = 'ad_attribution' AND attribution = 'true') OR (ad_version = 'phonebrandh' AND callback != '')`\n\n**Output Requirements**:\n- Target table: `internal_platform_db.t_my_ads_tracking_log_metrics_cand_prestosql_002`\n- Output fields and order: `ds` BIGINT, `ad_version` STRING, `media_id` INT, `log_num` BIGINT, `log_num_qimei` BIGINT\n- `ds`: Cast the original table's `ds` field to BIGINT\n- `media_id`: `CASE ad_version WHEN 'ad_attribution' THEN 39 WHEN 'phonebrandh' THEN 28 END`\n- `log_num`: `COUNT(*)` log count\n- `log_num_qimei`: `COUNT(DISTINCT device_id)` deduplicated user count\n- Group by `ds`, `ad_version`\n- If the target table does not exist, first create the table, then write the data\n- Use Presto/Trino SQL syntax; do not use Hive/Spark SQL dialects\n\n**Environment and Execution Notes**:\n- Presto is running, connected via the Hive catalog\n- Execute SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- After writing `result.sql`, you must execute it yourself to verify that it runs successfully and produces correct data", "ground_truth": "INSERT OVERWRITE TABLE internal_platform_db.t_my_ads_tracking_log_metrics_prestosql_002\nSELECT\n CAST(ds AS BIGINT) AS ds,\n ad_version,\n CASE ad_version WHEN 'ad_attribution' THEN 39 WHEN 'phonebrandh' THEN 28 END AS media_id,\n COUNT(*) AS log_num,\n COUNT(DISTINCT device_id) AS log_num_qimei\nFROM internal_platform_db.t_sh_event_log_v2_06000061157_prestosql_002\nWHERE ds = '2026060919'\n AND ((ad_version = 'ad_attribution' AND attribution = 'true')\n OR (ad_version = 'phonebrandh' AND callback != ''))\nGROUP BY ds, ad_version", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_002_en"}
|
| 3 |
+
{"task_id": "prestosql_003", "id": "offline-compute_PrestoSQL_prestosql_003", "name": "IM平台Q群离线报告子分区过滤", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n**任务目标**:从IM平台Q群离线报告原始日志中,筛选指定appid下包含\"诈骗\"标签的记录,提取关键字段写入输出表。\n\n**输入表**:\n- `internal_platform_db.dwd_t_event_log_v1_05900072467_with_subpartition_hi_prestosql_003`(IM平台Q群离线报告原始日志)\n - `databus_imp_date` STRING — 数据日期\n - `ftime` STRING — 时间\n - `appid` STRING — 应用ID\n - `message_id` STRING — 消息ID\n - `reqbody` STRING — 请求体(JSON)\n - `content` STRING — 内容\n - `model_id` STRING — 模型ID\n - `group_num` STRING — 群号\n - `punish_path_name` STRING — 处罚路径名称\n - `ext_field1` STRING — 扩展字段1\n - `ext_field2` STRING — 扩展字段2\n - `ds` BIGINT — 分区字段\n\n**过滤条件**:\n- `appid = '100553'`\n- `reqbody IS NOT NULL`\n- `get_json_object(reqbody, '$.tag_info') IS NOT NULL`\n- `get_json_object(reqbody, '$.tag_info.tag_result_text') LIKE '%诈骗-%'`\n- `ftime = '20250324'`\n\n**输出要求**:\n- 目标表: `internal_platform_db.dwd_qqgroup_offline_report_cand_prestosql_003`\n- 输出字段及顺序: `ftime` STRING, `appid` STRING, `model_id` STRING, `message_id` STRING, `databus_imp_date` STRING, `group_num` STRING, `punish_path_name` STRING, `content` STRING\n- appid 固定值 '101069'\n- model_id 固定值 'IM平台Qgroup_zhapian_report_1049'\n- 如果目标表不存在,请先建表再写入数据\n- 请使用Presto/Trino SQL语法,不要使用Hive/Spark SQL方言\n- 注意:Presto中使用json_extract_scalar代替get_json_object\n\n**环境与执行说明**:\n- Presto已启动,通过Hive catalog连接\n- 执行SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- 写出result.sql后,必须自己执行验证它能成功运行并产出正确数据", "ground_truth": "INSERT OVERWRITE TABLE internal_platform_db.dwd_qqgroup_offline_report_prestosql_003\nSELECT\n ftime,\n '101069' AS appid,\n 'IM平台Qgroup_zhapian_report_1049' AS model_id,\n message_id,\n databus_imp_date,\n group_num,\n punish_path_name,\n content\nFROM internal_platform_db.dwd_t_event_log_v1_05900072467_with_subpartition_hi_prestosql_003\nWHERE appid = '100553'\n AND reqbody IS NOT NULL\n AND get_json_object(reqbody, '$.tag_info') IS NOT NULL\n AND get_json_object(reqbody, '$.tag_info.tag_result_text') LIKE '%诈骗-%'\n AND ftime = '20250324'", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_003"}
|
| 4 |
+
{"task_id": "prestosql_004", "id": "offline-compute_PrestoSQL_prestosql_004", "name": "小说UDS算法书籍关系筛选", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n**任务目标**:从小说UDS算法书籍关系表中,筛选指定事件类型的记录,根据事件类型映射为操作类型,提取关键字段写入输出表。\n\n**输入表**:\n- `internal_platform_db.t_oh_novel_uds_algorithm_book_rel_prestosql_004`(小说UDS算法书籍关系表)\n - `ftime` STRING — 时间\n - `event_code` STRING — 事件编码\n - `book_id` STRING — 书籍ID\n - `guid` STRING — 用户标识\n - `reqid` STRING — 请求ID\n - `traceid` STRING — 追踪ID\n - `report_time` STRING — 上报时间\n - `ds` BIGINT — 分区字段\n\n**过滤条件**:\n- `ds = 2026060906`\n- `length(book_id) = 10`\n- `event_code IN ('expose', 'click', 'real_read', 'add_0', 'add_1', 'shelf_add', 'share', 'comment', 'like')`\n\n**输出要求**:\n- 目标表: `internal_platform_db.t_od_novel_user_action_detail_cand_prestosql_004`\n- 输出字段及顺序: `reqid` STRING, `guid` STRING, `bookid` STRING, `traceid` STRING, `action` STRING, `ftime` STRING, `report_time` STRING\n- action: CASE event_code WHEN 'expose' THEN 'expose' WHEN 'click' THEN 'click' WHEN 'real_read' THEN 'real_read' WHEN 'add_0' THEN 'add_0' WHEN 'add_1' THEN 'add_1' ELSE event_code END\n- bookid: book_id\n- traceid: substr(traceid, 1, 4)\n- 如果目标表不存在,请先建表再写入数据\n- 请使用Presto/Trino SQL语法,不要使用Hive/Spark SQL方言\n\n**环境与执行说明**:\n- Presto已启动,通过Hive catalog连接\n- 执行SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- 写出result.sql后,必须自己执行验证它能成功运行并产出正确数据", "ground_truth": "INSERT OVERWRITE TABLE internal_platform_db.t_od_novel_user_action_detail_prestosql_004\nSELECT\n reqid,\n guid,\n book_id AS bookid,\n substr(traceid, 1, 4) AS traceid,\n CASE event_code\n WHEN 'expose' THEN 'expose'\n WHEN 'click' THEN 'click'\n WHEN 'real_read' THEN 'real_read'\n WHEN 'add_0' THEN 'add_0'\n WHEN 'add_1' THEN 'add_1'\n ELSE event_code\n END AS action,\n ftime,\n report_time\nFROM internal_platform_db.t_oh_novel_uds_algorithm_book_rel_prestosql_004\nWHERE ds = 2026060906\n AND length(book_id) = 10\n AND event_code IN ('expose', 'click', 'real_read', 'add_0', 'add_1', 'shelf_add', 'share', 'comment', 'like')", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_004"}
|
| 5 |
+
{"task_id": "prestosql_005_en", "id": "offline-compute_PrestoSQL_prestosql_005", "name": "Hot Table Governance Metadata Wide Table Aggregation", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n**Task Objective**: From the hot table governance metadata detail table, filter valid hot table records (heat > 0, excluding temporary/test tables), aggregate by database name and table name to take the maximum of each metric, and write the results to the output table.\n\n**Input Table**:\n- `internal_platform_db.ads_gov_cost_table_govern_detail_df_prestosql_005` (hot table governance metadata detail table)\n - `imp_date` BIGINT — date partition\n - `db_name` STRING — database name\n - `table_name` STRING — table name\n - `heat` BIGINT — heat\n - `owner` STRING — owner\n - `storage_detail` DOUBLE — storage detail\n - `task_cnt` BIGINT — task count\n - `table_type` STRING — table type\n - `govern_status` STRING — governance status\n - `last_access_time` STRING — last access time\n - `table_comment` STRING — table comment\n - `partition_cnt` BIGINT — partition count\n - `file_format` STRING — file format\n - `table_size` DOUBLE — table size\n - `avg_file_size` DOUBLE — average file size\n - `is_partitioned` INT — whether partitioned\n - `lifecycle_days` INT — lifecycle days\n - `create_time` STRING — creation time\n - `modify_time` STRING — modification time\n - `project_name` STRING — project name\n\n**Filter Conditions**:\n- `imp_date = 20260507`\n- `heat > 0`\n- `table_name NOT LIKE '%temp%'`\n- `db_name NOT LIKE '%test%'`\n\n**Output Requirements**:\n- Target table: `internal_platform_db.dwd_hot_metadata_table_cand_prestosql_005`\n- Output fields and order: `dt` STRING, `db_name` STRING, `table_name` STRING, `owner` STRING, `storage_detail` DOUBLE, `heat` BIGINT, `task_cnt` BIGINT, `table_type` STRING, `govern_status` STRING, `last_access_time` STRING, `table_comment` STRING, `partition_cnt` BIGINT, `file_format` STRING, `table_size` DOUBLE, `avg_file_size` DOUBLE, `is_partitioned` INT, `lifecycle_days` INT, `create_time` STRING, `modify_time` STRING, `project_name` STRING\n- `dt`: Fixed value `'20260507'`\n- Group by `db_name`, `table_name`, apply `MAX()` to all other fields\n- If the target table does not exist, first create the table, then write the data\n- Use Presto/Trino SQL syntax; do not use Hive/Spark SQL dialects\n\n**Environment and Execution Notes**:\n- Presto is running, connected via the Hive catalog\n- Execute SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- After writing `result.sql`, you must execute it yourself to verify that it runs successfully and produces correct data", "ground_truth": "INSERT OVERWRITE TABLE internal_platform_db.dwd_hot_metadata_table_prestosql_005\nSELECT\n '20260507' AS dt,\n db_name,\n table_name,\n MAX(owner) AS owner,\n MAX(storage_detail) AS storage_detail,\n MAX(heat) AS heat,\n MAX(task_cnt) AS task_cnt,\n MAX(table_type) AS table_type,\n MAX(govern_status) AS govern_status,\n MAX(last_access_time) AS last_access_time,\n MAX(table_comment) AS table_comment,\n MAX(partition_cnt) AS partition_cnt,\n MAX(file_format) AS file_format,\n MAX(table_size) AS table_size,\n MAX(avg_file_size) AS avg_file_size,\n MAX(is_partitioned) AS is_partitioned,\n MAX(lifecycle_days) AS lifecycle_days,\n MAX(create_time) AS create_time,\n MAX(modify_time) AS modify_time,\n MAX(project_name) AS project_name\nFROM internal_platform_db.ads_gov_cost_table_govern_detail_df_prestosql_005\nWHERE imp_date = 20260507\n AND heat > 0\n AND table_name NOT LIKE '%temp%'\n AND db_name NOT LIKE '%test%'\nGROUP BY db_name, table_name", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_005_en"}
|
| 6 |
+
{"task_id": "prestosql_006_en", "id": "offline-compute_PrestoSQL_prestosql_006", "name": "News Plugin Send Process Multi-Dimensional Aggregation", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n**Task Objective**: From the news plugin send process flow table, aggregate and compute metrics such as send count, send UV, panel exposure count, panel exposure UV, inner-page PV, and inner-page UV by the scene (`pos_desc`) dimension, across two time windows — current day and last 1 hour — and write the results to the output table.\n\n**Input Table**:\n- `internal_platform_db.dwm_news_plugin_ai_assistant_send_process_flow_hi_prestosql_006` (news plugin send process flow table)\n - `imp_hour` BIGINT — hourly partition\n - `user_id` STRING — user ID\n - `content_id` STRING — content ID\n - `push_id` STRING — push ID\n - `pos` STRING — position\n - `send_cnt` BIGINT — send count\n - `panel_exp_cnt` BIGINT — panel exposure count\n - `pgin_pv` BIGINT — inner-page PV\n - `pos_desc` STRING — position description (scene)\n - `account_code` STRING — business code\n\n**Output Requirements**:\n- Target table: `internal_platform_db.ads_news_plugin_ai_assistant_hourly_report_cand_prestosql_006`\n- Output fields and order:\n - `imp_hour` BIGINT — hourly partition\n - `scene` STRING — scene (`pos_desc`)\n - `send_cnt_dth` BIGINT — current day send count (`SUM(send_cnt) WHERE imp_hour <= current hour`)\n - `send_uv_dth` BIGINT — current day send UV (`COUNT(DISTINCT user_id) WHERE imp_hour <= current hour`)\n - `panel_exp_cnt_dth` BIGINT — current day panel exposure count (`SUM(panel_exp_cnt) WHERE imp_hour <= current hour`)\n - `panel_exp_uv_dth` BIGINT — current day panel exposure UV (`COUNT(DISTINCT user_id) WHERE panel_exp_cnt > 0 AND imp_hour <= current hour`)\n - `pgin_pv_dth` BIGINT — current day inner-page PV (`SUM(pgin_pv) WHERE imp_hour <= current hour`)\n - `pgin_uv_dth` BIGINT — current day inner-page UV (`COUNT(DISTINCT user_id) WHERE pgin_pv > 0 AND imp_hour <= current hour`)\n - `send_cnt_1h` BIGINT — last 1 hour send count (`SUM(send_cnt) WHERE imp_hour = current hour`)\n - `send_uv_1h` BIGINT — last 1 hour send UV\n - `panel_exp_cnt_1h` BIGINT — last 1 hour panel exposure count\n - `panel_exp_uv_1h` BIGINT — last 1 hour panel exposure UV\n - `pgin_pv_1h` BIGINT — last 1 hour inner-page PV\n - `pgin_uv_1h` BIGINT — last 1 hour inner-page UV\n\n- Simplified explanation: For each `imp_hour` + `pos_desc` combination, compute the current day cumulative (dth) and current hour (1h) aggregation metrics\n- If the target table does not exist, first create the table, then write the data\n- Use Presto/Trino SQL syntax; do not use Hive/Spark SQL dialects\n\n**Environment and Execution Notes**:\n- Presto is running, connected via the Hive catalog\n- Execute SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- After writing `result.sql`, you must execute it yourself to verify that it runs successfully and produces correct data", "ground_truth": "INSERT OVERWRITE TABLE internal_platform_db.ads_news_plugin_ai_assistant_hourly_report_prestosql_006\nSELECT\n h.imp_hour,\n h.pos_desc AS scene,\n h.send_cnt_dth,\n h.send_uv_dth,\n h.panel_exp_cnt_dth,\n h.panel_exp_uv_dth,\n h.pgin_pv_dth,\n h.pgin_uv_dth,\n h.send_cnt_1h,\n h.send_uv_1h,\n h.panel_exp_cnt_1h,\n h.panel_exp_uv_1h,\n h.pgin_pv_1h,\n h.pgin_uv_1h\nFROM (\n SELECT\n t1.imp_hour,\n t1.pos_desc,\n t1.send_cnt AS send_cnt_dth,\n t1.send_uv AS send_uv_dth,\n t1.panel_exp_cnt AS panel_exp_cnt_dth,\n t1.panel_exp_uv AS panel_exp_uv_dth,\n t1.pgin_pv AS pgin_pv_dth,\n t1.pgin_uv AS pgin_uv_dth,\n t2.send_cnt AS send_cnt_1h,\n t2.send_uv AS send_uv_1h,\n t2.panel_exp_cnt AS panel_exp_cnt_1h,\n t2.panel_exp_uv AS panel_exp_uv_1h,\n t2.pgin_pv AS pgin_pv_1h,\n t2.pgin_uv AS pgin_uv_1h\n FROM (\n SELECT\n a.imp_hour,\n a.pos_desc,\n SUM(b.send_cnt) AS send_cnt,\n COUNT(DISTINCT b.user_id) AS send_uv,\n SUM(b.panel_exp_cnt) AS panel_exp_cnt,\n COUNT(DISTINCT CASE WHEN b.panel_exp_cnt > 0 THEN b.user_id END) AS panel_exp_uv,\n SUM(b.pgin_pv) AS pgin_pv,\n COUNT(DISTINCT CASE WHEN b.pgin_pv > 0 THEN b.user_id END) AS pgin_uv\n FROM (SELECT DISTINCT imp_hour, pos_desc FROM internal_platform_db.dwm_news_plugin_ai_assistant_send_process_flow_hi_prestosql_006) a\n JOIN internal_platform_db.dwm_news_plugin_ai_assistant_send_process_flow_hi_prestosql_006 b\n ON a.pos_desc = b.pos_desc AND b.imp_hour <= a.imp_hour\n GROUP BY a.imp_hour, a.pos_desc\n ) t1\n JOIN (\n SELECT\n imp_hour,\n pos_desc,\n SUM(send_cnt) AS send_cnt,\n COUNT(DISTINCT user_id) AS send_uv,\n SUM(panel_exp_cnt) AS panel_exp_cnt,\n COUNT(DISTINCT CASE WHEN panel_exp_cnt > 0 THEN user_id END) AS panel_exp_uv,\n SUM(pgin_pv) AS pgin_pv,\n COUNT(DISTINCT CASE WHEN pgin_pv > 0 THEN user_id END) AS pgin_uv\n FROM internal_platform_db.dwm_news_plugin_ai_assistant_send_process_flow_hi_prestosql_006\n GROUP BY imp_hour, pos_desc\n ) t2 ON t1.imp_hour = t2.imp_hour AND t1.pos_desc = t2.pos_desc\n) h", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_006_en"}
|
| 7 |
+
{"task_id": "prestosql_007_en", "id": "offline-compute_PrestoSQL_prestosql_007", "name": "APK Threat Scan Instance GPU Card-Hour 5-Minute Window Statistics", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n**Task Objective**: Compute the GPU card-hour consumption of APK scan instances, aggregated by 5-minute time windows, joining with Pod mapping and task instance GPU configuration information, and write the results to the output table.\n\n**Input Tables**:\n- `internal_platform_db.t_gpu_monitor_parsed_prestosql_007` (GPU monitoring data table)\n - `container` STRING — container name\n - `pod_name` STRING — Pod name\n - `pkg_time` STRING — reporting time (epoch second string)\n - `gpu_name` STRING — GPU model\n - `metric` STRING — metric name\n - `value` STRING — metric value\n - `dt` STRING — partition field (format `'2026060800'`)\n\n- `internal_platform_db.dwd_scan_instance_podname_prestosql_007` (Pod-to-scan-instance mapping table)\n - `dt` STRING — partition field\n - `instance_uuid` STRING — instance unique identifier\n - `pod_name` STRING — Pod name\n - `pod_phase` STRING — Pod phase\n - `namespace` STRING — namespace\n\n- `internal_platform_db.dwd_scan_task_instance_prestosql_007` (task instance GPU configuration table 1)\n - `databus_imp_date` STRING — partition field\n - `instance_uuid` STRING — instance unique identifier\n - `host_gpu_num` DOUBLE — host GPU card count\n - `host_num` DOUBLE — host count\n - `last_modify` DOUBLE — last modification timestamp\n - `gpu_name` STRING — GPU model\n\n- `internal_platform_db.scan_task_instance_prestosql_007` (scan task instance GPU configuration table 2)\n - `databus_imp_date` STRING — partition field\n - `instance_uuid` STRING — instance unique identifier\n - `host_gpu_num` DOUBLE — host GPU card count\n - `host_num` DOUBLE — host count\n - `last_modify` DOUBLE — last modification timestamp\n - `gpu_name` STRING — GPU model\n - `scan_type` STRING — scan type\n\n**Computation Logic**:\n1. Filter specified metrics from the GPU monitoring data, and compute runtime per Pod in 5-minute time windows\n2. Join with the Pod-to-instance mapping to aggregate the GPU runtime and Pod count per instance per 5-minute window\n3. Retrieve the latest GPU configuration information for each task instance\n4. Compute the GPU card-hours (GPU-hour) per instance per 5-minute window\n5. The specific time window bucketing method, join conditions, aggregation logic, and GPU-hour computation formula must be determined based on the table structures and business semantics\n\n**Output Requirements**:\n- Target table: `internal_platform_db.t_scan_instance_gpu_time_stats_cand_prestosql_007`\n- Output fields and order: `instance_uuid` STRING, `time_5min` BIGINT, `host_gpu_num` DOUBLE, `sum_run_time_m` DOUBLE, `gpu_hour` DOUBLE, `gpu_name` STRING, `pod_count` BIGINT, `host_num` DOUBLE\n- If the target table does not exist, first create the table, then write the data\n- Use Presto/Trino SQL syntax; do not use Hive/Spark SQL dialects\n\n**Environment and Execution Notes**:\n- Presto is running, connected via the Hive catalog\n- Execute SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- After writing `result.sql`, you must execute it yourself to verify that it runs successfully and produces correct data", "ground_truth": "INSERT INTO internal_platform_db.t_scan_instance_gpu_time_stats_prestosql_007\nWITH\n-- Step 1: From GPU monitoring data, extract pod run records with minute-level dedup\npod_run_minutes AS (\n SELECT\n pod_name,\n gpu_name,\n FLOOR(CAST(pkg_time AS BIGINT) / 60) * 60 AS minute_timestamp,\n FLOOR(CAST(pkg_time AS BIGINT) / 300) * 300 AS time_5min\n FROM internal_platform_db.t_gpu_monitor_parsed_prestosql_007\n WHERE dt = '2026060800'\n AND metric IN ('k8s_container_vgpu_gpu_mem_usage', 'k8s_dcgm_fi_dev_fb_util')\n GROUP BY pod_name, gpu_name, FLOOR(CAST(pkg_time AS BIGINT) / 60) * 60, FLOOR(CAST(pkg_time AS BIGINT) / 300) * 300\n),\n\n-- Step 2: Aggregate run minutes per pod per 5-minute window\npod_run_time AS (\n SELECT\n pod_name,\n MAX(gpu_name) AS gpu_name,\n time_5min,\n CAST(COUNT(DISTINCT minute_timestamp) AS DOUBLE) AS run_time_m\n FROM pod_run_minutes\n GROUP BY pod_name, time_5min\n),\n\n-- Step 3: Join pod-to-instance mapping, aggregate per instance per window\ninstance_run_time AS (\n SELECT\n p.time_5min,\n m.instance_uuid,\n MAX(p.gpu_name) AS gpu_name,\n CAST(SUM(p.run_time_m) AS DOUBLE) AS sum_run_time_m,\n COUNT(DISTINCT m.pod_name) AS pod_count\n FROM pod_run_time p\n INNER JOIN internal_platform_db.dwd_scan_instance_podname_prestosql_007 m\n ON p.pod_name = m.pod_name\n AND m.dt = '2026060800'\n GROUP BY p.time_5min, m.instance_uuid\n),\n\n-- Step 4: Get latest GPU config per instance from dual-table UNION ALL + ROW_NUMBER dedup\nlatest_task_config AS (\n SELECT\n instance_uuid,\n CAST(host_gpu_num AS DOUBLE) AS host_gpu_num,\n CAST(host_num AS DOUBLE) AS host_num,\n gpu_name\n FROM (\n SELECT\n instance_uuid,\n host_gpu_num,\n host_num,\n gpu_name,\n last_modify,\n ROW_NUMBER() OVER (PARTITION BY instance_uuid ORDER BY last_modify DESC) AS rn\n FROM (\n SELECT\n instance_uuid,\n host_gpu_num,\n host_num,\n gpu_name,\n last_modify\n FROM internal_platform_db.dwd_scan_task_instance_prestosql_007\n WHERE databus_imp_date = (\n SELECT MAX(databus_imp_date)\n FROM internal_platform_db.dwd_scan_task_instance_prestosql_007\n )\n\n UNION ALL\n\n SELECT\n instance_uuid,\n host_gpu_num,\n host_num,\n gpu_name,\n last_modify\n FROM internal_platform_db.scan_task_instance_prestosql_007\n WHERE databus_imp_date = (\n SELECT MAX(databus_imp_date)\n FROM internal_platform_db.scan_task_instance_prestosql_007\n )\n ) combined\n ) ranked\n WHERE rn = 1\n)\n\n-- Step 5: Join instance run time with GPU config, compute GPU-hour\nSELECT\n i.instance_uuid,\n i.time_5min,\n t.host_gpu_num,\n i.sum_run_time_m,\n CASE\n WHEN t.host_gpu_num IS NOT NULL AND i.sum_run_time_m IS NOT NULL\n THEN t.host_gpu_num * i.sum_run_time_m / 60.0\n ELSE NULL\n END AS gpu_hour,\n i.gpu_name,\n i.pod_count,\n t.host_num\nFROM instance_run_time i\nLEFT JOIN latest_task_config t\n ON i.instance_uuid = t.instance_uuid\n;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_007_en"}
|
| 8 |
+
{"task_id": "prestosql_008_en", "id": "offline-compute_PrestoSQL_prestosql_008", "name": "Report WUID Detail Filtering", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n**Task Objective**: From the ad report WUID detail wide table, filter target ad delivery records based on multi-dimensional filter conditions, extract key fields, and write the results to the output table.\n\n**Input Table**:\n- `internal_platform_db.t_report_wuid_detail_d_prestosql_008` (report WUID detail table)\n - `wuid` STRING — user identifier\n - `product_id` STRING — product ID\n - `adgroup_id` BIGINT — ad group ID\n - `action_time` BIGINT — action time\n - `crm_id` BIGINT — CRM ID\n - `creative_id` BIGINT — creative ID\n - `ocpx_conversion_cnt` BIGINT — oCpx conversion count\n - `optimization_goal` INT — optimization goal\n - `second_optimization_goal` INT — second-level optimization goal\n - `roi_goal` INT — ROI goal\n - `product_type` INT — product type\n - `site_set` INT — site set\n - `crm_advertiser_industry_id` BIGINT — CRM advertiser industry ID\n - `label` INT — label\n - `partition_time` BIGINT — partition time\n - `ds` BIGINT — partition field\n\n**Filter Conditions**:\n- `partition_time = 20260608`\n- `ocpx_conversion_cnt = 0`\n- `optimization_goal IN (105, 603)`\n- `second_optimization_goal = 0`\n- `roi_goal = 7`\n- `product_type = 46`\n- `site_set = 21`\n- `product_id IS NOT NULL`\n- `crm_advertiser_industry_id != 0`\n- `creative_id != 0`\n\n**Output Requirements**:\n- Target table: `internal_platform_db.sdk_sample_pay_neg_mini_cand_prestosql_008`\n- Output fields and order: `wuid` STRING, `product_id` STRING, `adgroup_id` BIGINT, `action_time` BIGINT, `crm_id` BIGINT, `creative_id` BIGINT, `label` INT, `product_type` INT, `optimization_goal` INT, `roi_goal` INT, `partition_time` BIGINT\n- If the target table does not exist, first create the table, then write the data\n- Use Presto/Trino SQL syntax; do not use Hive/Spark SQL dialects\n\n**Environment and Execution Notes**:\n- Presto is running, connected via the Hive catalog\n- Execute SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- After writing `result.sql`, you must execute it yourself to verify that it runs successfully and produces correct data", "ground_truth": "INSERT OVERWRITE TABLE internal_platform_db.sdk_sample_pay_neg_mini_prestosql_008\nSELECT\n wuid,\n product_id,\n adgroup_id,\n action_time,\n crm_id,\n creative_id,\n label,\n product_type,\n optimization_goal,\n roi_goal,\n partition_time\nFROM internal_platform_db.t_report_wuid_detail_d_prestosql_008\nWHERE partition_time = 20260608\n AND ocpx_conversion_cnt = 0\n AND optimization_goal IN (105, 603)\n AND second_optimization_goal = 0\n AND roi_goal = 7\n AND product_type = 46\n AND site_set = 21\n AND product_id IS NOT NULL\n AND crm_advertiser_industry_id != 0\n AND creative_id != 0", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_008_en"}
|
| 9 |
+
{"task_id": "prestosql_009", "id": "offline-compute_PrestoSQL_prestosql_009", "name": "Data Pipeline Killed Instance Analysis", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\nJoin pipeline span info and resource info tables to produce killed instance detail table. Specific filtering conditions and field selection need to be determined based on table structure.\n\n**输入表**:\n- `internal_platform_db.t_pipeline_span_info_prestosql_009`(Pipeline span信息表)\n - `databus_imp_date` STRING — 日期分区\n - `trace_id` STRING — 链路标识\n - `span_name` STRING — span名称\n - `start_time` STRING — 开始时间(epoch毫秒)\n - `end_time` STRING — 结束时间(epoch毫秒)\n - `status_code` INT — 状态码\n - `project_id` STRING — 项目ID\n - `task_id` STRING — 任务ID\n - `compute_type` STRING — 计算类型\n\n- `internal_platform_db.t_pipeline_resource_info_prestosql_009`(Pipeline资源信息表)\n - `databus_imp_date` STRING — 日期分区\n - `trace_id` STRING — 链路标识\n - `compute_type` STRING — 计算类型\n - `resource_id` STRING — 资源ID\n - `is_dedicated` STRING — 是否独占\n - `cpu_cores` INT — CPU核数\n\n**输出要求**:\n- 目标表: `internal_platform_db.t_pipeline_killed_instance_detail_cand_prestosql_009`\n- 具体过滤条件、字段选择、计算逻辑需根据表结构和数据特征自行分析确定\n- 如果目标表不存在,请先建表再写入数据\n- 请使用Presto/Trino SQL语法,不要使用Hive/Spark SQL方言\n\n**环境与执行说明**:\n- Presto已启动,通过Hive catalog连接\n- 执行SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- 写出result.sql后,必须自己执行验证它能成功运行并产出正确数据", "ground_truth": "INSERT INTO internal_platform_db.t_pipeline_killed_instance_detail_prestosql_009\nWITH base_trace AS (\n SELECT trace_id\n FROM internal_platform_db.t_pipeline_span_info_prestosql_009\n WHERE databus_imp_date = '20260608'\n AND span_name IN ('pipeline.execute', 'pipeline.killed')\n GROUP BY trace_id\n HAVING\n COUNT(CASE WHEN span_name = 'pipeline.killed' THEN 1 END) > 0\n AND\n COUNT(CASE WHEN span_name = 'pipeline.execute' THEN 1 END) = 0\n),\ncombined_spans AS (\n SELECT\n trace_id,\n span_name,\n start_time,\n end_time,\n project_id,\n task_id,\n compute_type,\n status_code\n FROM internal_platform_db.t_pipeline_span_info_prestosql_009\n WHERE databus_imp_date = '20260608'\n AND trace_id IN (SELECT trace_id FROM base_trace)\n AND span_name IN ('pipeline.killed', 'pipeline.start', 'task.run', 'task.compile', 'resource.request')\n\n UNION ALL\n\n SELECT\n trace_id,\n 'pipeline.execute' AS span_name,\n MAX(CASE WHEN span_name = 'pipeline.start' THEN start_time END) AS start_time,\n MAX(CASE WHEN span_name = 'pipeline.killed' THEN end_time END) AS end_time,\n MAX(CASE WHEN span_name = 'pipeline.killed' THEN project_id END) AS project_id,\n MAX(CASE WHEN span_name = 'pipeline.killed' THEN task_id END) AS task_id,\n MAX(CASE WHEN span_name = 'pipeline.killed' THEN compute_type END) AS compute_type,\n 2 AS status_code\n FROM internal_platform_db.t_pipeline_span_info_prestosql_009\n WHERE databus_imp_date = '20260608'\n AND trace_id IN (SELECT trace_id FROM base_trace)\n AND span_name IN ('pipeline.start', 'pipeline.killed')\n GROUP BY trace_id\n),\nbase_data_time_fixed AS (\n SELECT\n trace_id,\n span_name,\n CASE\n WHEN span_name = 'pipeline.killed'\n THEN MIN(CASE WHEN span_name IN ('task.run', 'pipeline.killed') THEN start_time END)\n OVER(PARTITION BY trace_id)\n ELSE start_time\n END AS start_time,\n end_time,\n project_id,\n task_id,\n compute_type,\n status_code\n FROM combined_spans\n),\nbase_data AS (\n SELECT\n trace_id,\n span_name,\n start_time,\n end_time,\n project_id,\n task_id,\n compute_type,\n status_code,\n from_unixtime(CAST(start_time AS BIGINT) / 1000) AS start_date,\n from_unixtime(CAST(end_time AS BIGINT) / 1000) AS end_date,\n date_diff('day', CAST(from_unixtime(CAST(start_time AS BIGINT) / 1000) AS TIMESTAMP), CAST(from_unixtime(CAST(end_time AS BIGINT) / 1000) AS TIMESTAMP)) AS diff_days\n FROM base_data_time_fixed\n),\npos_series AS (\n SELECT 0 AS pos UNION ALL SELECT 1 AS pos UNION ALL SELECT 2 AS pos UNION ALL SELECT 3 AS pos\n),\ndaily_split_spans AS (\n SELECT\n trace_id,\n span_name,\n project_id,\n task_id,\n compute_type,\n status_code,\n start_date,\n end_date,\n diff_days,\n CAST(date_add('day', s.pos, CAST(b.start_date AS TIMESTAMP)) AS VARCHAR) AS calc_date,\n CASE WHEN s.pos = 0 THEN b.start_time\n ELSE CAST(CAST(to_unixtime(CAST(date_add('day', s.pos, CAST(b.start_date AS TIMESTAMP)) AS TIMESTAMP)) AS BIGINT) * 1000 AS VARCHAR)\n END AS start_time,\n CASE WHEN s.pos = b.diff_days THEN b.end_time\n ELSE CAST(CAST(to_unixtime(CAST(date_add('day', s.pos + 1, CAST(b.start_date AS TIMESTAMP)) AS TIMESTAMP)) AS BIGINT) * 1000 - 1 AS VARCHAR)\n END AS end_time,\n b.start_time AS span_start_time,\n b.end_time AS span_end_time\n FROM base_data b\n INNER JOIN pos_series s ON s.pos <= b.diff_days\n),\ntrace_time_metrics AS (\n SELECT\n trace_id,\n calc_date,\n MAX(project_id) AS project_id,\n MAX(task_id) AS task_id,\n MAX(compute_type) AS compute_type,\n MAX(MAX(CASE WHEN span_name = 'pipeline.execute' THEN status_code END)) OVER(PARTITION BY trace_id) AS status_code,\n CAST(ROUND((MAX(CASE WHEN span_name = 'pipeline.execute' THEN CAST(end_time AS BIGINT) END) -\n MIN(CASE WHEN span_name = 'pipeline.execute' THEN CAST(start_time AS BIGINT) END)) / 1000.0) AS INT) AS instance_run_time,\n CAST(ROUND((MAX(CASE WHEN span_name IN ('task.run', 'task.compile', 'pipeline.killed') THEN CAST(end_time AS BIGINT) END) -\n MIN(CASE WHEN span_name IN ('task.run', 'task.compile', 'pipeline.killed') THEN CAST(start_time AS BIGINT) END)) / 1000.0) AS INT) AS code_run_time,\n CAST(ROUND((MAX(CASE WHEN span_name = 'resource.request' THEN CAST(end_time AS BIGINT) END) -\n MIN(CASE WHEN span_name = 'resource.request' THEN CAST(start_time AS BIGINT) END)) / 1000.0) AS INT) AS resource_wait_time\n FROM daily_split_spans\n GROUP BY trace_id, calc_date\n)\nSELECT\n t1.calc_date AS p_date,\n t1.trace_id,\n t1.project_id,\n t1.task_id,\n t1.compute_type,\n t1.status_code,\n t1.instance_run_time,\n t1.code_run_time,\n t1.resource_wait_time,\n t2.resource_id,\n CAST(t2.is_dedicated AS BOOLEAN) AS is_dedicated\nFROM trace_time_metrics t1 LEFT JOIN (\n SELECT\n trace_id,\n MAX(resource_id) AS resource_id,\n MAX(is_dedicated) AS is_dedicated\n FROM internal_platform_db.t_pipeline_resource_info_prestosql_009\n WHERE databus_imp_date = '20260608'\n GROUP BY trace_id\n) t2 ON t1.trace_id = t2.trace_id\n;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_009"}
|
| 10 |
+
{"task_id": "prestosql_010", "id": "offline-compute_PrestoSQL_prestosql_010", "name": "IOC MTTD指标计算", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n**任务目标**:从API指标表和威胁情报IOC表中,通过JSON解析提取IOC值,与IOC表关联计算MTTD(平均检测时间)指标,写入输出表。\n\n**输入表**:\n- `internal_platform_db.t_app_ti_entity_api_metrics_prod_hi_prestosql_010`(API指标表)\n - `timestamp` BIGINT — 时间戳\n - `username` STRING — 用户名\n - `appid` BIGINT — 应用ID\n - `path` STRING — 路径\n - `request` STRING — 请求体(JSON)\n - `response` STRING — 响应体\n - `ds` BIGINT — 分区字段\n\n- `internal_platform_db.t_sh_threat_intel_lab_breakingti_soc_endpoint_security_format_output_prod_prestosql_010`(威胁情报IOC表)\n - `ioctype` STRING — IOC类型\n - `ioc` STRING — IOC值\n - `port` STRING — 端口\n - `producer` STRING — 生产者\n - `stamp` STRING — 时间戳\n - `category` STRING — 分类\n - `family` STRING — 家族\n - `apt_org` STRING — APT组织\n - `weapon` STRING — 武器\n - `usefor` STRING — 用途\n - `ttps` STRING — TTPs\n - `confidence` INT — 置信度\n - `context` STRING — 上下文\n - `intelligence_investigation` STRING — 情报调查\n - `match_subdomains` INT — 匹配子域名\n - `bdelete` INT — 删除标记\n - `deleted_time` STRING — 删除时间\n - `first_occur_time` STRING — 首次出现时间\n - `last_occur_time` STRING — 最后出现时间\n - `ds` BIGINT — 分区字段\n\n**计算逻辑**:\n1. 从API指标表提取: json_extract_scalar(request, '$.entity_value') AS ioc_value, 按ioc_value分组取MIN(timestamp) AS earliest_timestamp, 过滤ds=20260608\n2. 从IOC表过滤: ioctype='DOMAIN' AND bdelete=0, 过滤ds=20260608\n3. JOIN条件: ioc = ioc_value\n4. time_diff_days = GREATEST(0, (unix_timestamp(first_occur_time) - earliest_timestamp) / 86400.0)\n\n**输出要求**:\n- 目标表: `internal_platform_db.t_app_breaking_ti_mttd_metric_cand_prestosql_010`\n- 输出字段及顺序: `IOC` STRING, `IOCTYPE` STRING, `PORT` STRING, `first_occur_time` STRING, `earliest_timestamp` BIGINT, `family` STRING, `match_subdomains` INT, `time_diff_days` DOUBLE, `ds` BIGINT\n- ds: 固定值 20260608\n- 注意Presto中用json_extract_scalar代替get_json_object,用to_unixtime代替unix_timestamp(需配合FROM_UNIXTIME相关的转换)\n- 如果目标表不存在,请先建表再写入数据\n- 请使用Presto/Trino SQL语法,不要使用Hive/Spark SQL方言\n\n**环境与执行说明**:\n- Presto已启动,通过Hive catalog连接\n- 执行SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- 写出result.sql后,必须自己执行验证它能成功运行并产出正确数据", "ground_truth": "INSERT OVERWRITE TABLE internal_platform_db.t_app_breaking_ti_mttd_metric_prestosql_010\nWITH api_metrics AS (\n SELECT\n get_json_object(request, '$.entity_value') AS ioc_value,\n MIN(`timestamp`) AS earliest_timestamp\n FROM internal_platform_db.t_app_ti_entity_api_metrics_prod_hi_prestosql_010\n WHERE ds = 20260608\n GROUP BY get_json_object(request, '$.entity_value')\n),\nfiltered_main AS (\n SELECT *\n FROM internal_platform_db.t_sh_threat_intel_lab_breakingti_soc_endpoint_security_format_output_prod_prestosql_010\n WHERE ioctype = 'DOMAIN' AND bdelete = 0 AND ds = 20260608\n)\nSELECT\n f.ioc AS IOC,\n f.ioctype AS IOCTYPE,\n f.port AS PORT,\n f.first_occur_time,\n a.earliest_timestamp,\n f.family,\n f.match_subdomains,\n GREATEST(0, (unix_timestamp(f.first_occur_time) - a.earliest_timestamp) / 86400.0) AS time_diff_days,\n 20260608 AS ds\nFROM filtered_main f\nJOIN api_metrics a ON f.ioc = a.ioc_value", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_010"}
|
| 11 |
+
{"task_id": "prestosql_011", "id": "offline-compute_PrestoSQL_prestosql_011", "name": "安全平台PG敏感接口2表UNION+聚合", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n**任务目标**:将两个安全平台PG敏感接口数据表合并,排除黑名单域名后,按日期、域名和接口路径聚合,将匹配规则名拼接为逗号分隔字符串,写入输出表。\n\n**输入表**:(2个表结构相同)\n- `internal_platform_db.internal_sec_radept_secpg_data_result2_prestosql_011`\n- `internal_platform_db.internal_sec_radept_secpg_data_result4_prestosql_011`\n\n各表字段:\n - `databus_imp_date` INT — 数据日期\n - `insert_time` STRING — 插入时间\n - `src_ip` STRING — 源IP\n - `employeename` STRING — 员工名\n - `http_host` STRING — 域名\n - `http_cgi` STRING — 接口路径\n - `http_param` STRING — 请求参数\n - `http_user_agent` STRING — 用户代理\n - `http_referer` STRING — 来源\n - `http_body` STRING — 请求体\n - `http_head` STRING — 请求头\n - `httpsrsp_body` STRING — 响应体\n - `httpsrsp_content_length` STRING — 响应内容长度\n - `https_method` STRING — HTTPS方法\n - `scan_group` STRING — 扫描组\n - `rule_name` STRING — 规则名\n - `match_string` STRING — 匹配字符串\n - `match_type` STRING — 匹配类型\n - `scan_comment` STRING — 扫描备注\n\n**过滤条件**:\n- `databus_imp_date = 20260608`\n- `http_host NOT IN ('api.im-platform.example.com', 'mp.im-platform.example.com', 'open.im-platform.example.com', 'wx.im.example.com', 'wx2.im.example.com', 'wx8.im.example.com', 'web.im-platform.example.com', 'login.im-platform.example.com', 'long.open.im-platform.example.com', 'ext.im.example.com', 'proxy.svc.example.com', 'resolver.svc.example.com', 'cloud.provider.example.com', 'console.cloud.provider.example.com', 'csec.cloud.provider.example.com')`\n\n**输出要求**:\n- 目标表: `internal_platform_db.secpg_sensitive_interface_cand_prestosql_011`\n- 输出字段及顺序: `databus_imp_date` INT, `http_host` STRING, `http_cgi` STRING, `con_con` STRING\n- con_con: listagg(rule_name, ',') 或 array_join(array_agg(DISTINCT rule_name), ',') 聚合规则名\n- 按 databus_imp_date, http_host, http_cgi 分组\n- 如果目标表不存在,请先建表再写入数据\n- 请使用Presto/Trino SQL语法,不要使用Hive/Spark SQL方言\n\n**环境与执行说明**:\n- Presto已启动,通过Hive catalog连接\n- 执行SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- 写出result.sql后,必须自己执行验证它能成功运行并产出正确数据", "ground_truth": "INSERT OVERWRITE TABLE internal_platform_db.secpg_sensitive_interface_prestosql_011\nSELECT\n databus_imp_date,\n http_host,\n http_cgi,\n concat_ws(',', collect_set(rule_name)) AS con_con\nFROM (\n SELECT databus_imp_date, http_host, http_cgi, rule_name\n FROM internal_platform_db.internal_sec_radept_secpg_data_result2_prestosql_011\n WHERE databus_imp_date = 20260608\n AND http_host NOT IN ('api.im-platform.example.com', 'mp.im-platform.example.com', 'open.im-platform.example.com', 'wx.im.example.com', 'wx2.im.example.com', 'wx8.im.example.com', 'web.im-platform.example.com', 'login.im-platform.example.com', 'long.open.im-platform.example.com', 'ext.im.example.com', 'proxy.svc.example.com', 'resolver.svc.example.com', 'cloud.provider.example.com', 'console.cloud.provider.example.com', 'csec.cloud.provider.example.com')\n UNION ALL\n SELECT databus_imp_date, http_host, http_cgi, rule_name\n FROM internal_platform_db.internal_sec_radept_secpg_data_result4_prestosql_011\n WHERE databus_imp_date = 20260608\n AND http_host NOT IN ('api.im-platform.example.com', 'mp.im-platform.example.com', 'open.im-platform.example.com', 'wx.im.example.com', 'wx2.im.example.com', 'wx8.im.example.com', 'web.im-platform.example.com', 'login.im-platform.example.com', 'long.open.im-platform.example.com', 'ext.im.example.com', 'proxy.svc.example.com', 'resolver.svc.example.com', 'cloud.provider.example.com', 'console.cloud.provider.example.com', 'csec.cloud.provider.example.com')\n) combined\nGROUP BY databus_imp_date, http_host, http_cgi", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_011"}
|
| 12 |
+
{"task_id": "prestosql_012_en", "id": "offline-compute_PrestoSQL_prestosql_012", "name": "Data Quality Check Pipeline Instance GPU Card-Hour Analysis", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n**Task Objective**: Analyze the runtime of data quality check pipeline instances. For some abnormally terminated instances, their completion records need to be backfilled. Compute the runtime duration of each instance per date shard, and combined with GPU monitoring data, compute the GPU card-hour consumption, ultimately outputting a detail table.\n\n**Business Background**:\nThe data quality check pipeline produces various span records, including check.start, check.completed, check.aborted, data.scan, rule.evaluate, resource.allocate, etc. Some instances only record check.aborted without check.completed. For these instances, a synthetic check.completed record must be constructed based on their start and aborted times to correctly compute the runtime duration.\n\nGPU monitoring data is collected in 5-minute windows and must be mapped to instances via Pod names. Combined with the GPU count from the task configuration, the card-hours are computed (gpu_hour = host_gpu_num * total_run_minutes / 60.0).\n\n**Input Tables**:\n- `internal_platform_db.t_quality_check_span_prestosql_012` (quality check span table)\n - `databus_imp_date` STRING — data date\n - `trace_id` STRING — trace ID\n - `span_name` STRING — span name\n - `start_time` STRING — start time (epoch milliseconds)\n - `end_time` STRING — end time (epoch milliseconds)\n - `status_code` INT — status code\n - `project_id` STRING — project ID\n - `task_id` STRING — task ID\n - `check_type` STRING — check type\n\n- `internal_platform_db.t_quality_gpu_monitor_prestosql_012` (GPU monitoring table)\n - `pod_name` STRING — Pod name\n - `pkg_time` STRING — collection time (epoch seconds)\n - `gpu_name` STRING — GPU model\n - `metric` STRING — monitoring metric\n - `value` STRING — metric value\n - `dt` STRING — date partition\n\n- `internal_platform_db.dwd_quality_podname_prestosql_012` (Pod-to-instance mapping table)\n - `dt` STRING — date partition\n - `instance_uuid` STRING — instance UUID\n - `pod_name` STRING — Pod name\n - `pod_phase` STRING — Pod phase\n\n- `internal_platform_db.dwd_quality_task_config_prestosql_012` (task GPU configuration table 1)\n - `databus_imp_date` STRING — data date\n - `instance_uuid` STRING — instance UUID\n - `host_gpu_num` DOUBLE — GPU count\n - `host_num` DOUBLE — host count\n - `last_modify` DOUBLE — last modification time\n - `gpu_name` STRING — GPU model\n - `resource_id` STRING — resource ID\n - `is_dedicated` STRING — whether dedicated\n\n- `internal_platform_db.quality_task_config_prestosql_012` (task GPU configuration table 2)\n - `databus_imp_date` STRING — data date\n - `instance_uuid` STRING — instance UUID\n - `host_gpu_num` DOUBLE — GPU count\n - `host_num` DOUBLE — host count\n - `last_modify` DOUBLE — last modification time\n - `gpu_name` STRING — GPU model\n - `resource_id` STRING — resource ID\n - `is_dedicated` STRING — whether dedicated\n - `scan_type` STRING — scan type\n\n**Key Logic Notes**:\n1. Identify trace_ids that have only check.aborted without check.completed, and synthesize a check.completed record for them\n2. Spans running across days must be split by day, generating one record per day\n3. GPU monitoring data must be deduplicated by 5-minute windows to compute running minutes, and mapped to instances via Pod mapping\n4. The two GPU configuration tables must be combined with UNION ALL, then use ROW_NUMBER to take the latest configuration per instance\n5. gpu_hour = host_gpu_num * total_run_minutes / 60.0\n\n**Output Requirements**:\n- Target table: `internal_platform_db.t_quality_check_gpu_instance_detail_cand_prestosql_012`\n- Output fields: `p_date` STRING, `trace_id` STRING, `project_id` STRING, `task_id` STRING, `check_type` STRING, `status_code` INT, `instance_run_time` INT, `code_run_time` INT, `gpu_hour` DOUBLE, `resource_id` STRING, `is_dedicated` BOOLEAN\n- If the target table does not exist, first create the table, then write the data\n- Use Presto/Trino SQL syntax; do not use Hive/Spark SQL dialects\n\n**Environment and Execution Notes**:\n- Presto is running, connected via the Hive catalog\n- Execute SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- After writing `result.sql`, you must execute it yourself to verify that it runs successfully and produces correct data", "ground_truth": "INSERT INTO internal_platform_db.t_quality_check_gpu_instance_detail_prestosql_012\nWITH base_trace AS (\n -- Step 1: Find trace_ids with check.aborted but NOT check.completed (HAVING inverted condition)\n SELECT trace_id\n FROM internal_platform_db.t_quality_check_span_prestosql_012\n WHERE databus_imp_date >= '2026060600'\n AND databus_imp_date <= '2026060800'\n AND span_name IN ('check.aborted', 'check.completed')\n GROUP BY trace_id\n HAVING COUNT(CASE WHEN span_name = 'check.aborted' THEN 1 END) > 0\n AND COUNT(CASE WHEN span_name = 'check.completed' THEN 1 END) = 0\n),\ncombined_spans AS (\n -- Step 2: All original spans for ALL traces + synthetic check.completed for aborted-only traces\n SELECT\n trace_id,\n span_name,\n start_time,\n end_time,\n status_code,\n project_id,\n task_id,\n check_type\n FROM internal_platform_db.t_quality_check_span_prestosql_012\n WHERE databus_imp_date >= '2026060600'\n AND databus_imp_date <= '2026060800'\n AND span_name IN ('check.aborted', 'check.start', 'check.completed', 'data.scan', 'rule.evaluate', 'resource.allocate')\n\n UNION ALL\n\n SELECT\n trace_id,\n 'check.completed' AS span_name,\n MAX(CASE WHEN span_name = 'check.start' THEN start_time END) AS start_time,\n MAX(CASE WHEN span_name = 'check.aborted' THEN end_time END) AS end_time,\n 2 AS status_code,\n MAX(CASE WHEN span_name = 'check.aborted' THEN project_id END) AS project_id,\n MAX(CASE WHEN span_name = 'check.aborted' THEN task_id END) AS task_id,\n MAX(CASE WHEN span_name = 'check.aborted' THEN check_type END) AS check_type\n FROM internal_platform_db.t_quality_check_span_prestosql_012\n WHERE databus_imp_date >= '2026060600'\n AND databus_imp_date <= '2026060800'\n AND trace_id IN (SELECT trace_id FROM base_trace)\n AND span_name IN ('check.start', 'check.aborted')\n GROUP BY trace_id\n),\nbase_data_time_fixed AS (\n -- Step 3: Fix check.aborted start_time -> earliest of code-related spans\n SELECT\n trace_id,\n span_name,\n CASE\n WHEN span_name = 'check.aborted'\n THEN MIN(CASE WHEN span_name IN ('data.scan', 'rule.evaluate', 'check.aborted') THEN start_time END)\n OVER(PARTITION BY trace_id)\n ELSE start_time\n END AS start_time,\n end_time,\n status_code,\n project_id,\n task_id,\n check_type\n FROM combined_spans\n),\nbase_data AS (\n -- Step 4: Convert timestamps, compute diff_days for cross-day splitting\n SELECT\n trace_id,\n span_name,\n start_time,\n end_time,\n status_code,\n project_id,\n task_id,\n check_type,\n from_unixtime(CAST(start_time AS BIGINT) / 1000) AS start_date,\n from_unixtime(CAST(end_time AS BIGINT) / 1000) AS end_date,\n date_diff('day', from_unixtime(CAST(start_time AS BIGINT) / 1000),\n from_unixtime(CAST(end_time AS BIGINT) / 1000)) AS diff_days,\n CAST(CAST(start_time AS BIGINT) / 86400000 AS BIGINT) * 86400000 AS start_day_midnight_ms\n FROM base_data_time_fixed\n),\npos_series AS (\n -- Step 5: Position series for cross-day expansion\n SELECT 0 AS pos UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3\n),\ndaily_split_spans AS (\n -- Step 6: INNER JOIN with pos_series, compute boundary timestamps per day\n SELECT\n trace_id,\n span_name,\n project_id,\n task_id,\n check_type,\n status_code,\n start_date,\n end_date,\n diff_days,\n date_add('day', s.pos, start_date) AS calc_date,\n CASE WHEN s.pos = 0 THEN start_time\n ELSE CAST(start_day_midnight_ms + s.pos * 86400000 AS VARCHAR)\n END AS split_start_time,\n CASE WHEN s.pos = diff_days THEN end_time\n ELSE CAST(start_day_midnight_ms + (s.pos + 1) * 86400000 - 1 AS VARCHAR)\n END AS split_end_time,\n start_time AS span_start_time,\n end_time AS span_end_time\n FROM base_data b\n INNER JOIN pos_series s ON s.pos <= b.diff_days\n),\nspan_metrics AS (\n -- Step 7: GROUP BY trace_id, calc_date -> compute instance_run_time, code_run_time, status_code\n SELECT\n trace_id,\n calc_date,\n MAX(project_id) AS project_id,\n MAX(task_id) AS task_id,\n MAX(check_type) AS check_type,\n MAX(MAX(CASE WHEN span_name = 'check.completed' THEN status_code END))\n OVER(PARTITION BY trace_id) AS status_code,\n CAST(ROUND(\n (MAX(CASE WHEN span_name = 'check.completed' THEN CAST(split_end_time AS BIGINT) END) -\n MIN(CASE WHEN span_name = 'check.completed' THEN CAST(split_start_time AS BIGINT) END)) / 1000.0\n ) AS INT) AS instance_run_time,\n CAST(ROUND(\n (MAX(CASE WHEN span_name IN ('data.scan', 'rule.evaluate', 'check.aborted') THEN CAST(split_end_time AS BIGINT) END) -\n MIN(CASE WHEN span_name IN ('data.scan', 'rule.evaluate', 'check.aborted') THEN CAST(split_start_time AS BIGINT) END)) / 1000.0\n ) AS INT) AS code_run_time\n FROM daily_split_spans\n GROUP BY trace_id, calc_date\n),\ngpu_stats AS (\n -- Step 8: FLOOR 5-min window bucketing + pod mapping + ROW_NUMBER config dedup + gpu_hour\n SELECT\n ig.instance_uuid,\n lc.host_gpu_num * ig.total_run_time_m / 60.0 AS gpu_hour,\n ig.gpu_name,\n lc.resource_id,\n CASE WHEN lc.is_dedicated = 'true' THEN true ELSE false END AS is_dedicated\n FROM (\n -- Aggregate GPU run time per instance\n SELECT\n m.instance_uuid,\n MAX(p.gpu_name) AS gpu_name,\n SUM(p.run_time_m) AS total_run_time_m\n FROM (\n -- pod_run_time: count distinct minutes per (pod_name, time_5min)\n SELECT\n pod_name,\n MAX(gpu_name) AS gpu_name,\n time_5min,\n CAST(COUNT(DISTINCT minute_timestamp) AS DOUBLE) AS run_time_m\n FROM (\n -- pod_run_minutes: FLOOR bucketing dedup\n SELECT\n pod_name,\n gpu_name,\n FLOOR(CAST(pkg_time AS BIGINT) / 60) * 60 AS minute_timestamp,\n FLOOR(CAST(pkg_time AS BIGINT) / 300) * 300 AS time_5min\n FROM internal_platform_db.t_quality_gpu_monitor_prestosql_012\n WHERE metric IN ('k8s_container_vgpu_gpu_mem_usage', 'k8s_dcgm_fi_dev_fb_util')\n GROUP BY pod_name, gpu_name,\n FLOOR(CAST(pkg_time AS BIGINT) / 60) * 60,\n FLOOR(CAST(pkg_time AS BIGINT) / 300) * 300\n ) pod_run_minutes\n GROUP BY pod_name, time_5min\n ) p\n INNER JOIN internal_platform_db.dwd_quality_podname_prestosql_012 m\n ON p.pod_name = m.pod_name\n GROUP BY m.instance_uuid\n ) ig\n LEFT JOIN (\n -- latest_task_config: ROW_NUMBER dedup from UNION ALL of two config tables\n SELECT\n instance_uuid,\n host_gpu_num,\n resource_id,\n is_dedicated\n FROM (\n SELECT\n instance_uuid,\n host_gpu_num,\n resource_id,\n is_dedicated,\n ROW_NUMBER() OVER (PARTITION BY instance_uuid ORDER BY last_modify DESC) AS rn\n FROM (\n SELECT instance_uuid, host_gpu_num, last_modify, resource_id, is_dedicated\n FROM internal_platform_db.dwd_quality_task_config_prestosql_012\n WHERE databus_imp_date = (\n SELECT MAX(databus_imp_date)\n FROM internal_platform_db.dwd_quality_task_config_prestosql_012\n )\n UNION ALL\n SELECT instance_uuid, host_gpu_num, last_modify, resource_id, is_dedicated\n FROM internal_platform_db.quality_task_config_prestosql_012\n WHERE databus_imp_date = (\n SELECT MAX(databus_imp_date)\n FROM internal_platform_db.quality_task_config_prestosql_012\n )\n ) combined\n ) ranked\n WHERE rn = 1\n ) lc ON ig.instance_uuid = lc.instance_uuid\n)\n-- Final: JOIN span_metrics with gpu_stats\nSELECT\n date_format(sm.calc_date, '%Y-%m-%d') AS p_date,\n sm.trace_id,\n sm.project_id,\n sm.task_id,\n sm.check_type,\n sm.status_code,\n sm.instance_run_time,\n sm.code_run_time,\n gs.gpu_hour,\n gs.resource_id,\n gs.is_dedicated\nFROM span_metrics sm\nLEFT JOIN gpu_stats gs ON sm.trace_id = gs.instance_uuid\n;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_012_en"}
|
hf_dataset/pyspark.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
hf_dataset/tasks.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|