atoti.Session.start_transaction()#
- Session.start_transaction(scenario_name='Base')#
Start a transaction to batch several table operations.
It is more efficient than doing each table operation one after the other.
It avoids possibly incorrect intermediate states (e.g. if loading some new data requires dropping existing rows first).
Note
Some operations are not allowed during a transaction:
Long-running operations such as
atoti.Table.load_kafka()
.Operations changing the structure of the session’s tables such as
atoti.Table.join()
oratoti.Session.read_parquet()
.Operations not related to data loading or dropping such as defining a new measure.
Operations on parameter tables created from
atoti.Cube.create_parameter_hierarchy_from_members()
andatoti.Cube.create_parameter_simulation()
.Operations on other source scenarios than the one the transaction is started on.
- Parameters:
scenario_name (str) – The name of the source scenario impacted by all the table operations inside the transaction.
- Return type:
Transaction
Example
>>> df = pd.DataFrame( ... columns=["City", "Price"], ... data=[ ... ("Berlin", 150.0), ... ("London", 240.0), ... ("New York", 270.0), ... ("Paris", 200.0), ... ], ... ) >>> table = session.read_pandas( ... df, keys=["City"], table_name="start_transaction example" ... ) >>> cube = session.create_cube(table) >>> extra_df = pd.DataFrame( ... columns=["City", "Price"], ... data=[ ... ("Singapore", 250.0), ... ], ... ) >>> with session.start_transaction(): ... table += ("New York", 100.0) ... table.drop(table["City"] == "Paris") ... table.load_pandas(extra_df) ... >>> table.head().sort_index() Price City Berlin 150.0 London 240.0 New York 100.0 Singapore 250.0