Package com.illumon.iris.db.tables.utils
Class TableManagementTools
java.lang.Object
com.illumon.iris.db.tables.utils.TableManagementTools
public class TableManagementTools extends Object
Tools for managing and manipulating tables on disk.
Most users will need
TableTools
and not TableManagementTools
.-
Field Summary
Fields Modifier and Type Field Description static String
INDEX_COL_NAME
static String
KEY_COL_NAME
-
Method Summary
Modifier and Type Method Description static TableDefinition
addColumns(TableDefinition currentDefinition, File rootDir, int levels, String... columnsToAdd)
Adds new columns to a table definition and persists the result in path.static TableDefinition
addColumns(TableDefinition currentDefinition, File path, String... columnsToAdd)
Adds new columns to a table definition and persists the result in path.static void
addGroupingMetadata(File tableDirectory)
Add grouping metadata to a table on disk.static void
addGroupingMetadata(File tableDirectory, TableDefinition tableDefinition)
Add grouping metadata to a table on disk.static void
appendToTable(Table tableToAppend, String destDir)
Appends to an existing table on disk, or writes a new table if the target table does not exist.static void
appendToTables(TableDefinition definitionToAppend, Table[] tablesToAppend, String[] destinationDirectoryNames)
Appends to existing tables on disk, or writes a new table if the target table does not exist.static void
deleteTable(File path)
Deletes a table on disk.static TableDefinition
dropColumns(TableDefinition currentDefinition, File rootDir, int levels, String... columnsToRemove)
Removes columns from a table definition and persists the result in path, potentially updating multiple persisted tables.static TableDefinition
dropColumns(TableDefinition currentDefinition, File path, String... columnsToRemove)
Removes columns from a table definition and persists the result in path, potentially updating multiple persisted tables.static void
flushColumnData()
Flush all previously written column data to disk.static List<File>
getAllDbDirs(String tableName, File rootDir, int levelsDepth)
Gets all sub-table directories.static Table
readGroupingTable(File tablePath, com.illumon.dataobjects.ColumnDefinition<?>... keyColDef)
Read a grouping table written bywriteGroupingTable(ColumnDefinition, File, Map)
.static Table
readGroupingTable(File tablePath, String... columnNames)
Read a grouping table written bywriteGroupingTable(ColumnDefinition, File, Table)
.static Table
readTable(File path)
Reads in a table from disk.static Table
readTable(File path, TableDefinition tableDefinition)
Reads in a table from disk.static TableDefinition
renameColumns(TableDefinition currentDefinition, File rootDir, int levels, String... columnsToRename)
Renames columns in a table definition and persists the result in path, potentially updating multiple persisted tables.static TableDefinition
renameColumns(TableDefinition currentDefinition, File path, MatchPair... columnsToRename)
Renames columns in a table definition and persists the result in path, potentially updating multiple persisted tables.static TableDefinition
renameColumns(TableDefinition currentDefinition, File path, String... columnsToRename)
Renames columns in a table definition and persists the result in path, potentially updating multiple persisted tables.static TableDefinition
updateColumns(TableDefinition currentDefinition, File rootDir, int levels, String... updates)
Updates columns in a table definition and persists the result in path, potentially updating multiple persisted tables.static void
writeDataIndexTable(File destinationDir, Table indexTable, String indexColumnName, String... keyColumnNames)
Write out the Data Index table for the specified columns.static void
writeDeephavenTables(Table[] sources, TableDefinition tableDefinition, File[] destinations)
Write out tables to disk in the Deephaven format.static void
writeGroupingTable(com.illumon.dataobjects.ColumnDefinition<?> groupingColDef, File destinationDir, Table grouping)
Write out the Grouping table for the specified column.static void
writeGroupingTable(com.illumon.dataobjects.ColumnDefinition groupingColDef, File destinationDir, Map<?,ReadOnlyIndex> grouping)
Write out the Grouping table for the specified column.static void
writeParquetTables(Table[] sources, TableDefinition tableDefinition, org.apache.parquet.hadoop.metadata.CompressionCodecName codecName, File[] destinations, String[] groupingColumns)
Writes tables to disk in parquet format under a given destinations.static void
writeTable(Table sourceTable, TableDefinition definition, File destDir, Database.StorageFormat storageFormat)
Write out a table to disk.static void
writeTable(Table sourceTable, File destDir)
Write out a table to disk.static void
writeTable(Table sourceTable, File destDir, Database.StorageFormat storageFormat)
Write out a table to disk.static void
writeTable(Table sourceTable, String destDir)
Write out a table to disk.static void
writeTable(Table sourceTable, String destDir, Database.StorageFormat storageFormat)
Write out a table to disk.static void
writeTables(Table[] sources, TableDefinition tableDefinition, File[] destinations)
Write out tables to disk.static void
writeTables(Table[] sources, TableDefinition tableDefinition, File[] destinations, Database.StorageFormat storageFormat)
Write out tables to disk.
-
Field Details
-
INDEX_COL_NAME
- See Also:
- Constant Field Values
-
KEY_COL_NAME
- See Also:
- Constant Field Values
-
-
Method Details
-
readTable
Reads in a table from disk.- Parameters:
path
- table locationtableDefinition
- table definition- Returns:
- table
-
readTable
Reads in a table from disk.- Parameters:
path
- table location- Returns:
- table
-
writeTable
Write out a table to disk.- Parameters:
sourceTable
- source tabledestDir
- destination
-
writeTable
public static void writeTable(@NotNull Table sourceTable, @NotNull String destDir, @NotNull Database.StorageFormat storageFormat)Write out a table to disk.- Parameters:
sourceTable
- source tabledestDir
- destinationstorageFormat
- Format used for storage
-
writeTable
public static void writeTable(@NotNull Table sourceTable, @NotNull TableDefinition definition, @NotNull File destDir, @NotNull Database.StorageFormat storageFormat)Write out a table to disk.- Parameters:
sourceTable
- source tabledefinition
- table definition. Will be written to disk as given.destDir
- destinationstorageFormat
- Format used for storage
-
writeTable
Write out a table to disk.- Parameters:
sourceTable
- source tabledestDir
- destination
-
writeTable
public static void writeTable(@NotNull Table sourceTable, @NotNull File destDir, @NotNull Database.StorageFormat storageFormat)Write out a table to disk.- Parameters:
sourceTable
- source tabledestDir
- destinationstorageFormat
- Format used for storage
-
writeParquetTables
public static void writeParquetTables(@NotNull Table[] sources, @NotNull TableDefinition tableDefinition, @Nullable org.apache.parquet.hadoop.metadata.CompressionCodecName codecName, @NotNull File[] destinations, @NotNull String[] groupingColumns)Writes tables to disk in parquet format under a given destinations. If you specify grouping columns, there must already be grouping information for those columns in the sources. This can be accomplished with.by(<grouping columns>).ungroup()
or.sort(<grouping column>)
.- Parameters:
sources
- The tables to writetableDefinition
- The common schema for all the tables to writecodecName
- Compression codec to use. The only supported codecs areCompressionCodecName.SNAPPY
andCompressionCodecName.UNCOMPRESSED
.destinations
- The destination paths. If the parquet extension is missing, the default parquet file name is used (table.parquet)groupingColumns
- List of columns the tables are grouped by (the write operation will store the grouping info)
-
writeTables
public static void writeTables(@NotNull Table[] sources, @NotNull TableDefinition tableDefinition, @NotNull File[] destinations)Write out tables to disk.- Parameters:
sources
- source tablestableDefinition
- table definitiondestinations
- destinations
-
writeTables
public static void writeTables(@NotNull Table[] sources, @NotNull TableDefinition tableDefinition, @NotNull File[] destinations, @Nullable Database.StorageFormat storageFormat)Write out tables to disk.- Parameters:
sources
- source tablestableDefinition
- table definitiondestinations
- destinationsstorageFormat
- Format used for storage
-
writeDeephavenTables
public static void writeDeephavenTables(@NotNull Table[] sources, @NotNull TableDefinition tableDefinition, @NotNull File[] destinations)Write out tables to disk in the Deephaven format. All tables are assumed to share the given TableDefinition, which will be written to all locations as passed in.- Parameters:
sources
- source tablestableDefinition
- table definitiondestinations
- destinations
-
addGroupingMetadata
Add grouping metadata to a table on disk.- Parameters:
tableDirectory
- table directory
-
addGroupingMetadata
public static void addGroupingMetadata(@NotNull File tableDirectory, @NotNull TableDefinition tableDefinition)Add grouping metadata to a table on disk.- Parameters:
tableDirectory
- table directorytableDefinition
- table definition
-
deleteTable
Deletes a table on disk.- Parameters:
path
- path to delete
-
appendToTable
Appends to an existing table on disk, or writes a new table if the target table does not exist.- Parameters:
tableToAppend
- table to appenddestDir
- destination
-
appendToTables
public static void appendToTables(@NotNull TableDefinition definitionToAppend, @NotNull Table[] tablesToAppend, @NotNull String[] destinationDirectoryNames)Appends to existing tables on disk, or writes a new table if the target table does not exist.- Parameters:
definitionToAppend
- table definitiontablesToAppend
- tables to appenddestinationDirectoryNames
- destination directories
-
flushColumnData
public static void flushColumnData()Flush all previously written column data to disk. -
getAllDbDirs
public static List<File> getAllDbDirs(@NotNull String tableName, @NotNull File rootDir, int levelsDepth)Gets all sub-table directories.- Parameters:
tableName
- table namerootDir
- root directory where tables are foundlevelsDepth
- levels below rootDir where table directories are found- Returns:
- all sub-table directories for tableName
-
dropColumns
public static TableDefinition dropColumns(@NotNull TableDefinition currentDefinition, @NotNull File rootDir, int levels, String... columnsToRemove)Removes columns from a table definition and persists the result in path, potentially updating multiple persisted tables.- Parameters:
currentDefinition
- initial table definition.rootDir
- root directory where tables are found.levels
- levels below rootDir where table directories are found.columnsToRemove
- columns to remove.- Returns:
- new table definition if successful; otherwise null.
-
dropColumns
public static TableDefinition dropColumns(@NotNull TableDefinition currentDefinition, @NotNull File path, String... columnsToRemove)Removes columns from a table definition and persists the result in path, potentially updating multiple persisted tables.- Parameters:
currentDefinition
- initial table definition.path
- path of the table receiving the definition.columnsToRemove
- columns to remove.- Returns:
- new table definition.
-
renameColumns
public static TableDefinition renameColumns(@NotNull TableDefinition currentDefinition, @NotNull File rootDir, int levels, String... columnsToRename) throws IOExceptionRenames columns in a table definition and persists the result in path, potentially updating multiple persisted tables.- Parameters:
currentDefinition
- initial table definition.rootDir
- root directory where tables are found.levels
- levels below rootDir where table directories are found.columnsToRename
- columns to rename.- Returns:
- new table definition.
- Throws:
IOException
-
renameColumns
public static TableDefinition renameColumns(@NotNull TableDefinition currentDefinition, @NotNull File path, String... columnsToRename) throws IOExceptionRenames columns in a table definition and persists the result in path, potentially updating multiple persisted tables.- Parameters:
currentDefinition
- initial table definition.path
- path of the table receiving the definition.columnsToRename
- columns to rename.- Returns:
- new table definition.
- Throws:
IOException
-
renameColumns
public static TableDefinition renameColumns(@NotNull TableDefinition currentDefinition, @NotNull File path, MatchPair... columnsToRename) throws IOExceptionRenames columns in a table definition and persists the result in path, potentially updating multiple persisted tables.- Parameters:
currentDefinition
- initial table definition.path
- path of the table receiving the definition.columnsToRename
- columns to rename.- Returns:
- new table definition.
- Throws:
IOException
-
updateColumns
public static TableDefinition updateColumns(@NotNull TableDefinition currentDefinition, @NotNull File rootDir, int levels, String... updates) throws IOExceptionUpdates columns in a table definition and persists the result in path, potentially updating multiple persisted tables.- Parameters:
currentDefinition
- initial table definition.rootDir
- root directory where tables are found.levels
- levels below rootDir where table directories are found.updates
- columns to update.- Returns:
- new table definition.
- Throws:
IOException
-
addColumns
public static TableDefinition addColumns(@NotNull TableDefinition currentDefinition, @NotNull File rootDir, int levels, String... columnsToAdd) throws IOExceptionAdds new columns to a table definition and persists the result in path. If there is an exception, the current definition is persisted.- Parameters:
currentDefinition
- initial table definition.rootDir
- root directory where tables are found.levels
- levels below rootDir where table directories are found.columnsToAdd
- columns to add.- Returns:
- new table definition.
- Throws:
IOException
-
addColumns
public static TableDefinition addColumns(@Nullable TableDefinition currentDefinition, @NotNull File path, String... columnsToAdd) throws IOExceptionAdds new columns to a table definition and persists the result in path. If there is an exception, the current definition is persisted.- Parameters:
currentDefinition
- initial table definition. If null, the definition from the table loaded from path is used.path
- path of the table containing the columns to add.columnsToAdd
- columns to add.- Returns:
- new table definition if successful; otherwise null.
- Throws:
IOException
-
writeGroupingTable
public static void writeGroupingTable(@NotNull com.illumon.dataobjects.ColumnDefinition groupingColDef, @NotNull File destinationDir, @NotNull Map<?,ReadOnlyIndex> grouping)Write out the Grouping table for the specified column. This will place the grouping information in a table adjacent to the data table in a directory titled "Index-<Column name>".- Parameters:
groupingColDef
- the grouping column definitiondestinationDir
- the destination for the source tablegrouping
- the grouping of values
-
writeGroupingTable
public static void writeGroupingTable(@NotNull com.illumon.dataobjects.ColumnDefinition<?> groupingColDef, @NotNull File destinationDir, @NotNull Table grouping)Write out the Grouping table for the specified column. This will place the grouping information in a table adjacent to the data table in a directory titled "Index-<Column name>".- Parameters:
groupingColDef
- the grouping column definitiondestinationDir
- the destination for the source tablegrouping
- the grouping of values
-
readGroupingTable
@Nullable public static Table readGroupingTable(@NotNull File tablePath, @NotNull com.illumon.dataobjects.ColumnDefinition<?>... keyColDef)Read a grouping table written bywriteGroupingTable(ColumnDefinition, File, Map)
.- Parameters:
tablePath
- the path to the source tablekeyColDef
- the list ofColumnDefinition
s of the grouping columns- Returns:
- a
Table
containing the groupings or null if it does not exist
-
readGroupingTable
@Nullable public static Table readGroupingTable(@NotNull File tablePath, @NotNull String... columnNames)Read a grouping table written bywriteGroupingTable(ColumnDefinition, File, Table)
.- Parameters:
tablePath
- the path to the source tablecolumnNames
- the column to locate grouping for- Returns:
- a
Table
containing the groupings or null if it does not exist
-
writeDataIndexTable
public static void writeDataIndexTable(@NotNull File destinationDir, @NotNull Table indexTable, @NotNull String indexColumnName, @NotNull String... keyColumnNames)Write out the Data Index table for the specified columns. This will place the Data Index in a table adjacent to the data table in a directory titled "Index-<Column names>".- Parameters:
destinationDir
- the destination for the source tableindexTable
- the table containing the indexindexColumnName
- the name of the Index columnkeyColumnNames
- the ordered names of key columns
-