Skip to main content
Version: v3.0.0

Create a schema

A schema is usually extracted from a data source. The schema represents the features of the feature set, and is the first thing you need in order to register a feature set.

Three helpers are available on the Schema class:

  • create_from creates a schema instance from a string formatted schema
  • create_derived_from creates a derived schema instance from a string formatted schema and parent feature set along with transformation — see Create a derived schema
  • to_string serialises a schema instance to string format — see Save and load schemas

Create a schema from a data source

A schema can also be created from a data source. To see all supported data sources, see Supported data sources.

workspace = client.workspaces.list(name="my_workspace")[0]
schema = workspace.extract_schema_from_source(source)
schema = workspace.extract_schema_from_source(source, credentials)
note

An optional parameter, credentials , can be specified. If specified, these credentials are used instead of environmental variables. The optional profile_id and spark_size parameters select an ingest profile and a Spark size preset; when spark_size is left blank, the workspace default is used.

Extraction runs as a job inside a workspace — see Where the extraction job runs below for why you should call it on the workspace rather than on the client.

An asynchronous variant is also available — see Asynchronous schema extraction.

Create a schema from a feature set

workspace = client.workspaces.list(name="my_workspace")[0]
feature_set = workspace.feature_sets.get_by_name("example")
schema = Schema.create_from(feature_set)

Create a schema from a string

A schema can be created from a string format:

from h2o_featurestore import Schema
schema = "col1 string, col2 string, col3 integer"
schema = Schema.create_from(schema)

Where the extraction job runs

Schema extraction runs as a job inside a workspace, so call it on the workspace you intend to register the feature set in: workspace.extract_schema_from_source(...).

The same method also exists on the client (client.extract_schema_from_source(...)), but it scopes the job to your default workspace. That means the job does not appear in the target workspace's job list, Spark size presets resolve against the default workspace instead of the target one, and the call fails if you are not allowed to create feature sets in the default workspace — so prefer the workspace-scoped form.

warning

Spark size presets are resolved per workspace. If you pass a spark_size that is only available in the target workspace, the client-level call does not quietly fall back to a default — it fails because the preset cannot be found in your default workspace.

from h2o_featurestore import CSVFile

source = CSVFile("s3://my-bucket/data.csv")

# Waits for the job to complete and returns a Schema
schema = workspace.extract_schema_from_source(source)

# Returns a Job immediately; call wait_for_result() when you need the Schema
job = workspace.extract_schema_from_source_async(source)
schema = job.wait_for_result()

Parameters

ParameterTypeRequiredDescription
sourcedata sourceYesThe data source to extract the schema from. See Supported data sources.
credentialscredentials objectNoCredentials for the data source. If omitted, they are read from environment variables. See Credentials configuration.
profile_idstrNoId of an ingest profile to use.
spark_sizestrNoSpark size preset name. When left blank, the workspace default is used.

Feedback