MCPcopy Create free account
hub / github.com/alibaba/zvec / alter_column

Method alter_column

python/zvec/model/collection.py:188–234  ·  view source on GitHub ↗

Rename a column, update its schema. This method supports three atomic operations: 1. Rename only (when `field_schema` is None). 2. Modify schema only (when `new_name` is None or empty string). Args: old_name (str): The current name of the column to b

(
        self,
        old_name: str,
        new_name: Optional[str] = None,
        field_schema: Optional[FieldSchema] = None,
        option: AlterColumnOption = AlterColumnOption(),
    )

Source from the content-addressed store, hash-verified

186 self._querier._schema = self._schema
187
188 def alter_column(
189 self,
190 old_name: str,
191 new_name: Optional[str] = None,
192 field_schema: Optional[FieldSchema] = None,
193 option: AlterColumnOption = AlterColumnOption(),
194 ) -> None:
195 """Rename a column, update its schema.
196
197 This method supports three atomic operations:
198 1. Rename only (when `field_schema` is None).
199 2. Modify schema only (when `new_name` is None or empty string).
200
201 Args:
202 old_name (str): The current name of the column to be altered.
203 new_name (Optional[str]): The new name for the column.
204 - If provided and non-empty, the column will be renamed.
205 - If `None` or empty string, no rename occurs.
206 field_schema (Optional[FieldSchema]): The new schema definition.
207 - If provided, the column's type, dimension, or other properties will be updated.
208 - If `None`, only renaming (if requested) is performed.
209 option (AlterColumnOption, optional): Options controlling the alteration behavior.
210 Defaults to ``AlterColumnOption()``.
211
212 **Limitation**: This operation **only supports scalar numeric columns**. such as:
213 - `DOUBLE`, `FLOAT`,
214 - `INT32`, `INT64`, `UINT32`, `UINT64`
215
216 Note:
217 - Schema modification may trigger data migration or index rebuild.
218
219 Examples:
220 >>> # Rename column only
221 >>> results = collection.alter_column(old_name="id", new_name="doc_id")
222
223 >>> # Modify schema only
224 >>> new_schema = FieldSchema(name="doc_id", dtype=DataType.INT64)
225 >>> collection.alter_column("id", field_schema=new_schema)
226 """
227 self._obj.AlterColumn(
228 old_name,
229 new_name or "",
230 field_schema._get_object() if field_schema else None,
231 option,
232 )
233 self._schema = CollectionSchema._from_core(self._obj.Schema())
234 self._querier._schema = self._schema
235
236 # ========== Collection DDL Methods ==========
237 @overload

Calls 4

AlterColumnMethod · 0.80
SchemaMethod · 0.80
_get_objectMethod · 0.45
_from_coreMethod · 0.45