@@ -29,7 +29,7 @@ def setup_method(self):
2929 ) # 2 weeks in milliseconds
3030 self .client .update_dataset (dataset , ["default_table_expiration_ms" ])
3131
32- def test_bigquery_ingestion_correctness (self ):
32+ def test_bigquery_table_to_datastore_correctness (self ):
3333 # create dataset
3434 ts = pd .Timestamp .now (tz = "UTC" ).round ("ms" )
3535 checked_value = (
@@ -45,15 +45,13 @@ def test_bigquery_ingestion_correctness(self):
4545
4646 # load dataset into BigQuery
4747 job_config = bigquery .LoadJobConfig ()
48- table_id = (
49- f"{ self .gcp_project } .{ self .bigquery_dataset } .correctness_{ int (time .time ())} "
50- )
48+ table_id = f"{ self .gcp_project } .{ self .bigquery_dataset } .table_correctness_{ int (time .time ())} "
5149 job = self .client .load_table_from_dataframe (df , table_id , job_config = job_config )
5250 job .result ()
5351
5452 # create FeatureView
5553 fv = FeatureView (
56- name = "test_bq_correctness " ,
54+ name = "test_bq_table_correctness " ,
5755 entities = ["driver_id" ],
5856 features = [Feature ("value" , ValueType .FLOAT )],
5957 ttl = timedelta (minutes = 5 ),
@@ -78,7 +76,67 @@ def test_bigquery_ingestion_correctness(self):
7876
7977 # run materialize()
8078 fs .materialize (
81- ["test_bq_correctness" ],
79+ [fv .name ],
80+ datetime .utcnow () - timedelta (minutes = 5 ),
81+ datetime .utcnow () - timedelta (minutes = 0 ),
82+ )
83+
84+ # check result of materialize()
85+ entity_key = EntityKeyProto (
86+ entity_names = ["driver_id" ], entity_values = [ValueProto (int64_val = 1 )]
87+ )
88+ t , val = fs ._get_provider ().online_read ("default" , fv , entity_key )
89+ assert abs (val ["value" ].double_val - checked_value ) < 1e-6
90+
91+ def test_bigquery_query_to_datastore_correctness (self ):
92+ # create dataset
93+ ts = pd .Timestamp .now (tz = "UTC" ).round ("ms" )
94+ checked_value = (
95+ random .random ()
96+ ) # random value so test doesn't still work if no values written to online store
97+ data = {
98+ "id" : [1 , 2 , 1 ],
99+ "value" : [0.1 , 0.2 , checked_value ],
100+ "ts_1" : [ts - timedelta (minutes = 2 ), ts , ts ],
101+ "created_ts" : [ts , ts , ts ],
102+ }
103+ df = pd .DataFrame .from_dict (data )
104+
105+ # load dataset into BigQuery
106+ job_config = bigquery .LoadJobConfig ()
107+ table_id = f"{ self .gcp_project } .{ self .bigquery_dataset } .query_correctness_{ int (time .time ())} "
108+ query = f"SELECT * FROM `{ table_id } `"
109+ job = self .client .load_table_from_dataframe (df , table_id , job_config = job_config )
110+ job .result ()
111+
112+ # create FeatureView
113+ fv = FeatureView (
114+ name = "test_bq_query_correctness" ,
115+ entities = ["driver_id" ],
116+ features = [Feature ("value" , ValueType .FLOAT )],
117+ ttl = timedelta (minutes = 5 ),
118+ input = BigQuerySource (
119+ event_timestamp_column = "ts" ,
120+ created_timestamp_column = "created_ts" ,
121+ field_mapping = {"ts_1" : "ts" , "id" : "driver_id" },
122+ date_partition_column = "" ,
123+ query = query ,
124+ ),
125+ )
126+ config = RepoConfig (
127+ metadata_store = "./metadata.db" ,
128+ project = "default" ,
129+ provider = "gcp" ,
130+ online_store = OnlineStoreConfig (
131+ local = LocalOnlineStoreConfig ("online_store.db" )
132+ ),
133+ )
134+ fs = FeatureStore (config = config )
135+ fs .apply ([fv ])
136+
137+ # run materialize()
138+ fs .materialize (
139+ [fv .name ],
82140 datetime .utcnow () - timedelta (minutes = 5 ),
83141 datetime .utcnow () - timedelta (minutes = 0 ),
84142 )
0 commit comments