Manage Catalogs, Databases, and Tables¶
Prepare a catalog and database by name within a workspace, create a table, and read its rows. Completing this returns a table resource on which subsequent reads, previews, truncations, or deletions are executed.
Task workflow¶
The caller provides workspace, catalog name, database name, table name, and column definitions.
The SDK searches for matching catalogs and databases in the workspace, creating them if not found.
The SDK creates the table inside that database and returns the corresponding table resource.
Use the returned table resource to read table data.
Prerequisites¶
Required item |
Role on this page |
|---|---|
Authenticated client and selected workspace |
Determine the scope of this resource operation. |
Catalog, database, and table names |
Select or create target resource locations. |
Column definitions |
Construct table schema. |
Creation permissions |
Allow provisioning non-existent resources in the target location. |
This page does not create clients or select workspaces. Complete the initial connection in Quickstart first, then pass the bound workspace to the following example.
Create a table¶
The following function prepares a catalog and database in an existing workspace, then creates a table. Preparing by name is not a read-only lookup: missing resources will trigger creation operations.
import moi_product_sdk as sdk
def create_orders_table(workspace):
catalog = workspace.prepare_catalog("analytics")
database = catalog.prepare_database("sales")
table, _ = database.create_table_from_columns(
"orders",
[
sdk.TableColumn("order_id", "INT"),
sdk.TableColumn("customer_name", "VARCHAR"),
],
)
return table
import (
"context"
sdk "github.com/matrixorigin/matrixflow/sdk/go-sdk"
)
func createOrdersTable(ctx context.Context, workspace *sdk.WorkspaceHandle) (*sdk.TableHandle, error) {
catalog, err := workspace.PrepareCatalog(ctx, "analytics")
if err != nil {
return nil, err
}
database, err := catalog.PrepareDatabase(ctx, "sales")
if err != nil {
return nil, err
}
table, _, err := database.CreateTable(ctx, "orders", []sdk.TableColumn{
{Name: "order_id", Type: "INT"},
{Name: "customer_name", Type: "VARCHAR"},
})
if err != nil {
return nil, err
}
return table, nil
}
Read table data¶
The table resource returned by the creation function can be used directly to read data. The following code only reads currently returned rows; it does not guarantee that subsequent writes, imports, or queries have completed.
rows = table.data()
rows, err := table.Data(ctx)
if err != nil {
return err
}
_ = rows
Result confirmation¶
Retain the table resource returned by the creation function, or reacquire it using explicitly provided resource identifiers from creation, listing, or caller inputs. Read results confirm only this retrieval; imports, queries, and writes should be verified via their respective task statuses.
Limitations¶
Table names and column schemas must be provided by the caller; the SDK does not infer table structure from file names or display titles.
Dropping or truncating tables modifies data. Confirm the target workspace, catalog, database, and table before proceeding.