Skip to content

Commit 39bba41

Browse files
committed
fix clickhouse join issue
1 parent aafc595 commit 39bba41

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

lib/dialect/clickhouse.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,37 @@ Clickhouse.prototype.visitArrayCall = function(arrayCall) {
231231
return [txt];
232232
};
233233

234-
Clickhouse.prototype.visitJoin = function(join) {
234+
Clickhouse.prototype.visitFrom = function(from) {
235235
var result = [];
236+
if (from.skipFromStatement) {
237+
result.push(',');
238+
} else {
239+
result.push('FROM');
240+
}
241+
for(var i = 0; i < from.nodes.length; i++) {
242+
// Currently clickhouse only support single table, but anyway
243+
result = result.concat(this.visit(from.nodes[i], {"parentIsFrom": true}));
244+
}
245+
return result;
246+
};
247+
248+
Clickhouse.prototype.visitJoin = function(join, config) {
249+
var result = [];
250+
var parentIsFrom = config && config.parentIsFrom;
236251
this._visitingJoin = true;
237-
result = result.concat(this.visit(join.from));
252+
if (parentIsFrom) {
253+
result = result.concat('(');
254+
}
255+
256+
result = result.concat(this.visit(join.from, {"joinFromQuery": true}));
238257
result = result.concat('ALL ' + join.subType + ' JOIN');
239258
result = result.concat(this.visit(join.to));
240259
result = result.concat('USING');
241260
result = result.concat(this.visit(join.on));
261+
if (parentIsFrom) {
262+
result = result.concat(')');
263+
}
264+
242265
return result;
243266
};
244267

lib/dialect/postgres.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Postgres.prototype.visit = function(node, config) {
156156
case 'TABLE' : return this.visitTable(node);
157157
case 'COLUMN' : return this.visitColumn(node);
158158
case 'FOREIGN KEY' : return this.visitForeignKey(node);
159-
case 'JOIN' : return this.visitJoin(node);
159+
case 'JOIN' : return this.visitJoin(node, config);
160160
case 'LITERAL' : return this.visitLiteral(node);
161161
case 'TEXT' : return node.text;
162162
case 'PARAMETER' : return this.visitParameter(node);
@@ -1028,7 +1028,7 @@ Postgres.prototype.visitForShare = function() {
10281028
Postgres.prototype.visitJoin = function(join) {
10291029
var result = [];
10301030
this._visitingJoin = true;
1031-
result = result.concat(this.visit(join.from, {"joinFromQuery": true}));
1031+
result = result.concat(this.visit(join.from));
10321032
result = result.concat(join.subType + ' JOIN');
10331033
result = result.concat(this.visit(join.to));
10341034
result = result.concat('ON');

0 commit comments

Comments
 (0)