rbql 0.26.0 → 0.27.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/package.json +1 -1
- package/rbql.js +27 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rbql",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.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.27.0';
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
function check_if_brackets_match(opening_bracket, closing_bracket) {
|
|
@@ -130,30 +130,30 @@ function column_info_from_text_span(text_span, string_literals) {
|
|
|
130
130
|
let subscript_str_match = /^([ab])\[___RBQL_STRING_LITERAL([0-9]+)___\]$/.exec(text_span);
|
|
131
131
|
let as_alias_match = /^(.*) (as|AS) +([a-zA-Z][a-zA-Z0-9_]*) *$/.exec(text_span);
|
|
132
132
|
if (as_alias_match !== null) {
|
|
133
|
-
return {table_name: null, column_index: null, column_name:
|
|
133
|
+
return {table_name: null, column_index: null, column_name: null, is_star: false, alias_name: as_alias_match[3]};
|
|
134
134
|
}
|
|
135
135
|
if (simple_var_match !== null) {
|
|
136
136
|
if (text_span == rbql_star_marker)
|
|
137
|
-
return {table_name: null, column_index: null, column_name: null, is_star: true,
|
|
137
|
+
return {table_name: null, column_index: null, column_name: null, is_star: true, alias_name: null};
|
|
138
138
|
if (text_span.startsWith('___RBQL_STRING_LITERAL'))
|
|
139
139
|
return null;
|
|
140
140
|
let match = /^([ab])([0-9]+)$/.exec(text_span);
|
|
141
141
|
if (match !== null) {
|
|
142
|
-
return {table_name: match[1], column_index: parseInt(match[2]) - 1, column_name: null, is_star: false,
|
|
142
|
+
return {table_name: match[1], column_index: parseInt(match[2]) - 1, column_name: null, is_star: false, alias_name: null};
|
|
143
143
|
}
|
|
144
144
|
// Some examples for this branch: NR, NF
|
|
145
|
-
return {table_name: null, column_index: null, column_name: text_span, is_star: false,
|
|
145
|
+
return {table_name: null, column_index: null, column_name: text_span, is_star: false, alias_name: null};
|
|
146
146
|
} else if (attribute_match !== null) {
|
|
147
147
|
let table_name = attribute_match[1];
|
|
148
148
|
let column_name = attribute_match[2];
|
|
149
149
|
if (column_name == rbql_star_marker) {
|
|
150
|
-
return {table_name: table_name, column_index: null, column_name: null, is_star: true,
|
|
150
|
+
return {table_name: table_name, column_index: null, column_name: null, is_star: true, alias_name: null};
|
|
151
151
|
}
|
|
152
|
-
return {table_name: null, column_index: null, column_name: column_name, is_star: false,
|
|
152
|
+
return {table_name: null, column_index: null, column_name: column_name, is_star: false, alias_name: null};
|
|
153
153
|
} else if (subscript_int_match != null) {
|
|
154
154
|
let table_name = subscript_int_match[1];
|
|
155
155
|
let column_index = parseInt(subscript_int_match[2]) - 1;
|
|
156
|
-
return {table_name: table_name, column_index: column_index, column_name: null, is_star: false,
|
|
156
|
+
return {table_name: table_name, column_index: column_index, column_name: null, is_star: false, alias_name: null};
|
|
157
157
|
} else if (subscript_str_match != null) {
|
|
158
158
|
let table_name = subscript_str_match[1];
|
|
159
159
|
let replaced_string_literal_id = subscript_str_match[2];
|
|
@@ -161,7 +161,7 @@ function column_info_from_text_span(text_span, string_literals) {
|
|
|
161
161
|
let quoted_column_name = string_literals[replaced_string_literal_id];
|
|
162
162
|
let unquoted_column_name = unquote_string(quoted_column_name);
|
|
163
163
|
if (unquoted_column_name !== null && unquoted_column_name !== undefined) {
|
|
164
|
-
return {table_name: null, column_index: null, column_name: unquoted_column_name, is_star: false,
|
|
164
|
+
return {table_name: null, column_index: null, column_name: unquoted_column_name, is_star: false, alias_name: null};
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
}
|
|
@@ -1259,8 +1259,8 @@ function generate_init_statements(query_text, variables_map, join_variables_map,
|
|
|
1259
1259
|
|
|
1260
1260
|
|
|
1261
1261
|
function replace_star_count(aggregate_expression) {
|
|
1262
|
-
var rgx = /(
|
|
1263
|
-
var result = aggregate_expression.replace(rgx, '
|
|
1262
|
+
var rgx = /(?:(?<=^)|(?<=,)) *COUNT\( *\* *\)/ig;
|
|
1263
|
+
var result = aggregate_expression.replace(rgx, ' COUNT(1)');
|
|
1264
1264
|
return str_strip(result);
|
|
1265
1265
|
}
|
|
1266
1266
|
|
|
@@ -1580,13 +1580,22 @@ function select_output_header(input_header, join_header, query_column_infos) {
|
|
|
1580
1580
|
if (input_header === null) {
|
|
1581
1581
|
assert(join_header === null);
|
|
1582
1582
|
}
|
|
1583
|
+
let query_has_star = false;
|
|
1584
|
+
let query_has_column_alias = false;
|
|
1585
|
+
for (let qci of query_column_infos) {
|
|
1586
|
+
query_has_star = query_has_star || (qci !== null && qci.is_star);
|
|
1587
|
+
query_has_column_alias = query_has_column_alias || (qci !== null && qci.alias_name !== null);
|
|
1588
|
+
}
|
|
1583
1589
|
if (input_header === null) {
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
throw new RbqlParsingError(`Specifying column alias "AS ${qci.column_name}" is not allowed if input table has no header`);
|
|
1587
|
-
}
|
|
1590
|
+
if (query_has_star && query_has_column_alias) {
|
|
1591
|
+
throw new RbqlParsingError('Using both * (star) and AS alias in the same query is not allowed for input tables without header');
|
|
1588
1592
|
}
|
|
1589
|
-
|
|
1593
|
+
if (!query_has_column_alias) {
|
|
1594
|
+
// Input table has no header and query has no aliases therefore the output table will be without header.
|
|
1595
|
+
return null;
|
|
1596
|
+
}
|
|
1597
|
+
input_header = [];
|
|
1598
|
+
join_header = [];
|
|
1590
1599
|
}
|
|
1591
1600
|
if (join_header === null) {
|
|
1592
1601
|
// This means there is no JOIN table.
|
|
@@ -1607,6 +1616,8 @@ function select_output_header(input_header, join_header, query_column_infos) {
|
|
|
1607
1616
|
}
|
|
1608
1617
|
} else if (qci.column_name !== null) {
|
|
1609
1618
|
output_header.push(qci.column_name);
|
|
1619
|
+
} else if (qci.alias_name !== null) {
|
|
1620
|
+
output_header.push(qci.alias_name);
|
|
1610
1621
|
} else if (qci.column_index !== null) {
|
|
1611
1622
|
if (qci.table_name == 'a' && qci.column_index < input_header.length) {
|
|
1612
1623
|
output_header.push(input_header[qci.column_index]);
|