ODPSQueryUtil.py 905 B

123456789101112131415161718192021222324
  1. from odps import ODPS
  2. # 阿里云odps连接
  3. access_id = 'LTAIWYUujJAm7CbH'
  4. access_key = 'RfSjdiWwED1sGFlsjXv0DlfTnZTG1P'
  5. endpoint = 'http://service.cn.maxcompute.aliyun.com/api'
  6. project_name = 'loghubods'
  7. odps = ODPS(
  8. access_id=access_id,
  9. secret_access_key=access_key,
  10. project=project_name,
  11. endpoint=endpoint
  12. )
  13. def query_videos(start_idx, limit):
  14. # 查询视频标题的表现(从阿里云odps中查询)
  15. sql = f"SELECT DISTINCT a.videoid, a.title, transed_video_path AS video_path FROM loghubods.video_return_top_500 a LEFT JOIN videoods.dim_video b ON a.videoid = b.videoid LEFT JOIN videoods.wx_video c ON a.videoid = c.id WHERE a.dt >= 20230101 LIMIT {start_idx}, {limit};"
  16. result = []
  17. with odps.execute_sql(sql).open_reader() as reader:
  18. for record in reader:
  19. # 处理查询结果
  20. result.append(record)
  21. return result