ODPSQueryUtil.py 814 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_video_title_perfermance(start_idx, limit):
  14. # 查询视频标题的表现(从阿里云odps中查询)
  15. sql = f"SELECT * FROM video_allbusinesstype_data WHERE dt = '20231120' and view_times > 10 AND title is not NULL AND title != '' ORDER BY videoid 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