Created
May 11, 2020 20:57
-
-
Save baranovxyz/3903ba87fb4f378802f9e972d6070e36 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function compress(column) { | |
column.compression = 'DICTIONARY'; | |
const dictionary = []; | |
const indexes = {}; | |
column.values = column.values.map(value => { | |
if (value === null) return null; | |
// add string to dictionary if there is no such string yet | |
if (indexes[value] === undefined) { | |
indexes[value] = dictionary.length; | |
dictionary.push(value); | |
} | |
// return value index | |
return indexes[value]; | |
}); | |
return Object.assign(column, { dictionary }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment