| 12345678910111213141516171819202122232425262728 |
- #!/usr/bin/env python3
- """Execute an explicit SQL file with the bundled environment-based ODPS client."""
- from __future__ import annotations
- import argparse
- from pathlib import Path
- from odps_module import ODPSClient
- def main() -> None:
- parser = argparse.ArgumentParser(description="Run an ODPS SQL file and save UTF-8 CSV")
- parser.add_argument("sql_file", type=Path)
- parser.add_argument("output_file", type=Path)
- parser.add_argument("--project", help="Override ODPS_PROJECT for this query")
- args = parser.parse_args()
- sql = args.sql_file.expanduser().read_text(encoding="utf-8")
- output_path = ODPSClient(project=args.project).execute_sql_result_save_file(
- sql,
- args.output_file,
- )
- print(f"[CSV] {output_path.resolve()}", flush=True)
- if __name__ == "__main__":
- main()
|