MCPcopy
hub / github.com/pathwaycom/pathway / _create_column_definitions

Function _create_column_definitions

python/pathway/internals/schema.py:184–258  ·  view source on GitHub ↗
(
    schema: SchemaMetaclass,
    bases: tuple[type],
    schema_properties: SchemaProperties,
)

Source from the content-addressed store, hash-verified

182
183
184def _create_column_definitions(
185 schema: SchemaMetaclass,
186 bases: tuple[type],
187 schema_properties: SchemaProperties,
188) -> dict[str, ColumnSchema]:
189 localns = locals()
190 # Update locals to handle recursive Schema definitions
191 localns[schema.__name__] = schema
192 annotations = get_type_hints(schema, localns=localns)
193 fields = _cls_fields(schema)
194 for base in bases:
195 if not isinstance(base, SchemaMetaclass):
196 continue
197 for column_name, column_schema in base.__columns__.items():
198 if column_name not in fields:
199 fields[column_name] = column_schema.to_definition()
200
201 columns = {}
202
203 for column_name, annotation in annotations.items():
204 col_dtype = dt.wrap(annotation)
205 column = fields.pop(column_name, column_definition(dtype=col_dtype))
206
207 if not isinstance(column, ColumnDefinition):
208 raise ValueError(
209 f"`{column_name}` should be a column definition, found {type(column)}"
210 )
211
212 dtype = column.dtype
213 if dtype is None:
214 dtype = col_dtype
215
216 if col_dtype != dtype:
217 raise TypeError(
218 f"type annotation of column `{column_name}` does not match column definition"
219 )
220
221 column_name = column.name or column_name
222
223 def _get_column_property(property_name: str, default: Any) -> Any:
224 match (
225 getattr(column, property_name),
226 getattr(schema_properties, property_name),
227 ):
228 case (None, None):
229 return default
230 case (None, schema_property):
231 return schema_property
232 case (column_property, None):
233 return column_property
234 case (column_property, schema_property):
235 if column_property != schema_property:
236 raise ValueError(
237 f"ambiguous property; schema property `{property_name}` has"
238 + f" value {schema_property!r} but column"
239 + f" `{column_name}` got {column_property!r}"
240 )
241 return column_property

Callers 1

__init__Method · 0.85

Calls 9

_cls_fieldsFunction · 0.85
column_definitionFunction · 0.85
ColumnSchemaClass · 0.85
_get_column_propertyFunction · 0.85
itemsMethod · 0.80
to_definitionMethod · 0.80
wrapMethod · 0.80
joinMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected