Skip to content

Commit

Permalink
Refactor max_statements property in Process
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusWirtz committed Oct 24, 2022
1 parent 04f8ff7 commit c216936
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 12 additions & 2 deletions TM1py/Objects/Process.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Optional, Iterable, Dict, List, Union

from TM1py.Objects.TM1Object import TM1Object
from TM1py.Utils import verify_version


class Process(TM1Object):
Expand All @@ -20,6 +21,13 @@ class Process(TM1Object):
MAX_STATEMENTS = 16_380
MAX_STATEMENTS_POST_11_8_015 = 100_000

@staticmethod
def max_statements(version: str):
if verify_version(required_version="11.8.015", version=version):
return Process.MAX_STATEMENTS_POST_11_8_015

return Process.MAX_STATEMENTS

@staticmethod
def add_generated_string_to_code(code: str) -> str:
pattern = r"(?s)#\*\*\*\*Begin: Generated Statements(.*)#\*\*\*\*End: Generated Statements\*\*\*\*"
Expand Down Expand Up @@ -144,8 +152,10 @@ def from_dict(cls, process_as_dict: Dict) -> 'Process':
datasource_ascii_header_records=process_as_dict['DataSource'].get('asciiHeaderRecords', ''),
datasource_ascii_quote_character=process_as_dict['DataSource'].get('asciiQuoteCharacter', ''),
datasource_ascii_thousand_separator=process_as_dict['DataSource'].get('asciiThousandSeparator', ''),
datasource_data_source_name_for_client=process_as_dict['DataSource'].get('dataSourceNameForClient',''),
datasource_data_source_name_for_server=process_as_dict['DataSource'].get('dataSourceNameForServer',''),
datasource_data_source_name_for_client=process_as_dict['DataSource'].get('dataSourceNameForClient',
''),
datasource_data_source_name_for_server=process_as_dict['DataSource'].get('dataSourceNameForServer',
''),
datasource_password=process_as_dict['DataSource'].get('password', ''),
datasource_user_name=process_as_dict['DataSource'].get('userName', ''),
datasource_query=process_as_dict['DataSource'].get('query', ''),
Expand Down
8 changes: 4 additions & 4 deletions TM1py/Services/CellService.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,9 +963,11 @@ def write_through_unbound_process(self, cube_name: str, cellset_as_dict: Dict, i
skip_non_updateable=skip_non_updateable)

chunk = list()

max_statements = Process.max_statements(self.version)
for n, statement in enumerate(statements):
chunk.append(statement)
if n > 0 and n % (Process.MAX_STATEMENTS * 2) == 0:
if n > 0 and n % (max_statements * 2) == 0:
success, status, log_file = self._execute_write_statements(chunk, enable_sandbox, kwargs)
successes.append(success)
if not success:
Expand Down Expand Up @@ -1152,9 +1154,7 @@ def get_elements_from_all_measure_hierarchies(self, cube_name: str) -> Dict[str,
return element_service.get_element_types_from_all_hierarchies(dimension_name=measure_dimension)

def _execute_write_statements(self, statements: List[str], enable_sandbox: str, kwargs) -> Tuple[bool, str, str]:
max_statements = Process.MAX_STATEMENTS
if verify_version(required_version="11.8.015", version=self.version):
max_statements = Process.MAX_STATEMENTS_POST_11_8_015
max_statements = Process.max_statements(self.version)

process = Process(
name="",
Expand Down

0 comments on commit c216936

Please sign in to comment.