Enforce session workspace boundaries
This commit is contained in:
@@ -49,7 +49,7 @@ skills/data-factory-sql/
|
||||
}
|
||||
```
|
||||
|
||||
多行 SQL 或复杂 SQL 不要通过命令行字符串硬塞。优先把 SQL 写到当前会话 scratchpad 或用户指定的任务目录,再用 `-f` 执行:
|
||||
多行 SQL 或复杂 SQL 不要通过命令行字符串硬塞。优先把 SQL 写到当前 session/scratchpad;只有用户明确指定外部目标文件时,才写到用户指定目录,再用 `-f` 执行:
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -86,7 +86,7 @@ https://data.mioffice.cn/workspace/?wid=<YOUR_WORKSPACE_ID>#/workspace/<YOUR_WOR
|
||||
| 集群 | `cnbj1` |
|
||||
| Base URL | `http://proxy-service-http-cnbj1-dp.api.xiaomi.net` |
|
||||
| 引擎 | `auto` |
|
||||
| 输出 | `~/Downloads/data_factory_<时间戳>.csv` |
|
||||
| 输出 | 当前 session/output/data_factory_<时间戳>.csv;如果没有 session 环境,则退回 `~/Downloads/data_factory_<时间戳>.csv` |
|
||||
| 轮询间隔 | 2.0s |
|
||||
| 查询超时 | 600s |
|
||||
|
||||
@@ -166,7 +166,7 @@ https://data.mioffice.cn/workspace/?wid=<YOUR_WORKSPACE_ID>#/workspace/<YOUR_WOR
|
||||
|
||||
### 指定输出路径
|
||||
|
||||
输出路径优先写到当前用户当前会话 output 目录,或用户明确指定的任务目录。不要写项目根目录。
|
||||
输出路径优先写到当前 session/output,或用户明确指定的任务目录。不要写项目根目录、源码目录或其他非 session 临时位置。
|
||||
|
||||
```json
|
||||
{
|
||||
|
||||
@@ -76,8 +76,13 @@ def read_sql(args: argparse.Namespace) -> str:
|
||||
|
||||
|
||||
def default_output_path(query_id: str) -> Path:
|
||||
"""Default: ~/Downloads/data_factory_<timestamp>.csv"""
|
||||
"""Default to current session output when python_exec exposes it."""
|
||||
ts = time.strftime("%Y%m%d_%H%M%S")
|
||||
scratchpad = os.environ.get("PYTHON_EXEC_SCRATCHPAD")
|
||||
if scratchpad:
|
||||
output_dir = Path(scratchpad).resolve().parent / "output"
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
return output_dir / f"data_factory_{ts}.csv"
|
||||
downloads = Path.home() / "Downloads"
|
||||
downloads.mkdir(parents=True, exist_ok=True)
|
||||
return downloads / f"data_factory_{ts}.csv"
|
||||
@@ -136,7 +141,11 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
p.add_argument("--catalog", help="default catalog")
|
||||
p.add_argument("--schema", help="default schema")
|
||||
p.add_argument(
|
||||
"--output", help="output CSV path (default: ~/Downloads/data_factory_<ts>.csv)"
|
||||
"--output",
|
||||
help=(
|
||||
"output CSV path (default: session output when PYTHON_EXEC_SCRATCHPAD "
|
||||
"is set, otherwise ~/Downloads/data_factory_<ts>.csv)"
|
||||
),
|
||||
)
|
||||
p.add_argument(
|
||||
"--no-save", action="store_true", help="don't save CSV, only print to stdout"
|
||||
|
||||
Reference in New Issue
Block a user