Hello GoodData team, I try to use function: sdk.ta...
# gooddata-cn
a
Hello GoodData team, I try to use function: sdk.tables.for_items. It expects to get items and filters. For items I provide attribute list Attribute(local_id=field, label=field), for filters: list of PositiveAttributeFilter with values. It works for attributes that I see in sdk.catalog_workspace_content.get_attributes_catalog(my_workspace_id). However I want to filter by date attribute. It is not in attribute catalog list, but in sdk.catalog_workspace_content.get_full_catalog(wp_id). Is there anyway to use date attribute and filter in sdk.tables.for_items?
@Igor Strupinskiy
j
Hi Andrei, It is possible to use the date attribute in sdk.tables.for_items. You can do the following:
Copy code
dates_table = sdk.tables.for_items(
        workspace_id="demo",
        items=[
            Attribute(local_id="attr1", label="date.month"),
            SimpleMetric(local_id="metric1", item=ObjId(type="fact", id="quantity")),
        ],
    )
It is strange that you cannot see the date attribute using
sdk.catalog_workspace_content.get_attributes_catalog(my_workspace_id)
. I tried it on
demo
workspace and I can see date attributes there.
Copy code
CatalogAttribute(id='date.year', type='attribute', json_api_entity=JsonApiEntityBase(id='date.year', type='attribute'), title='Date - Year', description='Year', tags=['Date'])
Does your LDM contain Date dataset?
j
Note: date filters cannot be specified with PositiveAttributeFilter. Instead, you have to use one of dedicated DateFilter objects, look here: https://github.com/gooddata/gooddata-python-sdk/blob/master/gooddata-sdk/gooddata_sdk/compute/model/filter.py#L105
a
Thank you for the response. I still have a question. I try to run 2 queries:
Copy code
return sdk.tables.for_items(
    workspace_id=gd_workspace_id,
    items=[Attribute(local_id="AccountId", label="AccountId")],
    filters=[
        AbsoluteDateFilter(
            dataset=ObjId(id="Account_EndDate", type="dataset"),
            from_date="2022-05-05",
            to_date="2023-06-05",
        )
    ],
)
and
Copy code
return sdk.tables.for_items(
    workspace_id=gd_workspace_id,
    items=[Attribute(local_id="Account_EndDate.year", label="Account_EndDate.year")],
    filters=[
        AbsoluteDateFilter(
            dataset=ObjId(id="Account_EndDate", type="dataset"),
            from_date="2022-05-05",
            to_date="2023-06-05",
        )
    ],
)
Here I have different items set. Second request fails with exception reason: Enumerating datetime attributes='[attribute/Account_EndDate.day....what exactly it means? What should be the correct attribute id?
+ if I run
Copy code
attributes = sdk.catalog_workspace_content.get_attributes_catalog(gd_workspace_id)

