1+ import logging
12import os
23from typing import List
34
78from bytewax .execution import cluster_main
89from bytewax .inputs import ManualInputConfig
910from bytewax .outputs import ManualOutputConfig
10- from tqdm import tqdm
1111
1212from feast import FeatureStore , FeatureView , RepoConfig
1313from feast .utils import _convert_arrow_to_proto , _run_pyarrow_field_mapping
1414
15+ logger = logging .getLogger (__name__ )
1516DEFAULT_BATCH_SIZE = 1000
1617
1718
@@ -29,14 +30,20 @@ def __init__(
2930 self .feature_view = feature_view
3031 self .worker_index = worker_index
3132 self .paths = paths
33+ self .mini_batch_size = int (
34+ os .getenv ("BYTEWAX_MINI_BATCH_SIZE" , DEFAULT_BATCH_SIZE )
35+ )
3236
3337 self ._run_dataflow ()
3438
3539 def process_path (self , path ):
40+ logger .info (f"Processing path { path } " )
3641 dataset = pq .ParquetDataset (path , use_legacy_dataset = False )
3742 batches = []
3843 for fragment in dataset .fragments :
39- for batch in fragment .to_table ().to_batches ():
44+ for batch in fragment .to_table ().to_batches (
45+ max_chunksize = self .mini_batch_size
46+ ):
4047 batches .append (batch )
4148
4249 return batches
@@ -45,40 +52,26 @@ def input_builder(self, worker_index, worker_count, _state):
4552 return [(None , self .paths [self .worker_index ])]
4653
4754 def output_builder (self , worker_index , worker_count ):
48- def yield_batch (iterable , batch_size ):
49- """Yield mini-batches from an iterable."""
50- for i in range (0 , len (iterable ), batch_size ):
51- yield iterable [i : i + batch_size ]
52-
53- def output_fn (batch ):
54- table = pa .Table .from_batches ([batch ])
55+ def output_fn (mini_batch ):
56+ table : pa .Table = pa .Table .from_batches ([mini_batch ])
5557
5658 if self .feature_view .batch_source .field_mapping is not None :
5759 table = _run_pyarrow_field_mapping (
5860 table , self .feature_view .batch_source .field_mapping
5961 )
60-
6162 join_key_to_value_type = {
6263 entity .name : entity .dtype .to_value_type ()
6364 for entity in self .feature_view .entity_columns
6465 }
65-
6666 rows_to_write = _convert_arrow_to_proto (
6767 table , self .feature_view , join_key_to_value_type
6868 )
69- provider = self .feature_store ._get_provider ()
70- with tqdm (total = len (rows_to_write )) as progress :
71- # break rows_to_write to mini-batches
72- batch_size = int (
73- os .getenv ("BYTEWAX_MINI_BATCH_SIZE" , DEFAULT_BATCH_SIZE )
74- )
75- for mini_batch in yield_batch (rows_to_write , batch_size ):
76- provider .online_write_batch (
77- config = self .config ,
78- table = self .feature_view ,
79- data = mini_batch ,
80- progress = progress .update ,
81- )
69+ self .feature_store ._get_provider ().online_write_batch (
70+ config = self .config ,
71+ table = self .feature_view ,
72+ data = rows_to_write ,
73+ progress = None ,
74+ )
8275
8376 return output_fn
8477
0 commit comments