Skip to main content
Enterprise only

Overview

A column that a Geneva UDF filled can be handed over to a registered Function without computing its values again. The ALTER TABLE ... ALTER COLUMN ... AS statement binds a Function to an existing column. It keeps the stored values and does not run the Function. After that, a refresh computes only the rows that have no value yet, and the Function fills new rows from then on. The statement accepts only a plain column. It refuses a column that still carries its Geneva UDF declaration, so the procedure has three steps:
  1. Replace the Geneva column with a plain copy of its values.
  2. Bind the plain column to the Function.
  3. Refresh the column to fill the rows that are still NULL.
The examples use a documents table with a text column, an embedding column and a summary column. The Functions embed_text and summarize are registered at version 1.

Prerequisites

  • A registered Function for each column. See Create a Function. Its output type must match the column’s type exactly, including the vector dimension. Use the same model and parameters as the UDF that filled the column, so old and new rows are comparable.
  • A table that does not have the Realtime Engine enabled. Steps 1 and 2 are refused on a table that has it.
  • A window in which nothing writes to the table or changes its schema, for steps 1 and 2.

Geneva to Functions mapping

Procedure

Before you start, record which columns Geneva filled and how many rows each one has filled. You compare against these counts in Validation.

Step 1: Replace the Geneva column with a plain copy

Stop writes to the table. Then copy each Geneva column, drop the original and rename the copy back. The copy runs on the deployment and reads the stored values. It does not call the UDF.
Dropping the original column also removes its index, so build the index on the copy first. Use your own index settings in place of IvfPq(distance_type="cosine"). The helper drops one column at a time. If one UDF fills several columns, copy each of them first, drop them together in one drop_columns call, then rename each copy. Convert every Geneva column you plan to bind before you go to step 2. The converted columns now come last in the schema, and each index keeps the name it was built with, such as embedding_copy_idx.

Step 2: Bind the column to the Function

Positional arguments name the input columns. A name => literal argument sets one of the Function’s initialization values. version selects the Function version. If you omit it, the latest published version is used and stays fixed for the column. Each statement returns one row, such as Function column 'summary' declared on table 'documents'. The statement keeps the stored values, the indexes and the column order. It does not run the Function or rewrite data files. If the column was declared non-nullable, it becomes nullable. By running the statement, you declare that this Function version computed the existing non-NULL values from the current inputs. LanceDB does not check this. Automatic refresh is enabled by default. Set auto_refresh_enabled = false so that Function calls start only when you run a refresh. The statement binds one top-level column and needs at least one input column. It is refused, and the table stays unchanged, for:
  • a column whose type does not match the Function’s output type
  • a column that is already computed, or still carries a Geneva UDF declaration
  • a primary key column
  • a column that another Function binding reads or writes
  • a Function whose result is expanded into several columns
  • a materialized view
  • a table that has the Realtime Engine enabled
Writes that started before the statement are not blocked. One of them can still overwrite the column after it is bound. Resume writes only after the statement returns and your clients have reopened the table.

Step 3: Refresh the column

A refresh without a filter fills the rows whose value is NULL. It leaves the other rows alone while their inputs are unchanged. If Geneva filled every row, the refresh assigns no rows. Add a filter to keep rows out of the refresh, such as rows with empty input. A filtered refresh recomputes every matching row, including rows that already have a value. Add AND <column> IS NULL to the filter so that only unfilled rows are computed:
With error_policy="skip", rows that succeed are kept when other rows fail. See row errors. Rows you add later have no value in the column. Run the same refresh after each load, or turn on automatic refresh:
Automatic refresh runs without a filter, so it also computes rows that your filter kept out.

Behavior differences

  • NULL means not filled. A Function with a non-nullable output cannot return NULL. Use a refresh filter to leave rows unfilled. See Function signatures.
  • A NULL input defers the row. When the Function’s parameter is declared non-nullable, a row with a NULL input is not computed and its output stays NULL.
  • A bound column cannot be written directly. Its values come from refresh. Leave the column out of the rows you append.
  • A changed Function is a new version. A bound column stays on the version it was bound with.
  • Arguments are fixed at binding. To change a literal or an initialization value, drop the column and add it again with the new value. The new column starts empty.
  • Overwriting the table is refused while it has Function columns. Append rows or use merge_insert.
  • Refresh filters accept less SQL than queries. Comparisons, IS NULL, AND, IN, LIKE and built-in functions such as lower work. The TRIM(...) syntax is rejected, so use btrim(...). Registered Functions and non-deterministic functions such as now() are also rejected.
  • A retry_policy changes how a failed call is handled. A whole call that still fails after its retries is not split up to find the failing row. See retrying temporary Function errors.

Validation

  1. Run the procedure on a copy of the table first.
  2. After step 2, print the schema and the filled counts again. The counts match the ones you recorded, no column is marked as a Geneva column, and table.list_indices() lists each index.
  3. After step 3, check that rows_failed is 0 and that table.function_errors(column="embedding") has no records.
  4. Run SHOW COLUMN STATUS ON documents to see the Function, the version and the row counts of each bound column. The statement returns an error while it cannot account for every unfilled row. That is the case right after step 2 if the column has NULL rows. See checking column status.
  5. Compare a sample of newly computed rows with rows the UDF computed. For an embedding, check the dimension and run the same search against both.
  6. Run one load of new rows end to end before you turn the Geneva job off.

Related guidance