odps_function.py 796 B

1234567891011121314151617181920212223242526272829303132333435
  1. """
  2. python odps function
  3. """
  4. import os
  5. from odps import ODPS
  6. class OdpsFunction(object):
  7. """
  8. odps function class
  9. """
  10. def __init__(self):
  11. self.endpoint = "http://service.cn.maxcompute.aliyun.com/api"
  12. self.access_id = "LTAIWYUujJAm7CbH"
  13. self.access_key = "RfSjdiWwED1sGFlsjXv0DlfTnZTG1P"
  14. self.project = "loghubods"
  15. self.od = ODPS(
  16. access_id=self.access_id,
  17. secret_access_key=self.access_key,
  18. endpoint=self.endpoint,
  19. project=self.project,
  20. )
  21. def select(self, sql):
  22. """
  23. :param sql: 查询语句
  24. :return: odps_obj{}
  25. """
  26. with self.od.execute_sql(sql).open_reader() as reader:
  27. for record in reader:
  28. return record