1+ import ast
2+ import json
3+ import random
4+ import string
5+
6+ import pandas as pd
7+ import pytest
8+
9+ from ads .feature_store .common .exceptions import NotMaterializedError
10+ from ads .feature_store .dataset import Dataset
11+ from ads .feature_store .statistics_config import StatisticsConfig
12+ from tests .integration .feature_store .test_base import FeatureStoreTestCase
13+ from ads .feature_store .feature_group import FeatureGroup
14+
15+
16+ class TestAsOfForFeatureGroupAndDataset (FeatureStoreTestCase ):
17+ """Contains integration tests for as_of support for feature groups and datasets"""
18+
19+ # Generate random data
20+ test_as_of_data = {
21+ 'Name' : [random .choice (['Alice' , 'Bob' , 'Charlie' , 'David' ]) for _ in range (10 )],
22+ 'Age' : [random .randint (20 , 40 ) for _ in range (10 )],
23+ 'Score' : [round (random .uniform (0 , 100 ), 2 ) for _ in range (10 )],
24+ 'City' : [random .choice (['New York' , 'Los Angeles' , 'Chicago' , 'Houston' ]) for _ in range (10 )],
25+ 'Gender' : [random .choice (['Male' , 'Female' ]) for _ in range (10 )],
26+ 'ID' : ['' .join (random .choices (string .ascii_uppercase , k = 5 )) for _ in range (10 )]
27+ }
28+
29+ as_of_data_frame = pd .DataFrame (test_as_of_data )
30+
31+ def define_feature_group_resource (
32+ self , entity_id , feature_store_id
33+ ) -> "FeatureGroup" :
34+ feature_group_resource = (
35+ FeatureGroup ()
36+ .with_description ("feature group with statistics disabled" )
37+ .with_compartment_id (self .COMPARTMENT_ID )
38+ .with_name (self .get_name ("petals2" ))
39+ .with_entity_id (entity_id )
40+ .with_feature_store_id (feature_store_id )
41+ .with_primary_keys (['ID' ])
42+ .with_schema_details_from_dataframe (self .as_of_data_frame )
43+ .with_statistics_config (False )
44+ )
45+ return feature_group_resource
46+
47+ def define_dataset_resource (
48+ self , entity_id , feature_store_id , feature_group_name
49+ ) -> "Dataset" :
50+ name = self .get_name ("petals_ds" )
51+ dataset_resource = (
52+ Dataset ()
53+ .with_description ("dataset description" )
54+ .with_compartment_id (self .COMPARTMENT_ID )
55+ .with_name (name )
56+ .with_entity_id (entity_id )
57+ .with_feature_store_id (feature_store_id )
58+ .with_query (f"SELECT * FROM `{ entity_id } `.{ feature_group_name } " )
59+ .with_statistics_config (
60+ StatisticsConfig (True , columns = ["sepal_length" , "petal_width" ])
61+ )
62+ )
63+ return dataset_resource
64+
65+ def test_as_of_for_non_materialized_feature_group (self ):
66+ fs = self .define_feature_store_resource ().create ()
67+ assert fs .oci_fs .id
68+
69+ entity = self .create_entity_resource (fs )
70+ assert entity .oci_fs_entity .id
71+
72+ fg = self .define_feature_group_resource (
73+ entity .oci_fs_entity .id , fs .oci_fs .id
74+ ).create ()
75+ assert fg .oci_feature_group .id
76+
77+ with pytest .raises (NotMaterializedError ):
78+ fg .as_of ()
79+
80+ self .clean_up_feature_group (fg )
81+ self .clean_up_entity (entity )
82+ self .clean_up_feature_store (fs )
0 commit comments