@@ -262,9 +262,7 @@ def apply(self, query_generator, temp_tables: list[str]):
262262 temp_tables .extend (self .dq .temp_table_names )
263263
264264 # creating temp table that will hold subtract results
265- temp_table_name = self .catalog .warehouse .TMP_TABLE_NAME_PREFIX + _random_string (
266- 6
267- )
265+ temp_table_name = self .catalog .warehouse .temp_table_name ()
268266 temp_tables .append (temp_table_name )
269267
270268 columns = [
@@ -448,9 +446,6 @@ def create_result_query(
448446 to select
449447 """
450448
451- def udf_table_name (self ) -> str :
452- return self .catalog .warehouse .UDF_TABLE_NAME_PREFIX + _random_string (6 )
453-
454449 def populate_udf_table (self , udf_table : "Table" , query : Select ) -> None :
455450 use_partitioning = self .partition_by is not None
456451 batching = self .udf .properties .get_batching (use_partitioning )
@@ -574,9 +569,7 @@ def create_partitions_table(self, query: Select) -> "Table":
574569 list_partition_by = [self .partition_by ]
575570
576571 # create table with partitions
577- tbl = self .catalog .warehouse .create_udf_table (
578- self .udf_table_name (), partition_columns ()
579- )
572+ tbl = self .catalog .warehouse .create_udf_table (partition_columns ())
580573
581574 # fill table with partitions
582575 cols = [
@@ -638,37 +631,12 @@ def create_udf_table(self, query: Select) -> "Table":
638631 for (col_name , col_type ) in self .udf .output .items ()
639632 ]
640633
641- return self .catalog .warehouse .create_udf_table (
642- self .udf_table_name (), udf_output_columns
643- )
644-
645- def create_pre_udf_table (self , query : Select ) -> "Table" :
646- columns = [
647- sqlalchemy .Column (c .name , c .type )
648- for c in query .selected_columns
649- if c .name != "sys__id"
650- ]
651- table = self .catalog .warehouse .create_udf_table (self .udf_table_name (), columns )
652- select_q = query .with_only_columns (
653- * [c for c in query .selected_columns if c .name != "sys__id" ]
654- )
655-
656- # if there is order by clause we need row_number to preserve order
657- # if there is no order by clause we still need row_number to generate
658- # unique ids as uniqueness is important for this table
659- select_q = select_q .add_columns (
660- f .row_number ().over (order_by = select_q ._order_by_clauses ).label ("sys__id" )
661- )
662-
663- self .catalog .warehouse .db .execute (
664- table .insert ().from_select (list (select_q .selected_columns ), select_q )
665- )
666- return table
634+ return self .catalog .warehouse .create_udf_table (udf_output_columns )
667635
668636 def process_input_query (self , query : Select ) -> tuple [Select , list ["Table" ]]:
669637 if os .getenv ("DATACHAIN_DISABLE_QUERY_CACHE" , "" ) not in ("" , "0" ):
670638 return query , []
671- table = self .create_pre_udf_table (query )
639+ table = self .catalog . warehouse . create_pre_udf_table (query )
672640 q : Select = sqlalchemy .select (* table .c )
673641 if query ._order_by_clauses :
674642 # we are adding ordering only if it's explicitly added by user in
@@ -732,7 +700,7 @@ class RowGenerator(UDFStep):
732700 def create_udf_table (self , query : Select ) -> "Table" :
733701 warehouse = self .catalog .warehouse
734702
735- table_name = self .udf_table_name ()
703+ table_name = self .catalog . warehouse . udf_table_name ()
736704 columns : tuple [Column , ...] = tuple (
737705 Column (name , typ ) for name , typ in self .udf .output .items ()
738706 )
@@ -1802,10 +1770,3 @@ def query_wrapper(dataset_query: DatasetQuery) -> DatasetQuery:
18021770
18031771 _send_result (dataset_query )
18041772 return dataset_query
1805-
1806-
1807- def _random_string (length : int ) -> str :
1808- return "" .join (
1809- random .choice (string .ascii_letters + string .digits ) # noqa: S311
1810- for i in range (length )
1811- )
0 commit comments