"""
@author: luojunhui
"""
from odps import ODPS


class PyODPS(object):
    """
    PyODPS class, get data from odps server
    """

    def __init__(self):
        self.endpoint = "http://service.cn.maxcompute.aliyun.com/api"
        self.access_id = "LTAIWYUujJAm7CbH"
        self.access_key = "RfSjdiWwED1sGFlsjXv0DlfTnZTG1P"
        self.project = "loghubods"

        self.od = ODPS(
            access_id=self.access_id,
            secret_access_key=self.access_key,
            endpoint=self.endpoint,
            project=self.project,
        )

    def select(self, sql):
        """
        :param sql: 查询语句
        :return: odps_obj{}
        """
        result = []
        with self.od.execute_sql(sql).open_reader() as reader:
            for record in reader:
                result.append(record)
        return result