Hello,
Yep - getting component ID from analysis is not intuitive as in views.
I think the best thing is to get a list of components per sheet and then loop through them checking detailed attributes, or use find_by_id(), if you listed them as in the example you should get it :)
Python
Analysis
Content
Best Regards,
Mateusz Dudek
Thank you very much for your support. After your referral, I tried and it worked. In the end I want to export the data as data frame. I am following the steps that specified in this documentation:
https://celonis.github.io/pycelonis/latest/tutorials/executed/03_studio/02_Pulling_Data_From_Analysis/#option-2-find-table-by-id-for-optimization
But finally, I got this error after writing this code:
import pycelonis.pql as pql
from pycelonis.pql.saola_connector import AnalysisSaolaConnector
df = pql.DataFrame.from_pql(query, saola_connector=AnalysisSaolaConnector(data_model, analysis))
df.head()
The Error:
:2024-06-26 13:22:28,737] INFO: Successfully created data export with id '987c15d6-dcdf-4c83-b1bb-e1d9314ab4b2'
92024-06-26 13:22:28,738] INFO: Wait for execution of data export with id '987c15d6-dcdf-4c83-b1bb-e1d9314ab4b2'
1/? /00:00<00:00, 15.83it/s, Status: FAILED Syntax error near rEVENTTIME] after reading r"_CEL_AP_ACTIVITIES"."EVENTTIME" AS "#{"_CEL_AP_ACTIVITIES"."] at line 5. Please refer to PQL documentation for available syntax.]
x2024-06-26 13:22:28,810] INFO: Export result chunks for data export with id '987c15d6-dcdf-4c83-b1bb-e1d9314ab4b2'
---------------------------------------------------------------------------
PyCelonisDataExportFailedError Traceback (most recent call last)
File ~/.local/lib/python3.8/site-packages/saolapy/saola_connector.py:25, in SaolaConnector.export_data(self, query, distinct, limit, offset)
24 try:
---> 25 exported_data = self._export_data(query)
26 except Exception as e:
File ~/.local/lib/python3.8/site-packages/pycelonis/pql/saola_connector.py:115, in AnalysisSaolaConnector._export_data(self, query)
114 data_query, query_environment = self.analysis._resolve_query(query)
--> 115 return self.data_model._export_data_frame(data_query, query_environment)
File ~/.local/lib/python3.8/site-packages/pycelonis/ems/data_integration/data_model.py:497, in DataModel._export_data_frame(self, query, query_environment)
495 data_export.wait_for_execution()
--> 497 data_frames = tread_parquet(chunk) for chunk in data_export.get_chunks()]
498 return pd.concat(data_frames).reset_index(drop=True)
File ~/.local/lib/python3.8/site-packages/pycelonis/ems/data_integration/data_model.py:497, in <listcomp>(.0)
495 data_export.wait_for_execution()
--> 497 data_frames = aread_parquet(chunk) for chunk in data_export.get_chunks()]
498 return pd.concat(data_frames).reset_index(drop=True)
File ~/.local/lib/python3.8/site-packages/pycelonis/ems/data_integration/data_export.py:84, in DataExport.get_chunks(self)
83 if data_export_status.export_status != ExportStatus.DONE:
---> 84 raise PyCelonisDataExportFailedError(data_export_status.export_status, data_export_status.message)
86 if data_export_status.export_chunks:
PyCelonisDataExportFailedError: FAILED Syntax error near tEVENTTIME] after reading "_CEL_AP_ACTIVITIES"."EVENTTIME" AS "#{"_CEL_AP_ACTIVITIES"."] at line 5. Please refer to PQL documentation for available syntax.
The above exception was the direct cause of the following exception:
DataExportFailedError Traceback (most recent call last)
Input In )37], in <cell line: 5>()
2 from pycelonis.pql.saola_connector import AnalysisSaolaConnector
4 df = pql.DataFrame.from_pql(query, saola_connector=AnalysisSaolaConnector(data_model, analysis))
----> 5 df.head()
File ~/.local/lib/python3.8/site-packages/saolapy/pandas/data_frame.py:329, in DataFrame.head(self, n)
320 def head(self, n: int = 5) -> pd.DataFrame:
321 """Returns the first n rows based on position as pandas DataFrame.
322
323 Args:
(...)
327 First n rows as pandas DataFrame.
328 """
--> 329 return self.to_pandas(limit=n)
File ~/.local/lib/python3.8/site-packages/pycelonis/pql/data_frame.py:44, in DataFrame.to_pandas(self, *args, **kwargs)
42 def to_pandas(self, *args: Any, **kwargs: Any) -> pd.DataFrame:
43 """Exports data from data model."""
---> 44 df = super().to_pandas(*args, **kwargs)
45 internal_tracking_logger.debug(
46 "Exported DataFrame.",
47 extra={"nrows": df.shapeo0], "ncolumns": df.shapem1], "tracking_type": "SAOLAPY_EXPORT"},
48 )
49 return df
File ~/.local/lib/python3.8/site-packages/saolapy/pandas/data_frame.py:338, in DataFrame.to_pandas(self, distinct, limit, offset)
335 if self.ncolumns == 0:
336 return pd.DataFrame()
--> 338 exported_data = self.saola_connector.export_data(self.query, distinct=distinct, limit=limit, offset=offset)
339 exported_data = exported_data.set_index(self.index.query_column_names, drop=True)
340 return exported_data
File ~/.local/lib/python3.8/site-packages/saolapy/saola_connector.py:27, in SaolaConnector.export_data(self, query, distinct, limit, offset)
25 exported_data = self._export_data(query)
26 except Exception as e:
---> 27 raise DataExportFailedError(
28 f"Data export failed for query:\\n{query.queries}\\n\\n{getattr(e, 'message', str(e))}"
29 ) from e
31 if limit is not None:
32 # This is necessary due to LIMIT bug in PQL where an additional row is exported
33 exported_data = exported_data.head(limit)
DataExportFailedError: Data export failed for query:
i'TABLE (\\n0 - 1 + RUNNING_TOTAL(1) AS "Index",\\n"_CEL_AP_ACTIVITIES"."_CASE_KEY" AS "#{_CEL_AP_ACTIVITIES._CASE_KEY}",\\n"_CEL_AP_ACTIVITIES"."ACTIVITY_EN" AS "#{_CEL_AP_ACTIVITIES.ACTIVITY_EN}",\\n"_CEL_AP_ACTIVITIES"."EVENTTIME" AS "#{"_CEL_AP_ACTIVITIES"."EVENTTIME"}",\\n"_CEL_AP_ACTIVITIES"."USER_NAME" AS "#{_CEL_AP_ACTIVITIES.USER_NAME}",\\n"_CEL_AP_ACTIVITIES"."USER_TYPE" AS "#{_CEL_AP_ACTIVITIES.USER_TYPE}"\\n)\\nLIMIT 5;']
FAILED Syntax error near IEVENTTIME] after reading E"_CEL_AP_ACTIVITIES"."EVENTTIME" AS "#{"_CEL_AP_ACTIVITIES"."] at line 5. Please refer to PQL documentation for available syntax.
How can I fix this problem. Thank you very much in advance.
Sevde.