GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — feast/sdk/python/feast/data_format.py at master · feast-dev/feast Expand file tree/ Copy pathdata_format.pyMore file actions 177 lines (139 loc) · 5.13 KB / Copy pathdata_format.pyFile metadata and controls177 lines (139 loc) · 5.13 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 # Copyright 2020 The Feast Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY aIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from abc import ABC, abstractmethod from feast.protos.feast.core.DataFormat_pb2 import FileFormat as FileFormatProto from feast.protos.feast.core.DataFormat_pb2 import StreamFormat as StreamFormatProto from feast.protos.feast.core.DataFormat_pb2 import TableFormat as TableFormatProto class FileFormat(ABC): """ Defines an abtract file forma used to encode feature data in files """ @abstractmethod def to_proto(self): """ Convert this FileFormat into its protobuf representation. """ pass def __eq__(self, other): if not isinstance(other, FileFormat): return False return self.to_proto() == other.to_proto() @classmethod def from_proto(cls, proto): """ Construct this FileFormat from its protobuf representation. Raises NotImplementedError if FileFormat specified in given proto is not supported. """ fmt = proto.WhichOneof("format") if fmt == "parquet_format": return ParquetFormat() elif fmt == "delta_format": return DeltaFormat() if fmt is None: return None raise NotImplementedError(f"FileFormat is unsupported: {fmt}") def __str__(self): """ String representation of the file format passed to spark """ raise NotImplementedError() class ParquetFormat(FileFormat): """ Defines the Parquet data format """ def to_proto(self): return FileFormatProto(parquet_format=FileFormatProto.ParquetFormat()) def __str__(self): return "parquet" class DeltaFormat(FileFormat): """ Defines delta data format (deprecated - use TableFormat.DeltaFormat instead) """ def to_proto(self): # Reference TableFormat.DeltaFormat since DeltaFormat is now nested there return FileFormatProto(delta_format=TableFormatProto.DeltaFormat()) def __str__(self): return "delta" class StreamFormat(ABC): """ Defines an abtracts streaming data format used to encode feature data in streams """ @abstractmethod def to_proto(self): """ Convert this StreamFormat into its protobuf representation. """ pass def __eq__(self, other): if not isinstance(other, StreamFormat): return False return self.to_proto() == other.to_proto() @classmethod def from_proto(cls, proto): """ Construct this StreamFormat from its protobuf representation. """ fmt = proto.WhichOneof("format") if fmt == "avro_format": return AvroFormat(schema_json=proto.avro_format.schema_json) if fmt == "json_format": return JsonFormat(schema_json=proto.json_format.schema_json) if fmt == "proto_format": return ProtoFormat(class_path=proto.proto_format.class_path) raise NotImplementedError(f"StreamFormat is unsupported: {fmt}") class AvroFormat(StreamFormat): """ Defines the Avro streaming data format that encodes data in Avro format """ def __init__(self, schema_json: str): """ Construct a new Avro data format. Args: schema_json: Avro schema definition in JSON """ self.schema_json = schema_json def to_proto(self): proto = StreamFormatProto.AvroFormat(schema_json=self.schema_json) return StreamFormatProto(avro_format=proto) class JsonFormat(StreamFormat): """ Defines the Json streaming data format that encodes data in Json format """ def __init__(self, schema_json: str): """ Construct a new Json data format. For spark, uses pyspark ddl string format. Example shown here: https://vincent.doba.fr/posts/20211004_spark_data_description_language_for_defining_spark_schema/ Args: schema_json: Json schema definition """ self.schema_json = schema_json def to_proto(self): proto = StreamFormatProto.JsonFormat(schema_json=self.schema_json) return StreamFormatProto(json_format=proto) class ProtoFormat(StreamFormat): """ Defines the Protobuf data format """ def __init__(self, class_path: str): """ Construct a new Protobuf data format. Args: class_path: Class path to the Java Protobuf class that can be used to decode protobuf messages.; """ self.class_path = class_path def to_proto(self): return StreamFormatProto( proto_format=StreamFormatProto.ProtoFormat(class_path=self.class_path) ) |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |