|
6 | 6 |
|
7 | 7 | / Schemas returned by .compress.getSplayStats, .compress.getPartitionStats and .compress.splay |
8 | 8 | .compress.cfg.schemas:(`symbol$())!(); |
9 | | -.compress.cfg.schemas[`infoSplay]: flip `column`compressedLength`uncompressedLength`algorithm`logicalBlockSize`zipLevel!"SJJIII"$\:(); |
10 | | -.compress.cfg.schemas[`infoPartition]: flip `part`table`column`compressedLength`uncompressedLength`algorithm`logicalBlockSize`zipLevel!"*SSJJIII"$\:(); |
11 | | -.compress.cfg.schemas[`compSplay]: flip `col`source`target`compressed`inplace`empty`writeMode!"SSSBBBS"$\:(); |
| 9 | +.compress.cfg.schemas[`infoSplay]: flip `column`compressedLength`uncompressedLength`compressMode`algorithm`logicalBlockSize`zipLevel!"SJJSIII"$\:(); |
| 10 | +.compress.cfg.schemas[`infoPartition]: flip `part`table`column`compressedLength`uncompressedLength`compressMode`algorithm`logicalBlockSize`zipLevel!"*SSJJSIII"$\:(); |
| 11 | +.compress.cfg.schemas[`compSplay]: flip `column`source`target`compressed`inplace`empty`writeMode!"SSSBBBS"$\:(); |
| 12 | +.compress.cfg.schemas[`compPartition]: flip `part`table`column`source`target`compressed`inplace`empty`writeMode!"*SSSSBBBS"$\:(); |
12 | 13 |
|
13 | 14 | / Splay and partition compression option defaults provide the following behaviour |
14 | 15 | / - recompress (0b): Any compressed files will be copied |
|
30 | 31 | .compress.init:{}; |
31 | 32 |
|
32 | 33 |
|
33 | | -/ NOTE: Columns that are uncompressed will have null values for all information in the returned table |
| 34 | +/ NOTE: Columns that are uncompressed will have a null 'compressed' value |
34 | 35 | / @param splayPath (FolderPath) A folder path of a splayed table |
35 | 36 | / @returns (Table) The compressed stats (via -21!) of each column within the specified splay path |
36 | 37 | / @throws InvalidSplayPathException If the specified splay path does not exist, or does not contain a splayed table |
37 | 38 | / @see .compress.cfg.schemas |
38 | 39 | .compress.getSplayStats:{[splayPath] |
39 | | - / Needs a trailing slash for .Q.qp (in .type.isSplayedTable) to work correctly |
40 | | - if[not "/" = last string splayPath; |
41 | | - splayPath:` sv splayPath,`; |
42 | | - ]; |
43 | | - |
44 | 40 | if[not[.type.isFolder splayPath] | not .type.isSplayedTable splayPath; |
45 | 41 | '"InvalidSplayPathException"; |
46 | 42 | ]; |
47 | 43 |
|
48 | 44 | splayCols:cols splayPath; |
49 | 45 |
|
50 | 46 | compressStats:-21!/:` sv/: splayPath,/:splayCols; |
| 47 | + compressStats:(`algorithm`logicalBlockSize`zipLevel!0 0 0i) ^/: compressStats; |
51 | 48 |
|
52 | | - statsTbl:.compress.cfg.schemas[`infoSplay] upsert/ compressStats; |
| 49 | + statsTbl:.compress.cfg.schemas[`infoSplay] upsert compressStats; |
53 | 50 | statsTbl:update column:splayCols from statsTbl; |
| 51 | + statsTbl:update uncompressedLength:hcount each (` sv/: splayPath,/: column) from statsTbl where null uncompressedLength; |
| 52 | + statsTbl:update compressMode:key[.compress.defaults] algorithm from statsTbl; |
54 | 53 | :statsTbl; |
55 | 54 | }; |
56 | 55 |
|
57 | | -/ NOTE: Columns that are uncompressed will have null values for all information in the returned table |
58 | | -/ @param hdbRoot (FolderPath) The root folder containing a partitioned HDB |
| 56 | +/ NOTE: Columns that are uncompressed will have a null 'compressed' value |
| 57 | +/ @param hdbRoot (FolderPath) The root folder containing a partitioned HDB or the HDB segment if a segmented HDB |
59 | 58 | / @param partVal (Date|Month|Year|Long) The specific partition within the HDB to retrieve compression stats for |
60 | 59 | / @returns (Table) The compression stats (via -21!) of each column within each table within the specified HDB partition |
61 | 60 | / @throws InvalidHdbRootException If the specified HDB root folder does not exist |
|
83 | 82 | / Based on the specified parameters, the functions behaviour (returned in the 'writeMode' column) for each column will be: |
84 | 83 | / - 'compress': The file is uncompressed, or is compressed and the 'recompress' option is true |
85 | 84 | / - 'copy': The file is either empty (0 = count) or is already compressed and the 'recompress' option is missing or false |
86 | | -/ - 'ignore': The would've been copied (as above) but inplace |
| 85 | +/ - 'ignore': The file would've been copied (as above) but inplace so nothing to do |
87 | 86 | / @param sourceSplayPath (FolderPath) The source splay |
88 | 87 | / @param targetSplayPath (FolderPath) The target splay. This can be the same as 'sourceSplayPath' ONLY if the 'inplace' option is set to true |
89 | 88 | / @param compressType (Symbol|IntegerList) The compression type. If a symbol, the compression settings will be taken from '.compress.defaults' |
|
99 | 98 | .compress.splay:{[sourceSplayPath; targetSplayPath; compressType; options] |
100 | 99 | options:.compress.cfg.compressDefaults ^ options; |
101 | 100 |
|
102 | | - / Needs a trailing slash for .Q.qp (in .type.isSplayedTable) to work correctly |
103 | | - if[not .type.isSplayedTable ` sv sourceSplayPath,`; |
| 101 | + if[not .type.isSplayedTable sourceSplayPath; |
104 | 102 | '"InvalidSourceSplayPathException"; |
105 | 103 | ]; |
106 | 104 |
|
|
129 | 127 | ]; |
130 | 128 |
|
131 | 129 |
|
132 | | - compressCfg:.compress.cfg.schemas[`compSplay] upsert flip enlist[`col]!enlist cols sourceSplayPath; |
133 | | - compressCfg:update source:(` sv/: sourceSplayPath,/: col), target:(` sv/: targetSplayPath,/: col) from compressCfg; |
| 130 | + compressCfg:.compress.cfg.schemas[`compSplay] upsert flip enlist[`column]!enlist cols sourceSplayPath; |
| 131 | + compressCfg:update source:(` sv/: sourceSplayPath,/: column), target:(` sv/: targetSplayPath,/: column) from compressCfg; |
134 | 132 | compressCfg:update compressed:.file.isCompressed each source from compressCfg; |
135 | 133 | compressCfg:update empty:0 = count first .Q.V sourceSplayPath from compressCfg; |
136 | | - compressCfg:update inplace:source=target from compressCfg; |
| 134 | + compressCfg:update inplace:source = target from compressCfg; |
137 | 135 |
|
138 | 136 | compressCfg:update writeMode:`compress`copy compressed from compressCfg; |
139 | 137 | compressCfg:update writeMode:`ignore from compressCfg where inplace, writeMode = `copy; |
|
146 | 144 |
|
147 | 145 |
|
148 | 146 | .log.if.info ("Starting splay table compression [ Source: {} ] [ Target: {} ] [ Compression: {} ]"; sourceSplayPath; targetSplayPath; compressType); |
| 147 | + .log.if.trace "Compression configuration:\n",.Q.s compressCfg; |
| 148 | + |
149 | 149 | st:.time.now[]; |
150 | 150 |
|
151 | 151 | .file.ensureDir targetSplayPath; |
|
176 | 176 | / @param sourceRoot (FolderPath) The path of the source HDB |
177 | 177 | / @param targetRoot (FolderPath) The path of the target HDB |
178 | 178 | / @param partVal (Date|Month|Year|Long) The specific partition within the HDB to compress |
179 | | -/ @param tbls (SymbolList) The list of tables in the partition to compress |
| 179 | +/ @param tbls (Symbol|SymbolList) The list of tables in the partition to compress. If `COMP_ALL` is specified, all tables in the partition will be compressed |
180 | 180 | / @param compressType (Symbol|IntegerList) See '.compress.splay' |
181 | 181 | / @param options (Dict) See '.compress.splay', 'srcParTxt' / 'tgtParTxt' - set to false to ignore 'par.txt' in source or target HDBs respectively |
182 | 182 | / @throws SourceHdbPartitionDoesNotExistException If the specified source HDB does not exist |
|
201 | 201 | '"SourceHdbPartitionDoesNotExistException"; |
202 | 202 | ]; |
203 | 203 |
|
| 204 | + srcTables:.file.ls srcPartPath; |
204 | 205 |
|
205 | | - srcTables:tbls inter .file.ls srcPartPath; |
| 206 | + if[.type.isSymbolList tbls; |
| 207 | + srcTables:tbls inter srcTables; |
| 208 | + ]; |
206 | 209 |
|
207 | 210 | srcTblPaths:` sv/: srcPartPath,/:srcTables; |
208 | 211 | tgtTblPaths:` sv/: tgtPartPath,/:srcTables; |
|
211 | 214 | st:.time.now[]; |
212 | 215 |
|
213 | 216 | compressCfg:.compress.splay[;; compressType; options]'[srcTblPaths; tgtTblPaths]; |
| 217 | + compressCfg:(flip each enlist[`table]!/:enlist each (count each compressCfg)#'srcTables),''compressCfg; |
| 218 | + compressCfg:.compress.cfg.schemas[`compPartition] upsert raze compressCfg; |
| 219 | + compressCfg:update part:partVal from compressCfg; |
214 | 220 |
|
215 | 221 | .log.if.info ("HDB partition compression complete [ Source HDB: {} ] [ Target HDB: {} ] [ Partition: {} ] [ Tables: {} ] [ Compression Type: {} ] [ Time Taken: {} ]"; sourceRoot; targetRoot; partVal; srcTables; compressType; .time.now[] - st); |
216 | 222 |
|
|
0 commit comments