def from_proto(cls, feature_table_proto: FeatureTableProto): """ Creates a feature table from a protobuf representation of a feature table Args: feature_table_proto: A protobuf representation of a feature table Returns: Returns a FeatureTableProto object based on the feature table protobuf """ feature_table = cls( name=feature_table_proto.spec.name, entities=[entity for entity in feature_table_proto.spec.entities], features=[ Feature.from_proto(feature) for feature in feature_table_proto.spec.features ], labels=feature_table_proto.spec.labels, max_age=(None if feature_table_proto.spec.max_age.seconds == 0 and feature_table_proto.spec.max_age.nanos == 0 else feature_table_proto.spec.max_age), batch_source=DataSource.from_proto( feature_table_proto.spec.batch_source), stream_source=( None if not feature_table_proto.spec.stream_source.ByteSize() else DataSource.from_proto(feature_table_proto.spec.stream_source)), ) feature_table._created_timestamp = feature_table_proto.meta.created_timestamp return feature_table
def from_proto(cls, feature_view_proto: FeatureViewProto): """ Creates a feature view from a protobuf representation of a feature view. Args: feature_view_proto: A protobuf representation of a feature view. Returns: A FeatureViewProto object based on the feature view protobuf. """ batch_source = DataSource.from_proto(feature_view_proto.spec.batch_source) stream_source = ( DataSource.from_proto(feature_view_proto.spec.stream_source) if feature_view_proto.spec.HasField("stream_source") else None ) feature_view = cls( name=feature_view_proto.spec.name, entities=[entity for entity in feature_view_proto.spec.entities], features=[ Feature( name=feature.name, dtype=ValueType(feature.value_type), labels=dict(feature.labels), ) for feature in feature_view_proto.spec.features ], tags=dict(feature_view_proto.spec.tags), online=feature_view_proto.spec.online, ttl=( None if feature_view_proto.spec.ttl.seconds == 0 and feature_view_proto.spec.ttl.nanos == 0 else feature_view_proto.spec.ttl ), batch_source=batch_source, stream_source=stream_source, ) if feature_view_proto.meta.HasField("created_timestamp"): feature_view.created_timestamp = ( feature_view_proto.meta.created_timestamp.ToDatetime() ) if feature_view_proto.meta.HasField("last_updated_timestamp"): feature_view.last_updated_timestamp = ( feature_view_proto.meta.last_updated_timestamp.ToDatetime() ) for interval in feature_view_proto.meta.materialization_intervals: feature_view.materialization_intervals.append( ( utils.make_tzaware(interval.start_time.ToDatetime()), utils.make_tzaware(interval.end_time.ToDatetime()), ) ) return feature_view
def from_proto(cls, feature_view_proto: FeatureViewProto): """ Creates a feature view from a protobuf representation of a feature view. Args: feature_view_proto: A protobuf representation of a feature view. Returns: A FeatureViewProto object based on the feature view protobuf. """ batch_source = DataSource.from_proto( feature_view_proto.spec.batch_source) stream_source = ( DataSource.from_proto(feature_view_proto.spec.stream_source) if feature_view_proto.spec.HasField("stream_source") else None) feature_view = cls( name=feature_view_proto.spec.name, entities=[entity for entity in feature_view_proto.spec.entities], schema=[ Field.from_proto(field_proto) for field_proto in feature_view_proto.spec.features ], description=feature_view_proto.spec.description, tags=dict(feature_view_proto.spec.tags), owner=feature_view_proto.spec.owner, online=feature_view_proto.spec.online, ttl=(timedelta( days=0) if feature_view_proto.spec.ttl.ToNanoseconds() == 0 else feature_view_proto.spec.ttl.ToTimedelta()), source=batch_source, ) if stream_source: feature_view.stream_source = stream_source # FeatureViewProjections are not saved in the FeatureView proto. # Create the default projection. feature_view.projection = FeatureViewProjection.from_definition( feature_view) if feature_view_proto.meta.HasField("created_timestamp"): feature_view.created_timestamp = ( feature_view_proto.meta.created_timestamp.ToDatetime()) if feature_view_proto.meta.HasField("last_updated_timestamp"): feature_view.last_updated_timestamp = ( feature_view_proto.meta.last_updated_timestamp.ToDatetime()) for interval in feature_view_proto.meta.materialization_intervals: feature_view.materialization_intervals.append(( utils.make_tzaware(interval.start_time.ToDatetime()), utils.make_tzaware(interval.end_time.ToDatetime()), )) return feature_view
def GetHistoricalFeatures(self, request: GetHistoricalFeaturesRequest, context): """Produce a training dataset, return a job id that will provide a file reference""" if not self.is_whitelisted(request.project): raise ValueError( f"Project {request.project} is not whitelisted. Please contact your Feast administrator to whitelist it." ) job = start_historical_feature_retrieval_job( client=self.client, project=request.project, entity_source=DataSource.from_proto(request.entity_source), feature_tables=self.client._get_feature_tables_from_feature_refs( list(request.feature_refs), request.project), output_format=request.output_format, output_path=request.output_location, ) output_file_uri = job.get_output_file_uri(block=False) job_start_timestamp = Timestamp() job_start_timestamp.FromDatetime(job.get_start_time()) return GetHistoricalFeaturesResponse( id=job.get_id(), output_file_uri=output_file_uri, job_start_time=job_start_timestamp, )
def from_proto(cls, feature_view_proto: FeatureViewProto): """ Creates a feature view from a protobuf representation of a feature view Args: feature_view_proto: A protobuf representation of a feature view Returns: Returns a FeatureViewProto object based on the feature view protobuf """ feature_view = cls( name=feature_view_proto.spec.name, entities=[entity for entity in feature_view_proto.spec.entities], features=[ Feature( name=feature.name, dtype=ValueType(feature.value_type), labels=feature.labels, ) for feature in feature_view_proto.spec.features ], tags=dict(feature_view_proto.spec.tags), online=feature_view_proto.spec.online, ttl=(None if feature_view_proto.spec.ttl.seconds == 0 and feature_view_proto.spec.ttl.nanos == 0 else feature_view_proto.spec.ttl), input=DataSource.from_proto(feature_view_proto.spec.input), ) feature_view.created_timestamp = feature_view_proto.meta.created_timestamp return feature_view
def GetHistoricalFeatures(self, request, context): """Produce a training dataset, return a job id that will provide a file reference""" job = self.client.get_historical_features( request.feature_refs, entity_source=DataSource.from_proto(request.entity_source), project=request.project, output_location=request.output_location, ) output_file_uri = job.get_output_file_uri(block=False) return GetHistoricalFeaturesResponse(id=job.get_id(), output_file_uri=output_file_uri)
def GetHistoricalFeatures(self, request: GetHistoricalFeaturesRequest, context): """Produce a training dataset, return a job id that will provide a file reference""" job = start_historical_feature_retrieval_job( client=self.client, project=request.project, entity_source=DataSource.from_proto(request.entity_source), feature_tables=self.client._get_feature_tables_from_feature_refs( list(request.feature_refs), request.project), output_format=request.output_format, output_path=request.output_location, ) output_file_uri = job.get_output_file_uri(block=False) return GetHistoricalFeaturesResponse(id=job.get_id(), output_file_uri=output_file_uri)
def list_data_sources(self, project: str, allow_cache: bool = False) -> List[DataSource]: """ Retrieve a list of data sources from the registry Args: project: Filter data source based on project name allow_cache: Whether to allow returning data sources from a cached registry Returns: List of data sources """ registry_proto = self._get_registry_proto(allow_cache=allow_cache) data_sources = [] for data_source_proto in registry_proto.data_sources: if data_source_proto.project == project: data_sources.append(DataSource.from_proto(data_source_proto)) return data_sources
def get_data_source(self, name: str, project: str, allow_cache: bool = False) -> DataSource: """ Retrieves a data source. Args: name: Name of data source project: Feast project that this data source belongs to allow_cache: Whether to allow returning this data source from a cached registry Returns: Returns either the specified data source, or raises an exception if none is found """ registry = self._get_registry_proto(allow_cache=allow_cache) for data_source in registry.data_sources: if data_source.project == project and data_source.name == name: return DataSource.from_proto(data_source) raise DataSourceObjectNotFoundException(name, project=project)