We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The same query is failing when compiling the query with order_by but succeeding when returning the data.
To return the correct compiled SQL.
All this function does is to return the compiled SQL if explain is true, otherwise return the result.
def query_sl(sdk_query, explain=False): client = SemanticLayerClient( environment_id=*****, auth_token=DBT_SL_TOKEN_PROD, host="semantic-layer.cloud.getdbt.com", ) with client.session(): if explain: sql = client.compile_sql(**sdk_query) return sql else: table = client.query(**sdk_query) pandas_df = table.to_pandas() return pandas_df
My query:
sdk_query = {'metrics': ['sale_count'], 'group_by': ['metric_time__WEEK'], 'where': ["{{ TimeDimension('metric_time', 'WEEK') }} >= dateadd('month', -3, current_date)"], 'order_by': ['-metric_time__WEEK']}
When calling this:
df = query_sl(sdk_query)
it returns my dataframe as expected.
df = query_sl(sdk_query, explain=True)
It fails with following message:
/tmp/ipykernel_12/3049356820.py in query_sl(sdk_query, explain) 16 with client.session(): 17 if explain: ---> 18 sql = client.compile_sql(**sdk_query) 19 return sql 20 else: ~/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.9/lib/python3.9/site-packages/dbtsl/api/graphql/client/sync.py in _run(self, op, **kwargs) 74 res = self._gql_session.execute(gql_query, variable_values=variables) 75 except Exception as err: ---> 76 raise self._refine_err(err) 77 78 return op.parse_response(res) ~/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.9/lib/python3.9/site-packages/dbtsl/api/graphql/client/sync.py in _run(self, op, **kwargs) 72 73 try: ---> 74 res = self._gql_session.execute(gql_query, variable_values=variables) 75 except Exception as err: 76 raise self._refine_err(err) ~/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.9/lib/python3.9/site-packages/gql/client.py in execute(self, document, variable_values, operation_name, serialize_variables, parse_result, get_execution_result, **kwargs) 858 859 def __enter__(self): --> 860 return self.connect_sync() 861 862 def __exit__(self, *args): TransportQueryError: {'message': "Variable '$orderBy' got invalid value {'name': '-metric_time__WEEK'} at 'orderBy[0]'; Field 'name' is not defined by type 'OrderByInput'.", 'locations': [{'line': 1, 'column': 144}]}
No response
- OS: Hex - Python: 3.9 - Semantic Layer SDK: 0.5.0
The text was updated successfully, but these errors were encountered:
Hey @CooperData! Thanks for the feedback.
This was an oversight by me, and there's a PR to fix it here, which I just merged. It should be out in a new version soon :)
Sorry, something went wrong.
Fixed as of version 0.6.0.
No branches or pull requests
Is this a new bug in the SDK?
Current Behavior
The same query is failing when compiling the query with order_by but succeeding when returning the data.
Expected Behavior
To return the correct compiled SQL.
Steps To Reproduce
All this function does is to return the compiled SQL if explain is true, otherwise return the result.
My query:
When calling this:
it returns my dataframe as expected.
When calling this:
It fails with following message:
Relevant log output
No response
Environment
Additional Context
No response
The text was updated successfully, but these errors were encountered: