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 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
Flush all previously written column data to disk.getAllDbDirs
(String tableName, File rootDir, int levelsDepth) Gets all sub-table directories.static File
getDataIndexFile
(File destinationDir, String... columnNames) Get the directory path for the data index for the specified columns.static Table
readDataIndexTable
(File tablePath, String... columnNames) Read a grouping table written bywriteDataIndexTable(File, Table, String, String...)
(ColumnDefinition, File, Table)}.static Table
Reads in a table from disk.static Table
readTable
(File path, Database.StorageFormat formatHint, SourceTableInstructions sourceTableInstructions) Read a table from disk with the specified format.static Table
readTable
(File path, TableDefinition tableDefinition) Reads in a table from disk.static Table
readTable
(File path, TableDefinition tableDefinition, SourceTableInstructions instructions) 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
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:
-
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 theTableDataException
could not be loaded
-
readTable
public static Table readTable(@NotNull File path, @NotNull Database.StorageFormat formatHint, @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 theTableDataException
could not be loaded
-
readTable
Reads in a table from disk.- Parameters:
path
- table locationtableDefinition
- table definition- Returns:
- table
-
readTable
public static Table readTable(@NotNull File path, @NotNull TableDefinition tableDefinition, @NotNull SourceTableInstructions instructions) Reads in a table from disk.- Parameters:
path
- table locationtableDefinition
- table definitioninstructions
-SourceTableInstructions
for column and region creation- 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 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.- Returns:
- new table definition.
- Throws:
IOException
-
renameColumns
public static TableDefinition renameColumns(@NotNull TableDefinition currentDefinition, @NotNull File path, 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.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 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.- Returns:
- new table definition.
- Throws:
IOException
-
updateColumns
public static TableDefinition updateColumns(@NotNull TableDefinition currentDefinition, @NotNull File rootDir, int levels, 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
public static TableDefinition addColumns(@NotNull TableDefinition currentDefinition, @NotNull File rootDir, int levels, 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:
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 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:
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
-
readDataIndexTable
@Nullable public static Table readDataIndexTable(@NotNull File tablePath, @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
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
-
getDataIndexFile
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.
-