Package com.illumon.iris.db.tables.utils
Class TableManagementTools
java.lang.Object
com.illumon.iris.db.tables.utils.TableManagementTools
Tools for managing and manipulating tables on disk.
Most users will need
TableTools and not TableManagementTools.-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable TableDefinitionaddColumns(@NotNull TableDefinition currentDefinition, @NotNull File rootDir, int levels, @NotNull String... columnsToAdd) Adds new columns to a table.static @Nullable TableDefinitionaddColumns(@Nullable TableDefinition initialDefinition, @NotNull File path, @NotNull String... columnsToAdd) Adds new columns to a table definition and persists the result in path.static voidaddGroupingMetadata(@NotNull File tableDirectory) Add grouping metadata to a table on disk.static voidaddGroupingMetadata(@NotNull File tableDirectory, @NotNull TableDefinition tableDefinition) Add grouping metadata to a table on disk.static voidappendToTable(@NotNull TableDefinition definitionToAppend, @NotNull Table tableToAppend, @NotNull String destDir) Appends to an existing table on disk, or writes a new table if the target table does not exist.static voidappendToTable(@NotNull Table tableToAppend, @NotNull String destDir) Appends to an existing table on disk, or writes a new table if the target table does not exist.static voidappendToTables(@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.static voiddeleteTable(@NotNull File path) Deletes a table on disk.static TableDefinitiondropColumns(@NotNull TableDefinition currentDefinition, @NotNull File rootDir, int levels, @NotNull String... columnsToRemove) Removes columns from a table definition and persists the result in path, potentially updating multiple persisted tables.static TableDefinitiondropColumns(@NotNull TableDefinition currentDefinition, @NotNull File path, @NotNull String... columnsToRemove) Removes columns from a table definition and persists the result in path, potentially updating multiple persisted tables.static voidFlush all previously written column data to disk.getAllDbDirs(@NotNull String tableName, @NotNull File rootDir, int levelsDepth) Gets all directories named 'tableName', 'levelsDepth' levels below 'rootDir'.static longgetColumnFileSize(@NotNull ColumnFileTypeDetails columnTypeDetails, @NotNull String columnName, @NotNull File file, @NotNull File tableLocation, int columnVersion) Get the data size of the file for the given column.static FilegetDataIndexFile(@NotNull File destinationDir, @NotNull String... columnNames) Get the directory path for the data index for the specified columns.static FileprepareDestination(@NotNull File destination) Delete the destination directory if it exists, then make the destination directory and any missing parent directories, returning the first created for later rollback.static @Nullable TablereadDataIndexTable(@NotNull File tablePath, @NotNull String... columnNames) Read a grouping table written bywriteDataIndexTable(File, Table, String, String...)(ColumnDefinition, File, Table)}.static @NotNull com.illumon.iris.db.tables.utils.TableManagementTools.MutableCheckpointRecordreadMutableCheckpointRecord(@NotNull File tableLocation, @Nullable TableDefinition optionalTableDefinition) Read the entire supplied checkpoint record file into a newly-allocated checkpoint record.static TableReads in a table from disk.static TablereadTable(@NotNull File path, @NotNull Database.StorageFormat formatHint, @NotNull SourceTableInstructions sourceTableInstructions) Read a table from disk with the specified format.static TablereadTable(@NotNull File path, @NotNull TableDefinition tableDefinition) Reads in a table from disk.static TablereadTable(@NotNull File path, @NotNull TableDefinition tableDefinition, @NotNull SourceTableInstructions instructions) Reads in a table from disk.static TableDefinitionrenameColumns(@NotNull TableDefinition currentDefinition, @NotNull File rootDir, int levels, @NotNull String... columnsToRename) Renames columns in a table definition and persists the result in path, potentially updating multiple persisted tables.static TableDefinitionrenameColumns(@NotNull TableDefinition currentDefinition, @NotNull File path, @NotNull MatchPair... columnsToRename) Renames columns in a table definition and persists the result in path, potentially updating multiple persisted tables.static TableDefinitionrenameColumns(@NotNull TableDefinition currentDefinition, @NotNull File path, @NotNull String... columnsToRename) Renames columns in a table definition and persists the result in path.static TableDefinitionupdateColumns(@NotNull TableDefinition currentDefinition, @NotNull File rootDir, int levels, @NotNull String... updates) Updates columns in a table definition and persists the result in path, potentially updating multiple persisted tables.static voidwriteDataIndexTable(@NotNull File destinationDir, @NotNull Table indexTable, @NotNull String indexColumnName, @NotNull String... keyColumnNames) Write out the Data Index table for the specified columns.static voidwriteDeephavenTables(@NotNull Table[] sources, @NotNull TableDefinition tableDefinition, @NotNull File[] destinations) Write out tables to disk in the Deephaven format.static voidwriteParquetTables(@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.static voidwriteTable(@NotNull Table sourceTable, @NotNull TableDefinition definition, @NotNull File destDir, @NotNull Database.StorageFormat storageFormat) Write out a table to disk.static voidwriteTable(@NotNull Table sourceTable, @NotNull File destDir) Write out a table to disk.static voidwriteTable(@NotNull Table sourceTable, @NotNull File destDir, @NotNull Database.StorageFormat storageFormat) Write out a table to disk.static voidwriteTable(@NotNull Table sourceTable, @NotNull String destDir) Write out a table to disk.static voidwriteTable(@NotNull Table sourceTable, @NotNull String destDir, @NotNull Database.StorageFormat storageFormat) Write out a table to disk.static voidwriteTables(@NotNull Table[] sources, @NotNull TableDefinition tableDefinition, @NotNull File[] destinations) Write out tables to disk.static voidwriteTables(@NotNull Table[] sources, @NotNull TableDefinition tableDefinition, @NotNull File[] destinations, @Nullable Database.StorageFormat storageFormat) Write out tables to disk.
-
Field Details
-
INDEX_COL_NAME
- See Also:
-
OLD_GROUP_KEY_COL
- See Also:
-
-
Method Details
-
readTable
Reads in a table from disk. This method will attempt to determine the table type. If the type is known ahead of time, it is more efficient to invoke eitherreadTable(File, StorageFormat, SourceTableInstructions)orreadTable(File, TableDefinition)- Parameters:
path- the path to the table on disk.- Returns:
- the table read at the location.
- Throws:
TableDataException- if the table is Deephaven format and theTableDataExceptioncould not be loaded
-
readTable
public static Table readTable(@NotNull @NotNull File path, @NotNull @NotNull Database.StorageFormat formatHint, @NotNull @NotNull SourceTableInstructions sourceTableInstructions) throws TableDataException Read a table from disk with the specified format.- Parameters:
path- the path to the tableformatHint- the expected format on disk- Returns:
- the table read from disk.
- Throws:
TableDataException- if theTableDataExceptioncould not be loaded
-
readTable
public static Table readTable(@NotNull @NotNull File path, @NotNull @NotNull TableDefinition tableDefinition) Reads in a table from disk.- Parameters:
path- table locationtableDefinition- table definition- Returns:
- table
-
readTable
public static Table readTable(@NotNull @NotNull File path, @NotNull @NotNull TableDefinition tableDefinition, @NotNull @NotNull SourceTableInstructions instructions) Reads in a table from disk.- Parameters:
path- table locationtableDefinition- table definitioninstructions-SourceTableInstructionsfor column and region creation- Returns:
- table
-
writeTable
public static void writeTable(@NotNull @NotNull Table sourceTable, @NotNull @NotNull String destDir) Write out a table to disk.- Parameters:
sourceTable- source tabledestDir- destination
-
writeTable
public static void writeTable(@NotNull @NotNull Table sourceTable, @NotNull @NotNull String destDir, @NotNull @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 @NotNull Table sourceTable, @NotNull @NotNull TableDefinition definition, @NotNull @NotNull File destDir, @NotNull @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 @NotNull Table sourceTable, @NotNull @NotNull File destDir, @NotNull @NotNull Database.StorageFormat storageFormat) Write out a table to disk.- Parameters:
sourceTable- source tabledestDir- destinationstorageFormat- Format used for storage
-
prepareDestination
Delete the destination directory if it exists, then make the destination directory and any missing parent directories, returning the first created for later rollback.- Parameters:
destination- The destination directory- Returns:
- The first created directory
-
writeParquetTables
public static void writeParquetTables(@NotNull @NotNull Table[] sources, @NotNull @NotNull TableDefinition tableDefinition, @Nullable @Nullable org.apache.parquet.hadoop.metadata.CompressionCodecName codecName, @NotNull @NotNull File[] destinations, @NotNull @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.SNAPPYandCompressionCodecName.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 @NotNull Table[] sources, @NotNull @NotNull TableDefinition tableDefinition, @NotNull @NotNull File[] destinations) Write out tables to disk.- Parameters:
sources- source tablestableDefinition- table definitiondestinations- destinations
-
writeTables
public static void writeTables(@NotNull @NotNull Table[] sources, @NotNull @NotNull TableDefinition tableDefinition, @NotNull @NotNull File[] destinations, @Nullable @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 @NotNull Table[] sources, @NotNull @NotNull TableDefinition tableDefinition, @NotNull @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 @NotNull File tableDirectory, @NotNull @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
public static void appendToTable(@NotNull @NotNull Table tableToAppend, @NotNull @NotNull String destDir) 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
-
appendToTable
public static void appendToTable(@NotNull @NotNull TableDefinition definitionToAppend, @NotNull @NotNull Table tableToAppend, @NotNull @NotNull String destDir) Appends to an existing table on disk, or writes a new table if the target table does not exist.- Parameters:
definitionToAppend- table definitiontableToAppend- table to appenddestDir- destination
-
appendToTables
public static void appendToTables(@NotNull @NotNull TableDefinition definitionToAppend, @NotNull @NotNull Table[] tablesToAppend, @NotNull @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 @NotNull String tableName, @NotNull @NotNull File rootDir, int levelsDepth) Gets all directories named 'tableName', 'levelsDepth' levels below 'rootDir'.- 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 @NotNull TableDefinition currentDefinition, @NotNull @NotNull File rootDir, int levels, @NotNull @NotNull 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 @NotNull TableDefinition currentDefinition, @NotNull @NotNull File path, @NotNull @NotNull 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 @NotNull TableDefinition currentDefinition, @NotNull @NotNull File rootDir, int levels, @NotNull @NotNull String... columnsToRename) throws IOException Renames 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, as "toName=fromName".- Returns:
- new table definition.
- Throws:
IOException
-
renameColumns
public static TableDefinition renameColumns(@NotNull @NotNull TableDefinition currentDefinition, @NotNull @NotNull File path, @NotNull @NotNull String... columnsToRename) throws IOException Renames columns in a table definition and persists the result in path.- Parameters:
currentDefinition- initial table definition.path- path of the table receiving the definition.columnsToRename- columns to rename, as "toName=fromName".- Returns:
- new table definition.
- Throws:
IOException
-
renameColumns
public static TableDefinition renameColumns(@NotNull @NotNull TableDefinition currentDefinition, @NotNull @NotNull File path, @NotNull @NotNull MatchPair... columnsToRename) throws IOException Renames 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, as "toName=fromName".- Returns:
- new table definition.
- Throws:
IOException
-
updateColumns
public static TableDefinition updateColumns(@NotNull @NotNull TableDefinition currentDefinition, @NotNull @NotNull File rootDir, int levels, @NotNull @NotNull String... updates) throws IOException Updates 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
@Nullable public static @Nullable TableDefinition addColumns(@NotNull @NotNull TableDefinition currentDefinition, @NotNull @NotNull File rootDir, int levels, @NotNull @NotNull String... columnsToAdd) throws IOException Adds new columns to a table.
Finds all table locationslevelslevels belowrootDirthe table named bycurrentDefinition, and delegates toaddColumns(TableDefinition, File, String...). If any of the resulting definitions differ, the process stops and anIllegalStateExceptionis thrown.- 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 as "name=value"- Returns:
- new table definition if all delegated addColumns were successful; otherwise null.
- Throws:
com.fishlib.base.verify.AssertionFailure- if any of the resulting definitions differ, or if other preconditions are not metIOException- if there is an error reading or writing the table files
-
addColumns
@Nullable public static @Nullable TableDefinition addColumns(@Nullable @Nullable TableDefinition initialDefinition, @NotNull @NotNull File path, @NotNull @NotNull String... columnsToAdd) throws IOException Adds new columns to a table definition and persists the result in path. If there is an exception, the current definition is persisted.- Parameters:
initialDefinition- 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:
IllegalStateException- if any of the resulting definitions differ, or if other preconditions are not metIOException- if there is an error reading or writing the table files
-
readDataIndexTable
@Nullable public static @Nullable Table readDataIndexTable(@NotNull @NotNull File tablePath, @NotNull @NotNull String... columnNames) Read a grouping table written bywriteDataIndexTable(File, Table, String, String...)(ColumnDefinition, File, Table)}.- Parameters:
tablePath- the path to the source tablecolumnNames- the column to locate grouping for- Returns:
- a
Tablecontaining the groupings or null if it does not exist
-
writeDataIndexTable
public static void writeDataIndexTable(@NotNull @NotNull File destinationDir, @NotNull @NotNull Table indexTable, @NotNull @NotNull String indexColumnName, @NotNull @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
-
getDataIndexFile
public static File getDataIndexFile(@NotNull @NotNull File destinationDir, @NotNull @NotNull String... columnNames) Get the directory path for the data index for the specified columns. The column names will always be sorted first.- Parameters:
destinationDir- the base pathcolumnNames- the columns indexed- Returns:
- the directory where the specified data index should go.
-
getColumnFileSize
public static long getColumnFileSize(@NotNull @NotNull ColumnFileTypeDetails columnTypeDetails, @NotNull @NotNull String columnName, @NotNull @NotNull File file, @NotNull @NotNull File tableLocation, int columnVersion) Get the data size of the file for the given column.- Parameters:
columnTypeDetails- the column type detailscolumnName- the name of the columnfile- the data file. This is expected to exist.tableLocation- the location of table and data filescolumnVersion- the version of the column files- Returns:
- the data size of the column file (not including header), or 0 if the file does not exist
-
readMutableCheckpointRecord
@NotNull public static @NotNull com.illumon.iris.db.tables.utils.TableManagementTools.MutableCheckpointRecord readMutableCheckpointRecord(@NotNull @NotNull File tableLocation, @Nullable @Nullable TableDefinition optionalTableDefinition) Read the entire supplied checkpoint record file into a newly-allocated checkpoint record.- Parameters:
tableLocation- the directory containing the checkpoint fileoptionalTableDefinition- optional table definition. Will be read from the tableLocation if null.- Returns:
- a newly-allocated and populated checkpoint record
- Throws:
TableDataException- if the checkpoint file does not exist
-