|
|
@@ -39,6 +39,7 @@
|
|
|
assertLocations({
|
|
|
beforeCursor: 'SELECT * FROM testTable1 JOIN db1.table2; ',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 41 } },
|
|
|
{ type: 'asterisk', location: { first_line:1, last_line:1, first_column: 8, last_column: 9 }, tables: [{ identifierChain: [{ name: 'testTable1' }] }, { identifierChain: [{ name: 'db1' }, { name: 'table2' }] }] },
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 15, last_column: 25 }, identifierChain: [{ name: 'testTable1' }] },
|
|
|
{ type: 'database', location: { first_line: 1, last_line: 1, first_column: 31, last_column: 34}, identifierChain: [{ name: 'db1' }]},
|
|
|
@@ -52,6 +53,7 @@
|
|
|
dialect: 'impala',
|
|
|
beforeCursor: 'SELECT db.tbl.col FROM db.tbl; ',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 30 } },
|
|
|
{ type: 'database', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 10 }, identifierChain: [{ name: 'db' }]},
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 11, last_column: 14 }, identifierChain: [{ name: 'db' }, { name: 'tbl' }]},
|
|
|
{ type: 'column', location: { first_line: 1, last_line: 1, first_column: 15, last_column: 18 }, identifierChain: [{ name: 'db' }, { name: 'tbl' },{ name: 'col'}]},
|
|
|
@@ -65,6 +67,7 @@
|
|
|
assertLocations({
|
|
|
beforeCursor: 'SELECT t3.id, id FROM testTable1, db.testTable2, testTable3 t3;',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 63 } },
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 10 }, identifierChain: [{ name: 'testTable3' }] },
|
|
|
{ type:'column', location: { first_line: 1, last_line: 1, first_column: 11, last_column: 13 }, identifierChain: [{ name: 'testTable3' },{ name: 'id' }] },
|
|
|
{ type:'column', location: { first_line: 1, last_line: 1, first_column: 15, last_column: 17 }, identifierChain: [{ name: 'id' }], tables: [{ identifierChain: [{ name: 'testTable1' }]}, { identifierChain: [{ name: 'db' }, { name: 'testTable2' }]}, { identifierChain: [{ name: 'testTable3' }], alias: 't3'}] },
|
|
|
@@ -80,6 +83,7 @@
|
|
|
assertLocations({
|
|
|
beforeCursor: 'SELECT * FROM foo WHERE bar IN (1+1, 2+2);',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 42 } },
|
|
|
{ type: 'asterisk', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 }, tables: [{ identifierChain: [{ name: 'foo' }] }] },
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 15, last_column: 18 }, identifierChain: [{ name: 'foo' }]},
|
|
|
{ type: 'column', location: { first_line: 1, last_line: 1, first_column: 25, last_column: 28 }, identifierChain:[{ name: 'foo' }, { name: 'bar'}]}
|
|
|
@@ -91,6 +95,7 @@
|
|
|
assertLocations({
|
|
|
beforeCursor: 'SELECT * FROM foo WHERE bar IN (id+1-1, id+1-2);',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 48 } },
|
|
|
{ type: 'asterisk', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 }, tables: [{ identifierChain: [{ name: 'foo' }] }] },
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 15, last_column: 18 }, identifierChain: [{ name: 'foo' }]},
|
|
|
{ type: 'column', location: { first_line: 1, last_line: 1, first_column: 25, last_column: 28 }, identifierChain:[{ name: 'foo' }, { name: 'bar'}]},
|
|
|
@@ -120,6 +125,7 @@
|
|
|
'ORDER BY s08.salary-s07.salary DESC\r\n' +
|
|
|
'LIMIT 1000;',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 9, first_column: 1, last_column: 11 } },
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 11 }, identifierChain: [{ name: 'sample_07' }] },
|
|
|
{ type: 'column', location: { first_line: 1, last_line: 1, first_column: 12, last_column: 23 }, identifierChain: [{ name: 'sample_07' }, { name: 'description' }] },
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 25, last_column: 28 }, identifierChain: [{ name: 'sample_07' }] },
|
|
|
@@ -148,12 +154,11 @@
|
|
|
});
|
|
|
});
|
|
|
|
|
|
-
|
|
|
-
|
|
|
it('should report locations for "SELECT * FROM foo WHERE bar IN (id+1-1, id+1-2);|"', function() {
|
|
|
assertLocations({
|
|
|
beforeCursor: 'SELECT * FROM foo WHERE bar IN (id+1-1, id+1-2);',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 48 } },
|
|
|
{ type: 'asterisk', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 }, tables: [{ identifierChain: [{ name: 'foo' }] }] },
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 15, last_column: 18 }, identifierChain: [{ name: 'foo' }]},
|
|
|
{ type: 'column', location: { first_line: 1, last_line: 1, first_column: 25, last_column: 28 }, identifierChain:[{ name: 'foo' }, { name: 'bar'}]},
|
|
|
@@ -172,6 +177,7 @@
|
|
|
assertLocations({
|
|
|
beforeCursor: 'SELECT CASE cos(boo.a) > baa.boo \n\tWHEN baa.b THEN true \n\tWHEN boo.c THEN false \n\tWHEN baa.blue THEN boo.d \n\tELSE baa.e END \n\t FROM db1.foo boo, bar baa WHERE baa.bla IN (SELECT ble FROM bla);',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 6, first_column: 1, last_column: 67 } },
|
|
|
{ type: 'function', location: { first_line: 1, last_line: 1, first_column: 13, last_column: 15 }, function: 'cos'},
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 17, last_column: 20 }, identifierChain: [{ name: 'db1' },{ name: 'foo' }]},
|
|
|
{ type: 'column', location: { first_line: 1, last_line: 1, first_column: 21, last_column: 22 }, identifierChain: [{ name: 'db1' }, { name: 'foo' }, { name: 'a' }]},
|
|
|
@@ -202,6 +208,7 @@
|
|
|
assertLocations({
|
|
|
beforeCursor: 'SELECT tta.* FROM testTableA tta, testTableB; ',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 45 } },
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 11}, identifierChain: [{ name: 'testTableA' }]},
|
|
|
{ type: 'asterisk', location:{ first_line: 1, last_line: 1, first_column: 12, last_column: 13 }, tables: [{ alias: 'tta', identifierChain: [{ name: 'testTableA' }] }] },
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 19, last_column: 29}, identifierChain: [{ name: 'testTableA' }]},
|
|
|
@@ -214,6 +221,7 @@
|
|
|
assertLocations({
|
|
|
beforeCursor: 'SELECT COUNT(*) FROM testTable;',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 31 } },
|
|
|
{ type: 'function', location:{ first_line: 1, last_line: 1, first_column: 8, last_column: 12}, function: 'count'},
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 22, last_column: 31}, identifierChain: [{ name: 'testTable' }]}
|
|
|
]
|
|
|
@@ -226,6 +234,7 @@
|
|
|
dialect: 'hive',
|
|
|
beforeCursor: 'LOAD DATA LOCAL INPATH \'/some/path/file.ble\' OVERWRITE INTO TABLE bla;',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 70 } },
|
|
|
{ type: 'hdfs', location: {first_line: 1, last_line: 1, first_column: 25, last_column: 44}, path: '/some/path/file.ble' },
|
|
|
{ type: 'table', location: {first_line: 1, last_line: 1, first_column: 67, last_column: 70}, identifierChain: [{name: 'bla'}] }
|
|
|
]
|
|
|
@@ -237,6 +246,7 @@
|
|
|
dialect: 'impala',
|
|
|
beforeCursor: 'CREATE TABLE bla (id INT) LOCATION \'/bla/bla/\';',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 47 } },
|
|
|
{ type: 'hdfs', location: {first_line: 1, last_line: 1, first_column: 37, last_column: 46}, path: '/bla/bla/' }
|
|
|
]
|
|
|
});
|
|
|
@@ -249,6 +259,7 @@
|
|
|
dialect: 'hive',
|
|
|
beforeCursor: 'SELECT * FROM testTable t1 ORDER BY t1.a ASC, t1.b, t1.c DESC, t1.d;\nSELECT t1.bla FROM testTable2 t1;\nSELECT * FROM testTable3 t3, testTable4 t4; ',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 68 } },
|
|
|
{ type: 'asterisk', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 }, tables: [{ alias: 't1', identifierChain: [{ name: 'testTable' }] }] },
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 15, last_column: 24 }, identifierChain: [{ name: 'testTable' }]},
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 37, last_column: 39 }, identifierChain: [{ name: 'testTable' }]},
|
|
|
@@ -259,9 +270,11 @@
|
|
|
{ type: 'column', location: { first_line: 1, last_line: 1, first_column: 56, last_column: 57 }, identifierChain: [{ name: 'testTable' }, { name: 'c' }]},
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 64, last_column: 66 }, identifierChain: [{ name: 'testTable' }]},
|
|
|
{ type: 'column', location: { first_line: 1, last_line: 1, first_column: 67, last_column: 68 }, identifierChain: [{ name: 'testTable' }, { name: 'd' }]},
|
|
|
+ { type: 'statement', location: { first_line: 2, last_line: 2, first_column: 1, last_column: 33 } },
|
|
|
{ type: 'table', location: { first_line: 2, last_line: 2, first_column: 8, last_column: 10 }, identifierChain: [{ name: 'testTable2' }]},
|
|
|
{ type: 'column', location: { first_line: 2, last_line: 2, first_column: 11, last_column: 14 }, identifierChain: [{ name: 'testTable2' }, { name: 'bla' }]},
|
|
|
{ type: 'table', location: { first_line: 2, last_line: 2, first_column: 20, last_column: 30 }, identifierChain: [{ name: 'testTable2' }]},
|
|
|
+ { type: 'statement', location: { first_line: 3, last_line: 3, first_column: 1, last_column: 43 } },
|
|
|
{ type: 'asterisk', location: { first_line: 3, last_line: 3, first_column: 8, last_column: 9 }, tables: [{ alias: 't3', identifierChain: [{ name: 'testTable3' }]}, { alias: 't4', identifierChain: [{ name: 'testTable4' }] }] },
|
|
|
{ type: 'table', location: { first_line: 3, last_line: 3, first_column: 15, last_column: 25 }, identifierChain: [{ name: 'testTable3' }]},
|
|
|
{ type: 'table', location: { first_line: 3, last_line: 3, first_column: 30, last_column: 40 }, identifierChain: [{ name: 'testTable4' }]}
|
|
|
@@ -274,6 +287,7 @@
|
|
|
dialect: 'hive',
|
|
|
beforeCursor: 'SELECT t1.foo FROM table1 t1 CROSS JOIN table2 LEFT OUTER JOIN table3 JOIN table4 t4 ON (t1.c1 = table2.c2); ',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 108 } },
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 10 }, identifierChain: [{ name: 'table1' }]},
|
|
|
{ type: 'column', location: { first_line: 1, last_line: 1, first_column: 11, last_column: 14 }, identifierChain: [{ name: 'table1' },{ name: 'foo' }]},
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 20, last_column: 26 }, identifierChain: [{ name: 'table1' }]},
|
|
|
@@ -293,6 +307,7 @@
|
|
|
dialect: 'hive',
|
|
|
beforeCursor: 'SELECT * FROM foo WHERE bar IN (SELECT * FROM bla);',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 51 } },
|
|
|
{ type: 'asterisk', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 }, tables: [{ identifierChain: [{ name: 'foo' }] }] },
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 15, last_column: 18 }, identifierChain: [{ name: 'foo' }]},
|
|
|
{ type: 'column', location: { first_line: 1, last_line: 1, first_column: 25, last_column: 28 }, identifierChain:[{ name: 'foo' }, { name: 'bar'}]},
|
|
|
@@ -308,6 +323,7 @@
|
|
|
beforeCursor: 'SELECT ',
|
|
|
afterCursor: ' FROM testTableA',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 32 } },
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 22, last_column: 32}, identifierChain: [{ name: 'testTableA' }]}
|
|
|
]
|
|
|
});
|
|
|
@@ -319,6 +335,7 @@
|
|
|
beforeCursor: 'SELECT a.',
|
|
|
afterCursor: ' FROM testTableA',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 34 } },
|
|
|
{ type: 'column', location: { first_line: 1, last_line: 1, first_column: 10, last_column: 11 }, identifierChain: [{ name: 'testTableA' },{ name: 'a' }]},
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 24, last_column: 34}, identifierChain: [{ name: 'testTableA' }]}
|
|
|
]
|
|
|
@@ -331,6 +348,7 @@
|
|
|
beforeCursor: 'SELECT aaa',
|
|
|
afterCursor: ' FROM testTableA',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 27 } },
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 17, last_column: 27}, identifierChain: [{ name: 'testTableA' }]}
|
|
|
]
|
|
|
});
|
|
|
@@ -342,6 +360,7 @@
|
|
|
beforeCursor: 'SELECT aaa',
|
|
|
afterCursor: ' \nFROM testTableA',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 2, first_column: 1, last_column: 16 } },
|
|
|
{ type: 'table', location: { first_line: 2, last_line: 2, first_column: 6, last_column: 16}, identifierChain: [{ name: 'testTableA' }]}
|
|
|
]
|
|
|
});
|
|
|
@@ -353,17 +372,19 @@
|
|
|
beforeCursor: 'SELECT ',
|
|
|
afterCursor: 'bbbb FROM testTableA',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 28 } },
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 18, last_column: 28}, identifierChain: [{ name: 'testTableA' }]}
|
|
|
]
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- it('should report locations for "SELECT a.aaaaa|bbbb FROM testTableA"', function() {
|
|
|
+ it('should report locations for "SELECT aaaaa|bbbb FROM testTableA"', function() {
|
|
|
assertLocations({
|
|
|
dialect: 'hive',
|
|
|
beforeCursor: 'SELECT aaaaa',
|
|
|
afterCursor: 'bbbb FROM testTableA',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 33 } },
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 23, last_column: 33}, identifierChain: [{ name: 'testTableA' }]}
|
|
|
]
|
|
|
});
|
|
|
@@ -375,6 +396,7 @@
|
|
|
beforeCursor: 'SELECT foo.aaaaa',
|
|
|
afterCursor: 'bbbb FROM testTableA',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 37 } },
|
|
|
{ type: 'column', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 11}, identifierChain: [{ name: 'testTableA' },{ name: 'foo' }]},
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 27, last_column: 37}, identifierChain: [{ name: 'testTableA' }]}
|
|
|
]
|
|
|
@@ -387,6 +409,7 @@
|
|
|
beforeCursor: 'SELECT b, foo.aaaaa',
|
|
|
afterCursor: 'bbbb FROM testTableA',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 40 } },
|
|
|
{ type: 'column', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9}, identifierChain: [{ name: 'testTableA' }, { name: 'b' }]},
|
|
|
{ type: 'column', location: { first_line: 1, last_line: 1, first_column: 11, last_column: 14}, identifierChain: [{ name: 'testTableA' },{ name: 'foo' }]},
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 30, last_column: 40}, identifierChain: [{ name: 'testTableA' }]}
|
|
|
@@ -400,6 +423,7 @@
|
|
|
beforeCursor: 'SELECT foo, aaaaa',
|
|
|
afterCursor: 'bbbb FROM testTableA',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 38 } },
|
|
|
{ type: 'column', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 11}, identifierChain: [{ name: 'testTableA' }, { name: 'foo' }]},
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 28, last_column: 38}, identifierChain: [{ name: 'testTableA' }]}
|
|
|
]
|
|
|
@@ -412,6 +436,7 @@
|
|
|
beforeCursor: 'SELECT testTableB.a, cos(1), tta.abcdefg',
|
|
|
afterCursor: 'hijk, tta.bla, cos(1) FROM testTableA tta, testTableB;',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 94 } },
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 18 }, identifierChain: [{ name: 'testTableB' }]},
|
|
|
{ type: 'column', location: { first_line: 1, last_line: 1, first_column: 19, last_column: 20 }, identifierChain: [{ name: 'testTableB' },{ name: 'a' }]},
|
|
|
{ type: 'function', location: { first_line: 1, last_line: 1, first_column: 22, last_column: 24 }, function: 'cos' },
|
|
|
@@ -433,6 +458,7 @@
|
|
|
beforeCursor: 'SELECT tmp.bc, ROUND(tmp.r, 2) AS r FROM ( SELECT tstDb1.b1.cat AS bc, SUM(tstDb1.b1.price * tran.qua) AS r FROM tstDb1.b1 JOIN [SHUFFLE] tran ON ( tran.b_id = tstDb1.b1.id AND YEAR(tran.tran_d) BETWEEN 2008 AND 2010) GROUP BY tstDb1.b1.cat) tmp ORDER BY r DESC LIMIT 60;',
|
|
|
afterCursor: '',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 271 } },
|
|
|
{ type: 'subQuery', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 11 }, identifierChain: [{ subQuery: 'tmp' }]},
|
|
|
{ type: 'column', location: { first_line: 1, last_line: 1, first_column: 12, last_column: 14 }, identifierChain: [{ subQuery: 'tmp' },{name: 'bc' }]},
|
|
|
{ type: 'function', location: { first_line: 1, last_line: 1, first_column: 16, last_column: 20 }, function: 'round' },
|
|
|
@@ -472,6 +498,7 @@
|
|
|
beforeCursor: 'SELECT * FROM testTable ORDER BY a ASC, b, c DESC, d; ',
|
|
|
afterCursor: '',
|
|
|
expectedLocations: [
|
|
|
+ { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 53 } },
|
|
|
{ type: 'asterisk', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 }, tables: [{ identifierChain: [{ name: 'testTable' }] }] },
|
|
|
{ type: 'table', location: { first_line: 1, last_line: 1, first_column: 15, last_column: 24 }, identifierChain: [{ name: 'testTable' }]},
|
|
|
{ type: 'column', location: { first_line: 1, last_line: 1, first_column: 34, last_column: 35 }, identifierChain: [{ name: 'testTable' }, { name: 'a'}]},
|