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
| let doc = { type: 'string' }; | |
| console.log(BSON.serialize(doc)); | |
| // <Buffer 16 00 00 00 02 74 79 70 65 00 07 00 00 00 73 74 72 69 6e 67 00 00> |
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
| let doc = { _id: 1 }; | |
| console.log(BSON.serialize(doc)); | |
| // <Buffer 0e 00 00 00 10 5f 69 64 00 01 00 00 00 00> |
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
| const doc = {}; | |
| console.log(BSON.serialize(doc)); | |
| // <Buffer 05 00 00 00 00> |
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
| interface Column { | |
| _id: string; // MongoDB id field | |
| type: 'string'; // yes, it is literally 'string' | |
| values: (string | null)[]; // an array, each element is either string or null | |
| } |
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
| async function findOneMongoDB(query) { | |
| /* implemented somewhere */ | |
| } | |
| async function get(query) { | |
| let doc = await findOneMongoDB(query); | |
| // return doc at once if it is not splitted | |
| if (!doc._splitted) return doc; | |
| const { _id, type } = doc; |
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
| // use unique uuids | |
| const { v4: uuidv4 } = require('uuid'); | |
| // split will be done if values size exceed ~15Mb | |
| const SPLIT_SIZE = 15e6; | |
| async function insertOneMongoDB(_id, data) { | |
| /* implemented somewhere */ | |
| } |
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; |
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 = 'ZIP_JSON_STRINGIFY'; | |
| column.values = zip(JSON.stringify(column.values)); | |
| return column; | |
| } |
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
| interface ColumnOfStrings { | |
| _id: string; // MongoDB id field | |
| type: 'string'; // yes, it is literal 'string' for column of strings | |
| values: (string | null)[]; // an array, each element is either string or null | |
| } |
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
| const recursiveFn = trampoline(function _recursiveFn(n) { | |
| if (n < 0) return; | |
| return () => _recursiveFn(n - 1); | |
| }); | |
| recursiveFn(100000); | |
| console.log('No range error!'); |