Skip to content

Commit d8a3795

Browse files
authored
fix historical test for azure (#1262)
* fix historical test for azure Signed-off-by: Jacob Klegar <jacob@tecton.ai> * fix adlfs version Signed-off-by: Jacob Klegar <jacob@tecton.ai> * overwrite existing Azure blobs to match s3 and gcs Signed-off-by: Jacob Klegar <jacob@tecton.ai> * fix linting Signed-off-by: Jacob Klegar <jacob@tecton.ai>
1 parent 468f417 commit d8a3795

4 files changed

Lines changed: 30 additions & 6 deletions

File tree

sdk/python/feast/pyspark/launchers/k8s/k8s.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import yaml
1010
from kubernetes.client.api import CustomObjectsApi
1111

12-
from feast.constants import ConfigOptions as opt
1312
from feast.pyspark.abc import (
1413
BQ_SPARK_PACKAGE,
1514
BatchIngestionJob,
@@ -196,7 +195,7 @@ def _get_azure_credentials(self):
196195
account_key = self._azure_account_key
197196
if account_name is None or account_key is None:
198197
raise Exception(
199-
f"Using Azure blob storage requires Azure blob account name and access key to be set in config"
198+
"Using Azure blob storage requires Azure blob account name and access key to be set in config"
200199
)
201200
return {
202201
f"spark.hadoop.fs.azure.account.key.{account_name}.blob.core.windows.net": f"{account_key}"

sdk/python/feast/staging/storage_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def upload_fileobj(
397397
)
398398
bucket, key = self._uri_to_bucket_key(remote_uri)
399399
container_client = self.blob_service_client.get_container_client(bucket)
400-
container_client.upload_blob(name=key, data=fileobj)
400+
container_client.upload_blob(name=key, data=fileobj, overwrite=True)
401401
return remote_uri
402402

403403

sdk/python/requirements-ci.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ pytest-timeout==1.4.2
2121
pytest-ordering==0.6.*
2222
pytest-mock==1.10.4
2323
PyYAML==5.3.1
24-
great-expectations==0.13.2
24+
great-expectations==0.13.2
25+
adlfs==0.5.9

tests/e2e/test_historical_features.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
from pyarrow import parquet
1212

1313
from feast import Client, Entity, Feature, FeatureTable, ValueType
14+
from feast.constants import ConfigOptions as opt
1415
from feast.data_source import BigQuerySource, FileSource
1516
from feast.pyspark.abc import SparkJobStatus
1617

1718
np.random.seed(0)
1819

1920

20-
def read_parquet(uri):
21+
def read_parquet(uri, azure_account_name=None, azure_account_key=None):
2122
parsed_uri = urlparse(uri)
2223
if parsed_uri.scheme == "file":
2324
return pd.read_parquet(parsed_uri.path)
@@ -42,6 +43,16 @@ def read_parquet(uri):
4243
files = ["s3://" + path for path in fs.glob(s3uri + "/part-*")]
4344
ds = parquet.ParquetDataset(files, filesystem=fs)
4445
return ds.read().to_pandas()
46+
elif parsed_uri.scheme == "wasbs":
47+
import adlfs
48+
49+
fs = adlfs.AzureBlobFileSystem(
50+
account_name=azure_account_name, account_key=azure_account_key
51+
)
52+
uripath = parsed_uri.username + parsed_uri.path
53+
files = fs.glob(uripath + "/part-*")
54+
ds = parquet.ParquetDataset(files, filesystem=fs)
55+
return ds.read().to_pandas()
4556
else:
4657
raise ValueError(f"Unsupported URL scheme {uri}")
4758

@@ -75,6 +86,13 @@ def generate_data():
7586
return transactions_df, customer_df
7687

7788

89+
def _get_azure_creds(feast_client: Client):
90+
return (
91+
feast_client._config.get(opt.AZURE_BLOB_ACCOUNT_NAME, None),
92+
feast_client._config.get(opt.AZURE_BLOB_ACCOUNT_ACCESS_KEY, None),
93+
)
94+
95+
7896
def test_historical_features(
7997
feast_client: Client,
8098
tfrecord_feast_client: Client,
@@ -108,7 +126,13 @@ def test_historical_features(
108126

109127
job = feast_client.get_historical_features(feature_refs, customers_df)
110128
output_dir = job.get_output_file_uri()
111-
joined_df = read_parquet(output_dir)
129+
130+
# will both be None if not using Azure blob storage
131+
account_name, account_key = _get_azure_creds(feast_client)
132+
133+
joined_df = read_parquet(
134+
output_dir, azure_account_name=account_name, azure_account_key=account_key
135+
)
112136

113137
expected_joined_df = pd.DataFrame(
114138
{

0 commit comments

Comments
 (0)