rbql 0.29.0 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +0 -0
- package/DEV_README.md +0 -0
- package/README.md +0 -0
- package/cli_parser.js +0 -0
- package/csv_utils.js +17 -7
- package/index.js +0 -0
- package/package.json +1 -1
- package/rbql.js +1 -1
- package/rbql_csv.js +17 -17
package/.eslintrc.json
CHANGED
|
File without changes
|
package/DEV_README.md
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
File without changes
|
package/cli_parser.js
CHANGED
|
File without changes
|
package/csv_utils.js
CHANGED
|
@@ -106,14 +106,23 @@ function split_whitespace_separated_str(src, preserve_whitespaces=false) {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
|
|
109
|
+
function get_polymorphic_split_function(dlm, policy, preserve_quotes_and_whitespaces) {
|
|
110
|
+
// TODO consider moving this function to rbql_csv.js
|
|
111
|
+
if (policy === 'simple') {
|
|
112
|
+
return (src) => [src.split(dlm), false];
|
|
113
|
+
} else if (policy === 'whitespace') {
|
|
114
|
+
return (src) => [split_whitespace_separated_str(src, preserve_quotes_and_whitespaces), false];
|
|
115
|
+
} else if (policy === 'monocolumn') {
|
|
116
|
+
return (src) => [[src], false];
|
|
117
|
+
} else if (policy === 'quoted' || policy === 'quoted_rfc') {
|
|
118
|
+
return (src) => split_quoted_str(src, dlm, preserve_quotes_and_whitespaces);
|
|
119
|
+
} else {
|
|
120
|
+
throw new Error(`Unsupported splitting policy: ${policy}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
109
124
|
function smart_split(src, dlm, policy, preserve_quotes_and_whitespaces) {
|
|
110
|
-
|
|
111
|
-
return [src.split(dlm), false];
|
|
112
|
-
if (policy === 'whitespace')
|
|
113
|
-
return [split_whitespace_separated_str(src, preserve_quotes_and_whitespaces), false];
|
|
114
|
-
if (policy === 'monocolumn')
|
|
115
|
-
return [[src], false];
|
|
116
|
-
return split_quoted_str(src, dlm, preserve_quotes_and_whitespaces);
|
|
125
|
+
return get_polymorphic_split_function(dlm, policy, preserve_quotes_and_whitespaces)(src);
|
|
117
126
|
}
|
|
118
127
|
|
|
119
128
|
|
|
@@ -161,6 +170,7 @@ class MultilineRecordAggregator {
|
|
|
161
170
|
module.exports.split_quoted_str = split_quoted_str;
|
|
162
171
|
module.exports.split_whitespace_separated_str = split_whitespace_separated_str;
|
|
163
172
|
module.exports.smart_split = smart_split;
|
|
173
|
+
module.exports.get_polymorphic_split_function = get_polymorphic_split_function;
|
|
164
174
|
module.exports.quote_field = quote_field;
|
|
165
175
|
module.exports.rfc_quote_field = rfc_quote_field;
|
|
166
176
|
module.exports.unquote_field = unquote_field;
|
package/index.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rbql",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "Rainbow Query Language",
|
|
5
5
|
"keywords": ["CSV", "TSV", "spreadsheet", "SQL", "SQL-like", "transpiler", "CLI", "command-line", "library", "browser", "Node", "select", "update", "join"],
|
|
6
6
|
"scripts": {
|
package/rbql.js
CHANGED
|
@@ -70,7 +70,7 @@ var query_context = null; // Needs to be global for MIN(), MAX(), etc functions.
|
|
|
70
70
|
|
|
71
71
|
|
|
72
72
|
const wrong_aggregation_usage_error = 'Usage of RBQL aggregation functions inside JavaScript expressions is not allowed, see the docs';
|
|
73
|
-
const RBQL_VERSION = '0.
|
|
73
|
+
const RBQL_VERSION = '0.30.0';
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
function check_if_brackets_match(opening_bracket, closing_bracket) {
|
package/rbql_csv.js
CHANGED
|
@@ -14,9 +14,6 @@ class RbqlIOHandlingError extends Error {}
|
|
|
14
14
|
class AssertionError extends Error {}
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
// TODO performance improvement: replace smart_split() with polymorphic_split()
|
|
18
|
-
|
|
19
|
-
|
|
20
17
|
function assert(condition, message=null) {
|
|
21
18
|
if (!condition) {
|
|
22
19
|
if (!message) {
|
|
@@ -215,6 +212,8 @@ class CSVRecordIterator extends rbql.RBQLInputIterator {
|
|
|
215
212
|
this.produced_records_queue = new RecordQueue();
|
|
216
213
|
|
|
217
214
|
this.process_line_polymorphic = policy == 'quoted_rfc' ? this.process_partial_rfc_record_line : this.process_record_line_simple;
|
|
215
|
+
|
|
216
|
+
this.polymorphic_split = csv_utils.get_polymorphic_split_function(this.delim, this.policy, false);
|
|
218
217
|
}
|
|
219
218
|
|
|
220
219
|
|
|
@@ -353,7 +352,7 @@ class CSVRecordIterator extends rbql.RBQLInputIterator {
|
|
|
353
352
|
|
|
354
353
|
process_record_line(line) {
|
|
355
354
|
this.NR += 1;
|
|
356
|
-
var [record, warning] =
|
|
355
|
+
var [record, warning] = this.polymorphic_split(line);
|
|
357
356
|
if (this.trim_whitespaces) {
|
|
358
357
|
record = record.map((v) => v.trim());
|
|
359
358
|
}
|
|
@@ -664,33 +663,34 @@ class FileSystemCSVRegistry extends rbql.RBQLTableRegistry {
|
|
|
664
663
|
this.encoding = encoding;
|
|
665
664
|
this.has_header = has_header;
|
|
666
665
|
this.comment_prefix = comment_prefix;
|
|
667
|
-
this.stream = null;
|
|
668
|
-
this.record_iterator = null;
|
|
669
|
-
|
|
670
666
|
this.options = options;
|
|
671
|
-
this.
|
|
672
|
-
this.table_path = null;
|
|
667
|
+
this.active_join_files = [];
|
|
673
668
|
}
|
|
674
669
|
|
|
675
670
|
get_iterator_by_table_id(table_id) {
|
|
676
|
-
|
|
677
|
-
|
|
671
|
+
let stream = null;
|
|
672
|
+
let table_path = find_table_path(this.input_file_dir, table_id);
|
|
673
|
+
if (table_path === null) {
|
|
678
674
|
throw new RbqlIOHandlingError(`Unable to find join table "${table_id}"`);
|
|
679
675
|
}
|
|
676
|
+
let bulk_input_path = null;
|
|
680
677
|
if (this.options && this.options['bulk_read']) {
|
|
681
|
-
|
|
678
|
+
bulk_input_path = table_path;
|
|
682
679
|
} else {
|
|
683
|
-
|
|
680
|
+
stream = fs.createReadStream(table_path);
|
|
684
681
|
}
|
|
685
682
|
let trim_whitespaces = this.options && this.options['trim_whitespaces'] ? true : false;
|
|
686
683
|
let comment_regex = this.options && this.options.hasOwnProperty('comment_regex') ? this.options['comment_regex'] : null;
|
|
687
|
-
|
|
688
|
-
|
|
684
|
+
let record_iterator = new CSVRecordIterator(stream, bulk_input_path, this.encoding, this.delim, this.policy, this.has_header, this.comment_prefix, table_id, 'b', trim_whitespaces, comment_regex);
|
|
685
|
+
this.active_join_files.push({'table_path': table_path, 'input_stream': stream, 'record_iterator': record_iterator});
|
|
686
|
+
return record_iterator;
|
|
689
687
|
};
|
|
690
688
|
|
|
691
689
|
get_warnings(output_warnings) {
|
|
692
|
-
if (this.
|
|
693
|
-
|
|
690
|
+
if (this.has_header) {
|
|
691
|
+
for (let active_join_file of this.active_join_files) {
|
|
692
|
+
output_warnings.push(`The first record in JOIN file ${path.basename(active_join_file.table_path)} was also treated as header (and skipped)`);
|
|
693
|
+
}
|
|
694
694
|
}
|
|
695
695
|
}
|
|
696
696
|
}
|