Interface WritableDatabase
- All Known Implementing Classes:
DatabaseImpl
The WritableDatabase writes to User tables, this interface does not apply to System tables.
There are two types of historical User tables:
- Unpartitioned: unpartitioned tables have a single location with data.
- Partitioned: partitioned tables have one or more locations with data, that can be added and removed independently. Each partitioned User table must have exactly one partitioning column (e.g., Date) which separates the data by partition.
Historical User tables may be read and written from any Deephaven query worker, but users are responsible for ensuring that tables are not concurrently written.
Live User tables are always partitioned and are centrally managed by Deephaven system processes. Live tables provide an eventually consistent view of the data, even when multiple workers write to them.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
addPartitionedTableSchema
(@NotNull String namespace, @NotNull String tableName, @NotNull String partitionColumnName, @NotNull TableDefinition prototype) Adds a schema for a partitioned user table.void
addTablePartition
(@NotNull String namespace, @NotNull String tableName, @NotNull String partitionColumnValue, @NotNull Table table) Adds a single column partition of data to a partitioned user table.void
addUnpartitionedTable
(@NotNull String namespace, @NotNull String tableName, @NotNull Table table) Adds an unpartitioned user table.void
appendLiveTable
(@NotNull String namespace, @NotNull String tableName, @NotNull String partitionColumnValue, @NotNull Table table) Appends all rows from a given table to a live user table partition.appendLiveTableIncremental
(@NotNull String namespace, @NotNull String tableName, @NotNull String partitionColumnValue, @NotNull Table table) Appends all rows from a given table to a live user table partition.boolean
deleteLiveTablePartition
(@NotNull String namespace, @NotNull String tableName, @NotNull String partitionColumnValue) Delete a partition from a live user table.boolean
deletePartitionedTable
(@NotNull String namespace, @NotNull String tableName) Delete all partitions, whether direct or live, and the schema, from a partitioned user table.boolean
deleteTablePartition
(@NotNull String namespace, @NotNull String tableName, @NotNull String partitionColumnValue) Deletes a single column partition of data from a partitioned user table.boolean
deleteUnpartitionedTable
(@NotNull String namespace, @NotNull String tableName) Deletes an unpartitioned user table and the schema.boolean
updatePartitionedTableSchema
(@NotNull String namespace, @NotNull String tableName, @NotNull TableDefinition prototype) Updates a preexisting User table schema.
-
Method Details
-
addUnpartitionedTable
void addUnpartitionedTable(@NotNull @NotNull String namespace, @NotNull @NotNull String tableName, @NotNull @NotNull Table table) Adds an unpartitioned user table.
Writes an unpartitioned user table to disk. If the namespace does not exist, then it is created. The schema must not already exist.
If a
UserTableIOException
is thrown, the state of the table is undefined.- Parameters:
namespace
- table namespacetableName
- table nametable
- table that the definition and data will be based on- Throws:
UserTablePreexistingSchemaException
- when a table definition already exists for the given namespace and table nameUserTablePermissionException
- when the caller doesn't have full access to the specified namespace and table nameUserTableNamespaceException
- when a system namespace is specifiedUserTableWriteException
- when there's a failure in data writingUserTableColumnDefinitionException
- when a partitioning column is defined
-
deleteUnpartitionedTable
boolean deleteUnpartitionedTable(@NotNull @NotNull String namespace, @NotNull @NotNull String tableName) Deletes an unpartitioned user table and the schema.If the schema does not exist, then data is not deleted. If there is no data but the schema exists, then the schema is deleted.
The namespace is not removed even if this is the last table in the namespace.
If a
UserTableIOException
is thrown, the state of the table is undefined.- Parameters:
namespace
- table namespacetableName
- table name- Returns:
- true if the data was deleted, false if there was no data or preexisting schema
- Throws:
UserTablePermissionException
- when the caller doesn't have full access to the specified namespace and table nameUserTableNamespaceException
- when a system namespace is specifiedUserTableStorageTypeException
- when the schema is not an unpartitioned tableUserTableDeleteException
- when there's a failure in data deletion
-
addPartitionedTableSchema
boolean addPartitionedTableSchema(@NotNull @NotNull String namespace, @NotNull @NotNull String tableName, @NotNull @NotNull String partitionColumnName, @NotNull @NotNull TableDefinition prototype) Adds a schema for a partitioned user table.The schema is derived from the prototype
TableDefinition
and the partitionColumnName parameter. The prototype definition must not include a partitioning column.If the namespace does not exist, then it is created.
If the schema already exists and it is identical (this is a stricter check than compatibility; all columns must be present in the same order with the same properties), then the method returns false. If the schema already exists and is not identical, then an error is thrown.
- Parameters:
namespace
- table namespacetableName
- table namepartitionColumnName
- name of the partitioning columnprototype
- table definition to derive schema from- Returns:
- true if the partitioned table definition was added, false if it already existed
- Throws:
UserTableColumnDefinitionException
- when the prototype contains a column with the same name as partitionColumnNameUserTablePermissionException
- when the caller doesn't have full access to the specified namespace and table nameUserTablePreexistingSchemaException
- when a schema already exists and is not identicalUserTableNamespaceException
- when a system namespace is specified
-
updatePartitionedTableSchema
boolean updatePartitionedTableSchema(@NotNull @NotNull String namespace, @NotNull @NotNull String tableName, @NotNull @NotNull TableDefinition prototype) Updates a preexisting User table schema.If the schema does not exist an error is thrown. Not all schema modifications are permitted. The partitioning column may not be changed. Existing columns may not have their type changed. Columns may be added or deleted.
Note that no data is modified by this operation. Removed columns remain on persistent storage, and added columns are treated as null on read.
Although each modification in isolation is verified for safety, a sequence of modifications to the schema may be unsafe. For example, deleting a column and adding it back with a new type results in unreadable data.
- Parameters:
namespace
- table namespacetableName
- table nameprototype
- table definition to derive schema from- Returns:
- true if the partitioned table definition was updated, false if there was already an identical definition
- Throws:
UserTablePermissionException
- when the caller doesn't have full access to the specified namespace and table nameUserTableMissingSchemaException
- when there is no table to updateUserTableStorageTypeException
- when the schema is not a partitioned tableUserTableColumnDefinitionException
- when the target user table doesn't have exactly one partitioning column, the prototype contains a column with the same name as the partitioning column, or a column's type is attempted to be updatedUserTableNamespaceException
- when a system namespace is specified
-
addTablePartition
void addTablePartition(@NotNull @NotNull String namespace, @NotNull @NotNull String tableName, @NotNull @NotNull String partitionColumnValue, @NotNull @NotNull Table table) Adds a single column partition of data to a partitioned user table.The data table must have a
mutually compatible definition
with the current schema. The data table must not have a column with the same name as the partitioning column.If a
UserTableIOException
is thrown, the state of the table is undefined.- Parameters:
namespace
- table namespacetableName
- table namepartitionColumnValue
- value for the partitioning column, e.g. "2015-09-25" for "Date"table
- table to write data from- Throws:
UserTablePermissionException
- when the caller doesn't have full access to the specified namespace and table nameUserTableMissingSchemaException
- when a table definition is absent for the given namespace and table nameUserTableNamespaceException
- when a system namespace is specifiedUserTableStorageTypeException
- when the schema is not a partitioned tableUserTableColumnDefinitionException
- when the target user table doesn't have exactly one partitioning column or the data contains a column with the same name as the partitioning columnTableDefinition.IncompatibleTableDefinitionException
- when the table input definition isn't mutually compatibleUserTableWriteException
- when there's a failure in data writing
-
deleteTablePartition
boolean deleteTablePartition(@NotNull @NotNull String namespace, @NotNull @NotNull String tableName, @NotNull @NotNull String partitionColumnValue) Deletes a single column partition of data from a partitioned user table.If a
UserTableIOException
is thrown, the state of the table is undefined.- Parameters:
namespace
- table namespacetableName
- table namepartitionColumnValue
- value for the partitioning column, e.g. "2015-09-25" for "Date"- Returns:
- true if the partition was deleted, false if there was no partition or preexisting schema
- Throws:
UserTablePermissionException
- when the caller doesn't have full access to the specified namespace and table nameUserTableNamespaceException
- when a system namespace is specifiedUserTableStorageTypeException
- when the schema is not a partitioned tableUserTableDeleteException
- when there's a failure in data deletion
-
appendLiveTable
void appendLiveTable(@NotNull @NotNull String namespace, @NotNull @NotNull String tableName, @NotNull @NotNull String partitionColumnValue, @NotNull @NotNull Table table) Appends all rows from a given table to a live user table partition.The data table must have a
mutually compatible definition
with the current schema. The data table must not have a column with the same name as the partitioning column.The specified column partition may already exist, or may be created by the system.
This method is asynchronous. After returning, the data may not be immediately available. It is possible for the write to fail after this method has returned. When multiple workers append to a partition, ordering is imposed outside the worker by other system components.
If a
UserTableIOException
is thrown, the state of the table is undefined.- Parameters:
namespace
- table namespacetableName
- table namepartitionColumnValue
- value for the partitioning column, e.g. "2015-09-25" for "Date"table
- table to append rows from- Throws:
UserTablePermissionException
- when the caller doesn't have full access to the specified namespace and table nameUserTableMissingSchemaException
- when a table schema is absent for the given namespace and table nameUserTableNamespaceException
- when a system namespace is specifiedUserTableStorageTypeException
- when the schema is not a partitioned tableUserTableColumnDefinitionException
- when the target user table doesn't have exactly one partitioning column or the table contains a column with the same name as the partitioning columnTableDefinition.IncompatibleTableDefinitionException
- when the table input definition isn't mutually compatibleUserTableWriteException
- when there's a failure in appending data
-
appendLiveTableIncremental
SafeCloseable appendLiveTableIncremental(@NotNull @NotNull String namespace, @NotNull @NotNull String tableName, @NotNull @NotNull String partitionColumnValue, @NotNull @NotNull Table table) Appends all rows from a given table to a live user table partition. When rows are added to the table, they are additionally appended to the table.The input table updates can only have additions and shifts. No modifications or removals are permitted.
The data table must have a
mutually compatible definition
with the current schema. The data table must not have a column with the same name as the partitioning column.The specified column partition may already exist, or may be created by the system.
This method is asynchronous, after returning the data may not be immediately available. It is possible for the write to fail after this method has returned. When multiple workers append to a partition, ordering is imposed outside the worker by other system components.
A reference must be maintained to the returned
SafeCloseable
to ensure expected functionality; callingSafeCloseable.close()
will stop incremental appends, and clean up related resources.If a
UserTableIOException
is thrown, the state of the table is undefined.- Parameters:
namespace
- table namespacetableName
- table namepartitionColumnValue
- value for the partitioning column, e.g. "2015-09-25" for "Date"table
- table to append updates from- Returns:
- the
Closeable
reference used to ensure and stop expected functionality - Throws:
UserTablePermissionException
- when the caller doesn't have full access to the specified namespace and table nameUserTableMissingSchemaException
- when a table definition is absent for the given namespace and table nameUserTableNamespaceException
- when a system namespace is specifiedUserTableStorageTypeException
- when the schema is not a partitioned tableUserTableColumnDefinitionException
- when the target schema does not have exactly one partitioning column or the table contains a column with the same name as the partitioning columnTableDefinition.IncompatibleTableDefinitionException
- when the table input definition isn't mutually compatibleUserTableWriteException
- when there's a failure in appending data
-
deleteLiveTablePartition
boolean deleteLiveTablePartition(@NotNull @NotNull String namespace, @NotNull @NotNull String tableName, @NotNull @NotNull String partitionColumnValue) Delete a partition from a live user table.If a
UserTableIOException
is thrown, the state of the table is undefined.- Parameters:
namespace
- table namespacetableName
- table namepartitionColumnValue
- value for the partitioning column, e.g. "2015-09-25" for "Date"- Returns:
- true if the partition was deleted, false if there was no partition or preexisting schema
- Throws:
UserTablePermissionException
- when the caller doesn't have full access to the specified namespace and table nameUserTableNamespaceException
- when a system namespace is specifiedUserTableStorageTypeException
- when the schema is not a partitioned tableUserTableColumnDefinitionException
- when the target user table doesn't have exactly one partitioning columnUserTableDeleteException
- when there's a failure deleting data
-
deletePartitionedTable
boolean deletePartitionedTable(@NotNull @NotNull String namespace, @NotNull @NotNull String tableName) Delete all partitions, whether direct or live, and the schema, from a partitioned user table.All partitions from the table are deleted sequentially. If a partition cannot be deleted, then the operation fails but some data may have already been removed. After all partitions are deleted, then the schema is deleted. If the schema does not exist, then data is not deleted. If there is no data, but the schema exists, then the schema is deleted.
The namespace is not removed, even if this is the last table in the namespace.
If a
UserTableIOException
is thrown, the state of the table is undefined.- Parameters:
namespace
- table namespacetableName
- table name- Returns:
- true if data was deleted, false if there was no data or preexisting schema
- Throws:
UserTablePermissionException
- when the caller doesn't have full access to the specified namespace and table nameUserTableNamespaceException
- when a system namespace is specifiedUserTableStorageTypeException
- when the schema is not a partitioned tableUserTableColumnDefinitionException
- when the target user table doesn't have exactly one partitioning columnUserTableDeleteException
- when there's a failure deleting data
-