`assign_var` and `last_raw_result_var` options do not assign result to specified user variables as defined in specs
Closed this issue · 3 comments
I need to assign results of the query to a variable within a method because it's a multi-threaded call and I cannot use the global kql_raw_result variable.
Example query:
%kql -query queryStr -assign_var "res" -enable_suppress_result ;
I believe that's the intended use of the -assign_var
option. When used like so, the res
variable gets defined within the python method but nevertheless is always an empty string. So is the _
variable. The _kql_raw_result
is still initialized with the query result.
The same is true for the last_raw_result_var
option.
Michael,
Thank you for your quick response. Would you happen to have any example of directly using Kqlmagic module's Kqlmagic class and it's execute method?
Thanks again,
Alena
For posterity, sharing the way I was able to retrieve query results via using locally scoped variable:
from Kqlmagic.kql_magic import Kqlmagic as Magic
def kql(queryString: str, in_cell=False):
"""
Query Kqlmagic
@param queryString: query string
@param in_cell: force kql to be a cell only query
"""
kql = Magic(shell=None)
res = kql.execute(
line=f"{queryString};" if in_cell is False else "",
cell=None if in_cell is False else queryString,
override_options={"try_vscode_login": True},
override_connection="AzureDataExplorer://code;cluster='VSO';database='VSO'"
)
return res