print([attr for attr in attributes if attr.id=="Account_EndDate.year"])
I see the following response: [CatalogAttribute(id=Account_EndDate.year, title=Account enddate - Year, labels=[])]
j
The date dataset represents an abstract date meaning that there are all dates. Therefore, listing it independently without any other fact or attribute is not allowed.
j
This is documented limitation of GoodData cloud/CN products. Interestingly, it works in GoodData Platform product. Why? Well, the difference relates to if date dataset is or is not materialized. We materialize the date dimension in GoodData platform, only DAY granularity, circa from 1900 to 2040. That is why we can enumerate values from it. In GoodData cloud/CN we intentionally did not want to go the same way. Why? Because when you query the DATE(TIMESTAMP) columns directly, you can provide more features, for instance slice reports by hours/minutes. You can't materialize date dimension with MINUTE or even SECOND granularity without huge performance impact 😉 However, we have a plan how to provide what you want. In short, we will evaluate if the date dataset is connected to exactly one standard dataset. If so, we enumerate available DATE/TIMESTAMP values from this connected dataset. If the date dataset will be connected to more datasets, we are not yet sure about a solution. We are afraid to do some kind of UNION query, performance could be very bad. We may return error, we may pick randomly one from the connected datasets, maybe there are other solutions. What would you expect? Feedback is welcome! Anyway, now you can workaround the issue by adding any context to the report definition, e.g. some metric. It won't change the granularity of the date values you get and you can throw away the metric values. Btw. it gives you the full flexibility to define the context in the case if the date dimension is connected to multiple standard datasets.
a
@Igor Strupinskiy ^
@James Lee ^
j
can we schedule a call with one of you to go over the absolute date filter + attribute issues we're runinng into?
j
Sure, DM me
j
sent dm with cayce
@Jan Kadlec are you available to get on a call with us today? Soubusta is available tomorrow but we would like to get our issue resolved today if possible
j
Hi @James Lee, unfortunately, I am not available as well today. I am going to be available tomorrow.
j
@Jan Soubusta here's the error message: Traceback (most recent call last): File "<string>", line 1, in <module> _File "/Users/jameslee/Library/Caches/pypoetry/virtualenvs/statements-python-cf-hrEXxOCH-py3.9/lib/python3.9/site-packages/gooddata_sdk/table.py", line 234, in for_items_ _response = self._compute.for_exec_def(workspace_id=workspace_id, exec_def=exec_def)_ _File "/Users/jameslee/Library/Caches/pypoetry/virtualenvs/statements-python-cf-hrEXxOCH-py3.9/lib/python3.9/site-packages/gooddata_sdk/compute/service.py", line 31, in for_exec_def_ _response = self._actions_api.compute_report(workspace_id, exec_def.as_api_model(), _check_return_type=False)_ _File "/Users/jameslee/Library/Caches/pypoetry/virtualenvs/statements-python-cf-hrEXxOCH-py3.9/lib/python3.9/site-packages/gooddata_api_client/api/actions_api.py", line 2439, in compute_report_ _return self.compute_report_endpoint.call_with_http_info(**kwargs)_ _File "/Users/jameslee/Library/Caches/pypoetry/virtualenvs/statements-python-cf-hrEXxOCH-py3.9/lib/python3.9/site-packages/gooddata_api_client/api_client.py", line 880, in call_with_http_info_ _return self.api_client.call_api(_ _File "/Users/jameslee/Library/Caches/pypoetry/virtualenvs/statements-python-cf-hrEXxOCH-py3.9/lib/python3.9/site-packages/gooddata_api_client/api_client.py", line 422, in call_api_ _return self.__call_api(resource_path, method,_ _File "/Users/jameslee/Library/Caches/pypoetry/virtualenvs/statements-python-cf-hrEXxOCH-py3.9/lib/python3.9/site-packages/gooddata_api_client/api_client.py", line 206, in __call_api_ raise e _File "/Users/jameslee/Library/Caches/pypoetry/virtualenvs/statements-python-cf-hrEXxOCH-py3.9/lib/python3.9/site-packages/gooddata_api_client/api_client.py", line 199, in __call_api_ _response_data = self.request(_ _File "/Users/jameslee/Library/Caches/pypoetry/virtualenvs/statements-python-cf-hrEXxOCH-py3.9/lib/python3.9/site-packages/gooddata_api_client/api_client.py", line 468, in request_ _return self.rest_client.POST(url,_ _File "/Users/jameslee/Library/Caches/pypoetry/virtualenvs/statements-python-cf-hrEXxOCH-py3.9/lib/python3.9/site-packages/gooddata_api_client/rest.py", line 271, in POST_ return self.request("POST", url, _File "/Users/jameslee/Library/Caches/pypoetry/virtualenvs/statements-python-cf-hrEXxOCH-py3.9/lib/python3.9/site-packages/gooddata_api_client/rest.py", line 230, in request_ _raise ApiException(http_resp=r)_ _gooddata_api_client.exceptions.ApiException: Status Code: 400_ Reason: Bad Request _HTTP response headers: HTTPHeaderDict({'Date': 'Mon, 24 Jul 2023 191600 GMT', 'Content-Type': 'application/problem+json', 'Content-Length': '128', 'Connection': 'keep-alive', 'Vary': 'Origin, Access-Control-Request-Method, Access-Control-Request-Headers', 'X-GDC-TRACE-ID': 'b156fb02fae87d96', 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Content-Type-Options': 'nosniff', 'Strict-Transport-Security': 'max-age=15724800; includeSubDomains', 'X-XSS-Protection': '1 ; mode=block', 'Referrer-Policy': 'no-referrer', 'Set-Cookie': 'SPRING_REDIRECT_URI=; Path=/; Max-Age=0; Expires=Thu, 01 Jan 1970 000000 GMT; Secure; HttpOnly; SameSite=Lax'})_ HTTP response body: {"title":"Bad Request","status":400,"detail":"Objects [] are either inaccessible or not existing.","traceId":"b156fb02fae87d96"}
j
Thanks, will raise an internal Jira. We arranged a call and fixed it. @Jakub Sterba FYI the outcome is that it is hard to understand why date attributes are put to items but date dataset must be put to filters. We should definitely improve our documentation, but maybe we could also think about it, if we could make it even more intuitive...
j
The reason for use of datasets was perhaps easier combination of dashboard date filter with insight filters (filter is replaced if it is applied on the same date dataset as in the insight else both filters are applied). I think we may consider to support date attributes on API/SDK as well in future.