Legacy Schema Inference

Deephaven provides schema generation tools to facilitate schema creation. Schemas can only be inferred from Deephaven tables in Legacy. For other data sources, see the Core+ Schema Inference guide.

Tables

The SchemaService can infer a schema from the column names and types of a Deephaven table and deploy the schema to the system. The commands in this guide must be run in a Legacy Groovy console.

SchemaServiceFactory.getDefault() returns a SchemaService that supports write operations and System tables.

import com.illumon.iris.db.schema.SchemaServiceFactory

schemaService = SchemaServiceFactory.getDefault()

The namespace must be defined before deploying the schema using the SchemaService.

import com.illumon.iris.db.schema.NamespaceSet

schemaService.createNamespace(NamespaceSet.SYSTEM, "ExampleNamespace")

Note

This command will fail if the namespace is already defined as a user namespace. To change an existing namespace to a system namespace, you must delete all tables in the namespace and then delete the namespace itself. See the dhconfig documentation for instructions on deleting schemas.

Define a partitioning column, then create the schema from the table definition:

import com.illumon.iris.db.schema.NamespaceSet
import com.illumon.iris.db.tables.TableDefinition
import com.illumon.dataobjects.ColumnDefinition

partitioningColumn = new ColumnDefinition("Date", String.class, ColumnDefinition.COLUMNTYPE_PARTITIONING)
colDefs = new ArrayList(table.getDefinition().getColumnList())
colDefs.add(partitioningColumn)

schema = schemaService.fromDefinition(new TableDefinition(colDefs), namespace, tableName,
TableDefinition.STORAGETYPE_NESTEDPARTITIONEDONDISK, NamespaceSet.SYSTEM)

For information on TableDefinition.STORAGETYPE_NESTEDPARTITIONEDONDISK and the other storage types available, see Basic Table Attributes.

Finally, to deploy the schema:

schemaService.addSchema(schema)
Full query
import com.illumon.iris.db.schema.SchemaServiceFactory
import com.illumon.iris.db.schema.NamespaceSet
import com.illumon.iris.db.tables.TableDefinition
import com.illumon.dataobjects.ColumnDefinition

namespace = "ExampleNamespace"
tableName = "TableName"

table = newTable(stringCol("Letter", "A", "C", "F", "B", "E", "D", "A"),
        intCol("Number", NULL_INT, 2, 1, NULL_INT, 4, 5, 3),
        stringCol("Color", "red", "blue", "orange", "purple", "yellow", "pink", "blue"),
        intCol("Code", 12, 13, 11, NULL_INT, 16, 14, NULL_INT))

schemaService = SchemaServiceFactory.getDefault()

schemaService.createNamespace(NamespaceSet.SYSTEM, namespace)

partitioningColumn = new ColumnDefinition("Date", String.class, ColumnDefinition.COLUMNTYPE_PARTITIONING)
colDefs = new ArrayList(table.getDefinition().getColumnList())
colDefs.add(partitioningColumn)

schema = schemaService.fromDefinition(new TableDefinition(colDefs), namespace, tableName,
        TableDefinition.STORAGETYPE_NESTEDPARTITIONEDONDISK, NamespaceSet.SYSTEM)

schemaService.addSchema(schema)