Skip to content

Commit

Permalink
Merge pull request aliyun#191 from guhanjie/dev/add_sql_apis
Browse files Browse the repository at this point in the history
Add SQL apis
  • Loading branch information
yuanqj authored Sep 22, 2021
2 parents 56a5d4c + e709bad commit 020d7d9
Show file tree
Hide file tree
Showing 7 changed files with 438 additions and 86 deletions.
11 changes: 11 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Release History

### 0.6.57 (2020-09-09)
----------------------------
**Implementations**
- Add executeSQl apis
- Add extra parameter power_sql in get_log/get_logs/get_log_all
- Add SQL related headers(x-log-**) on GetLogResponse

**Fixing**
- fix typo


### 0.6.48 (2020-03-20)
----------------------------
**Implementations**
Expand Down
42 changes: 40 additions & 2 deletions aliyun/log/getlogsrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ class GetLogsRequest(LogRequest):
:type reverse: bool
:param reverse: if reverse is set to true, the query will return the latest logs first
:type power_sql: bool
:param power_sql: if power_sql is set to true, the query will run on enhanced sql mode
"""

def __init__(self, project=None, logstore=None, fromTime=None, toTime=None, topic=None,
query=None, line=100, offset=0, reverse=False):
query=None, line=100, offset=0, reverse=False, power_sql=False):
LogRequest.__init__(self, project)
self.logstore = logstore
self.fromTime = fromTime
Expand All @@ -49,6 +52,7 @@ def __init__(self, project=None, logstore=None, fromTime=None, toTime=None, topi
self.line = line
self.offset = offset
self.reverse = reverse
self.power_sql = power_sql

def get_logstore(self):
""" Get logstore name
Expand Down Expand Up @@ -170,6 +174,21 @@ def set_reverse(self, reverse):
"""
self.reverse = reverse

def get_power_sql(self):
""" Get request power_sql flag
:return: bool, power_sql flag
"""
return self.power_sql

def set_power_sql(self, power_sql):
""" Set request power_sql flag
:type power_sql: bool
:param power_sql: power_sql flag
"""
self.power_sql = power_sql


class GetProjectLogsRequest(LogRequest):
""" The request used to get logs by a query from log cross multiple logstores.
Expand All @@ -179,11 +198,15 @@ class GetProjectLogsRequest(LogRequest):
:type query: string
:param query: user defined query
:type power_sql: bool
:param power_sql: if power_sql is set to true, the query will run on enhanced sql mode
"""

def __init__(self, project=None, query=None):
def __init__(self, project=None, query=None, power_sql=False):
LogRequest.__init__(self, project)
self.query = query
self.power_sql = power_sql

def get_query(self):
""" Get user defined query
Expand All @@ -199,3 +222,18 @@ def set_query(self, query):
:param query: user defined query
"""
self.query = query

def get_power_sql(self):
""" Get request power_sql flag
:return: bool, power_sql flag
"""
return self.power_sql

def set_power_sql(self, power_sql):
""" Set request power_sql flag
:type power_sql: bool
:param power_sql: power_sql flag
"""
self.power_sql = power_sql
56 changes: 56 additions & 0 deletions aliyun/log/getlogsresponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ def __init__(self, resp, header):
LogResponse.__init__(self, header, resp)
try:
self.progress = Util.h_v_t(header, 'x-log-progress')
self.processed_rows = Util.h_v_t(header, 'x-log-processed-rows')
self.elapsed_mills = Util.h_v_t(header, 'x-log-elapsed-millisecond')
self.has_sql = Util.h_v_t(header, 'x-log-has-sql')
self.where_query = Util.h_v_t(header, 'x-log-where-query')
self.agg_query = Util.h_v_t(header, 'x-log-agg-query')
self.cpu_sec = Util.h_v_t(header, 'x-log-cpu-sec')
self.cpu_cores = Util.h_v_t(header, 'x-log-cpu-cores')
self.logs = []
for data in resp:
contents = {}
Expand Down Expand Up @@ -65,6 +72,55 @@ def get_logs(self):
"""
return self.logs

def get_processed_rows(self):
""" Get processed rows from the response
:return: processed_rows, long
"""
return self.processed_rows

def get_elapsed_mills(self):
""" Get elapsed mills from the response
:return: elapsed_mills, long
"""
return self.elapsed_mills

def get_has_sql(self):
""" Get whether has sql from the response
:return: has_sql, boolean
"""
return self.has_sql

def get_where_query(self):
""" Get the Search part of "Search|Analysis"
:return: where_query, str
"""
return self.where_query

def get_agg_query(self):
""" Get the Analysis part of "Search|Analysis"
:return: agg_query, str
"""
return self.agg_query

def get_cpu_sec(self):
""" Get cpu seconds used from the response
:return: cpu_sec, long
"""
return self.cpu_sec

def get_cpu_cores(self):
""" Get cpu cores used from the response
:return: cpu_cores, long
"""
return self.cpu_cores

def log_print(self):
print('GetLogsResponse:')
print('headers:', self.get_all_headers())
Expand Down
Loading

0 comments on commit 020d7d9

Please sign in to comment.