Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update file api #2470

Merged
merged 12 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference/data-sources/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ from feast.data_format import ParquetFormat

parquet_file_source = FileSource(
file_format=ParquetFormat(),
file_url="file:///feast/customer.parquet",
path="file:///feast/customer.parquet",
)
```

Expand Down
8 changes: 8 additions & 0 deletions protos/feast/core/DataSource.proto
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,18 @@ message DataSource {
// s3://path/to/file for AWS S3 storage
// gs://path/to/file for GCP GCS storage
// file:///path/to/file for local storage
// Deprecated in Feast 0.23.0
string file_url = 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should change this in place; serialized protobufs only use the index number not the field name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I didn't know that but that makes a lot of sense! Thanks for the suggestion that makes the update so much easier.


// override AWS S3 storage endpoint with custom S3 endpoint
string s3_endpoint_override = 3;

// Target URL of file to retrieve and source features from.
// s3://path/to/file for AWS S3 storage
// gs://path/to/file for GCP GCS storage
// file:///path/to/file for local storage
// Deprecated in Feast 0.23.0
string uri = 4;
}

// Defines options for DataSource that sources features from a BigQuery Query
Expand Down
3 changes: 1 addition & 2 deletions sdk/python/feast/infra/offline_stores/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ def _to_arrow_internal(self):

def persist(self, storage: SavedDatasetStorage):
assert isinstance(storage, SavedDatasetFileStorage)

filesystem, path = FileSource.create_filesystem_and_path(
storage.file_options.file_url, storage.file_options.s3_endpoint_override,
storage.file_options.uri, storage.file_options.s3_endpoint_override,
)

if path.endswith(".parquet"):
Expand Down
48 changes: 30 additions & 18 deletions sdk/python/feast/infra/offline_stores/file_source.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from typing import Callable, Dict, Iterable, Optional, Tuple

from pyarrow._fs import FileSystem
Expand Down Expand Up @@ -60,7 +61,7 @@ def __init__(
)
self.file_options = FileOptions(
file_format=file_format,
file_url=path,
uri=path,
s3_endpoint_override=s3_endpoint_override,
)

Expand All @@ -85,7 +86,6 @@ def __eq__(self, other):

return (
self.name == other.name
and self.file_options.file_url == other.file_options.file_url
and self.file_options.file_format == other.file_options.file_format
and self.event_timestamp_column == other.event_timestamp_column
and self.created_timestamp_column == other.created_timestamp_column
Expand All @@ -102,15 +102,15 @@ def path(self):
"""
Returns the path of this file data source.
"""
return self.file_options.file_url
return self.file_options.uri

@staticmethod
def from_proto(data_source: DataSourceProto):
return FileSource(
name=data_source.name,
field_mapping=dict(data_source.field_mapping),
file_format=FileFormat.from_proto(data_source.file_options.file_format),
path=data_source.file_options.file_url,
path=data_source.file_options.uri,
event_timestamp_column=data_source.event_timestamp_column,
created_timestamp_column=data_source.created_timestamp_column,
date_partition_column=data_source.date_partition_column,
Expand Down Expand Up @@ -180,19 +180,20 @@ class FileOptions:
def __init__(
self,
file_format: Optional[FileFormat],
file_url: Optional[str],
s3_endpoint_override: Optional[str],
uri: Optional[str],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanted to confirm that this is not user facing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup isn't called anymore but maybe @adchia can also confirm?

):
"""
FileOptions initialization method

Args:
file_format (FileFormat, optional): file source format eg. parquet
file_url (str, optional): file source url eg. s3:// or local file
s3_endpoint_override (str, optional): custom s3 endpoint (used only with s3 file_url)
s3_endpoint_override (str, optional): custom s3 endpoint (used only with s3 uri)
uri (str, optional): file source url eg. s3:// or local file

"""
self._file_format = file_format
self._file_url = file_url
self._uri = uri
self._s3_endpoint_override = s3_endpoint_override

@property
Expand All @@ -210,18 +211,18 @@ def file_format(self, file_format):
self._file_format = file_format

@property
def file_url(self):
def uri(self):
"""
Returns the file url of this file
"""
return self._file_url
return self.uri

@file_url.setter
def file_url(self, file_url):
@uri.setter
def uri(self, uri):
"""
Sets the file url of this file
"""
self._file_url = file_url
self._uri = uri

@property
def s3_endpoint_override(self):
Expand Down Expand Up @@ -250,7 +251,7 @@ def from_proto(cls, file_options_proto: DataSourceProto.FileOptions):
"""
file_options = cls(
file_format=FileFormat.from_proto(file_options_proto.file_format),
file_url=file_options_proto.file_url,
uri=file_options_proto.uri,
s3_endpoint_override=file_options_proto.s3_endpoint_override,
)
return file_options
Expand All @@ -267,7 +268,7 @@ def to_proto(self) -> DataSourceProto.FileOptions:
file_format=(
None if self.file_format is None else self.file_format.to_proto()
),
file_url=self.file_url,
uri=self.uri,
s3_endpoint_override=self.s3_endpoint_override,
)

Expand All @@ -286,16 +287,27 @@ def __init__(
s3_endpoint_override: Optional[str] = None,
):
self.file_options = FileOptions(
file_url=path,
file_format=file_format,
s3_endpoint_override=s3_endpoint_override,
uri=path,
)

@staticmethod
def from_proto(storage_proto: SavedDatasetStorageProto) -> SavedDatasetStorage:
file_options = FileOptions.from_proto(storage_proto.file_storage)
if file_options.uri:
path = file_options.uri
else:
path = file_options.file_url
if path:
warnings.warn(
(
"FileSource Proto is replacing the file_url field in FileOptions with uri soon."
"Feast 0.23+ will no longer support file_url. Please change to using uri in your protos."
),
)
return SavedDatasetFileStorage(
path=file_options.file_url,
path=path,
file_format=file_options.file_format,
s3_endpoint_override=file_options.s3_endpoint_override,
)
Expand All @@ -305,7 +317,7 @@ def to_proto(self) -> SavedDatasetStorageProto:

def to_data_source(self) -> DataSource:
return FileSource(
path=self.file_options.file_url,
path=self.file_options.uri,
file_format=self.file_options.file_format,
s3_endpoint_override=self.file_options.s3_endpoint_override,
)