|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*-- |
| 3 | + |
| 4 | +# Copyright (c) 2023 Oracle and/or its affiliates. |
| 5 | +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ |
| 6 | + |
| 7 | +import pytest |
| 8 | +from ads.feature_store.feature_group_job import FeatureGroupJob |
| 9 | + |
| 10 | +from ads.feature_store.dataset import Dataset |
| 11 | +from ads.feature_store.feature_group import FeatureGroup |
| 12 | +from tests.integration.feature_store.test_base import FeatureStoreTestCase |
| 13 | + |
| 14 | + |
| 15 | +class TestFeatureGroupDatasetListing(FeatureStoreTestCase): |
| 16 | + """Contains integration tests for Feature Group and Dataset Listing.""" |
| 17 | + |
| 18 | + def define_feature_group_resource_with_default_config( |
| 19 | + self, entity_id, feature_store_id |
| 20 | + ) -> "FeatureGroup": |
| 21 | + feature_group_resource = ( |
| 22 | + FeatureGroup() |
| 23 | + .with_description("feature group with default stats config") |
| 24 | + .with_compartment_id(self.COMPARTMENT_ID) |
| 25 | + .with_name(self.get_name("petals3")) |
| 26 | + .with_entity_id(entity_id) |
| 27 | + .with_feature_store_id(feature_store_id) |
| 28 | + .with_primary_keys([]) |
| 29 | + .with_input_feature_details(self.INPUT_FEATURE_DETAILS) |
| 30 | + ) |
| 31 | + return feature_group_resource |
| 32 | + |
| 33 | + def define_feature_group_resource_with_stats_disabled( |
| 34 | + self, entity_id, feature_store_id |
| 35 | + ) -> "FeatureGroup": |
| 36 | + feature_group_resource = ( |
| 37 | + FeatureGroup() |
| 38 | + .with_description("feature group with statistics disabled") |
| 39 | + .with_compartment_id(self.COMPARTMENT_ID) |
| 40 | + .with_name(self.get_name("petals2")) |
| 41 | + .with_entity_id(entity_id) |
| 42 | + .with_feature_store_id(feature_store_id) |
| 43 | + .with_primary_keys([]) |
| 44 | + .with_input_feature_details(self.INPUT_FEATURE_DETAILS) |
| 45 | + .with_statistics_config(False) |
| 46 | + ) |
| 47 | + return feature_group_resource |
| 48 | + |
| 49 | + def define_dataset_resource_with_default_config( |
| 50 | + self, entity_id, feature_store_id, feature_group_name |
| 51 | + ) -> "Dataset": |
| 52 | + name = self.get_name("petals1") |
| 53 | + dataset_resource = ( |
| 54 | + Dataset() |
| 55 | + .with_description("dataset with default statistics configuration") |
| 56 | + .with_compartment_id(self.COMPARTMENT_ID) |
| 57 | + .with_name(self.get_name("petals_ds_default_stat")) |
| 58 | + .with_entity_id(entity_id) |
| 59 | + .with_feature_store_id(feature_store_id) |
| 60 | + .with_query(f"SELECT * FROM `{entity_id}`.{feature_group_name}") |
| 61 | + ) |
| 62 | + return dataset_resource |
| 63 | + |
| 64 | + def define_dataset_resource_with_stats_disabled( |
| 65 | + self, entity_id, feature_store_id, feature_group_name |
| 66 | + ) -> "Dataset": |
| 67 | + name = self.get_name("petals4") |
| 68 | + dataset_resource = ( |
| 69 | + Dataset() |
| 70 | + .with_description("dataset with statistics disabled") |
| 71 | + .with_compartment_id(self.COMPARTMENT_ID) |
| 72 | + .with_name(self.get_name("petals_ds_stat_disabled")) |
| 73 | + .with_entity_id(entity_id) |
| 74 | + .with_feature_store_id(feature_store_id) |
| 75 | + .with_query(f"SELECT * FROM `{entity_id}`.{feature_group_name}") |
| 76 | + .with_statistics_config(False) |
| 77 | + ) |
| 78 | + return dataset_resource |
| 79 | + |
| 80 | + def test_feature_group_listing_without_limit(self): |
| 81 | + """Tests listing of feature group resources with user defined limit.""" |
| 82 | + fs = self.define_feature_store_resource().create() |
| 83 | + assert fs.oci_fs.id |
| 84 | + |
| 85 | + entity = self.create_entity_resource(fs) |
| 86 | + assert entity.oci_fs_entity.id |
| 87 | + |
| 88 | + fg1 = self.define_feature_group_resource_with_default_config( |
| 89 | + entity.oci_fs_entity.id, fs.oci_fs.id |
| 90 | + ).create() |
| 91 | + assert fg1.oci_feature_group.id |
| 92 | + fg1.materialise(self.data) |
| 93 | + fg1.materialise(self.data2) |
| 94 | + |
| 95 | + fg1_job_list = FeatureGroupJob.list(compartment_id=self.COMPARTMENT_ID) |
| 96 | + assert fg1_job_list is not None |
| 97 | + assert len(fg1_job_list) == 2 |
| 98 | + |
| 99 | + fg2 = self.define_feature_group_resource_with_stats_disabled( |
| 100 | + entity.oci_fs_entity.id, fs.oci_fs.id |
| 101 | + ).create() |
| 102 | + assert fg2.oci_feature_group.id |
| 103 | + fg2.materialise(self.data3) |
| 104 | + |
| 105 | + fg_list = FeatureGroup.list(compartment_id=self.COMPARTMENT_ID) |
| 106 | + assert fg_list is not None |
| 107 | + assert len(fg_list) == 2 |
| 108 | + |
| 109 | + self.clean_up_feature_group(fg1) |
| 110 | + self.clean_up_feature_group(fg2) |
| 111 | + self.clean_up_entity(entity) |
| 112 | + self.clean_up_feature_store(fs) |
| 113 | + |
| 114 | + def test_feature_group_listing_with_limit(self): |
| 115 | + """Tests listing of feature group resources with user defined limit.""" |
| 116 | + fs = self.define_feature_store_resource().create() |
| 117 | + assert fs.oci_fs.id |
| 118 | + |
| 119 | + entity = self.create_entity_resource(fs) |
| 120 | + assert entity.oci_fs_entity.id |
| 121 | + |
| 122 | + fg1 = self.define_feature_group_resource_with_default_config( |
| 123 | + entity.oci_fs_entity.id, fs.oci_fs.id |
| 124 | + ).create() |
| 125 | + assert fg1.oci_feature_group.id |
| 126 | + fg1.materialise(self.data) |
| 127 | + fg1.materialise(self.data2) |
| 128 | + |
| 129 | + fg1_job_list = FeatureGroupJob.list( |
| 130 | + compartment_id=self.COMPARTMENT_ID, |
| 131 | + feature_group_id=fg1.id, |
| 132 | + sort_by="timeCreated", |
| 133 | + limit="1", |
| 134 | + ) |
| 135 | + assert fg1_job_list is not None |
| 136 | + assert len(fg1_job_list) == 1 |
| 137 | + |
| 138 | + fg2 = self.define_feature_group_resource_with_stats_disabled( |
| 139 | + entity.oci_fs_entity.id, fs.oci_fs.id |
| 140 | + ).create() |
| 141 | + assert fg2.oci_feature_group.id |
| 142 | + fg2.materialise(self.data3) |
| 143 | + |
| 144 | + fg_list = FeatureGroup.list( |
| 145 | + compartment_id=self.COMPARTMENT_ID, |
| 146 | + sort_by="timeCreated", |
| 147 | + limit="1", |
| 148 | + ) |
| 149 | + assert fg_list is not None |
| 150 | + assert len(fg_list) == 1 |
| 151 | + |
| 152 | + self.clean_up_feature_group(fg1) |
| 153 | + self.clean_up_feature_group(fg2) |
| 154 | + self.clean_up_entity(entity) |
| 155 | + self.clean_up_feature_store(fs) |
| 156 | + |
| 157 | + def test_dataset_listing_without_limit(self): |
| 158 | + """Tests listing of dataset resources without any limit.""" |
| 159 | + fs = self.define_feature_store_resource().create() |
| 160 | + assert fs.oci_fs.id |
| 161 | + |
| 162 | + entity = self.create_entity_resource(fs) |
| 163 | + assert entity.oci_fs_entity.id |
| 164 | + |
| 165 | + fg = self.define_feature_group_resource( |
| 166 | + entity.oci_fs_entity.id, fs.oci_fs.id |
| 167 | + ).create() |
| 168 | + assert fg.oci_feature_group.id |
| 169 | + |
| 170 | + fg.materialise(self.data) |
| 171 | + |
| 172 | + dataset = self.define_dataset_resource( |
| 173 | + entity.oci_fs_entity.id, fs.oci_fs.id, fg.oci_feature_group.name |
| 174 | + ).create() |
| 175 | + assert dataset.oci_dataset.id |
| 176 | + |
| 177 | + dataset.materialise() |
| 178 | + ds_list = Dataset.list(compartment_id=self.COMPARTMENT_ID) |
| 179 | + assert ds_list is not None |
| 180 | + assert len(ds_list) == 1 |
| 181 | + |
| 182 | + self.clean_up_dataset(dataset) |
| 183 | + self.clean_up_feature_group(fg) |
| 184 | + self.clean_up_entity(entity) |
| 185 | + self.clean_up_feature_store(fs) |
0 commit comments