-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YQL): improve work with scopes (#264)
* feat(YQL): improve work with scopes * fix: review
- Loading branch information
Showing
10 changed files
with
346 additions
and
75 deletions.
There are no files selected for viewing
This file contains 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
70 changes: 70 additions & 0 deletions
70
src/autocomplete/databases/yql/tests/yql/select/select-scopes.test.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import {parseYqlQueryWithCursor} from '../../../index'; | ||
import {YQLColumnsSuggestion} from '../../../types'; | ||
|
||
test('should suggest table name for column between statements', () => { | ||
const autocompleteResult = parseYqlQueryWithCursor( | ||
'ALTER TABLE before_table DROP COLUMN id; SELECT | FROM test_table ; ALTER TABLE after_table DROP COLUMN id;', | ||
); | ||
const columnSuggestions: YQLColumnsSuggestion = {tables: [{name: 'test_table'}], all: true}; | ||
|
||
expect(autocompleteResult.suggestColumns).toEqual(columnSuggestions); | ||
}); | ||
|
||
test('should suggest table name in nested statements', () => { | ||
const autocompleteResult = parseYqlQueryWithCursor( | ||
'ALTER TABLE before_table DROP COLUMN id; SELECT * FROM (SELECT | FROM bar) ; ALTER TABLE after_table DROP COLUMN id;', | ||
); | ||
const columnSuggestions: YQLColumnsSuggestion = {tables: [{name: 'bar'}], all: true}; | ||
|
||
expect(autocompleteResult.suggestColumns).toEqual(columnSuggestions); | ||
}); | ||
test('should suggest table name in nested statements', () => { | ||
const autocompleteResult = parseYqlQueryWithCursor( | ||
'ALTER TABLE before_table DROP COLUMN |; SELECT * FROM (SELECT foo FROM bar) ; ALTER TABLE after_table DROP COLUMN id;', | ||
); | ||
const columnSuggestions: YQLColumnsSuggestion = {tables: [{name: 'before_table'}]}; | ||
|
||
expect(autocompleteResult.suggestColumns).toEqual(columnSuggestions); | ||
}); | ||
|
||
test('should suggest columns from subquery', () => { | ||
const autocompleteResult = parseYqlQueryWithCursor( | ||
'SELECT | FROM (SELECT foo, bar as baz FROM bar);', | ||
); | ||
const columnSuggestions: YQLColumnsSuggestion = { | ||
tables: [{name: '', columns: ['foo', 'baz']}], | ||
all: true, | ||
}; | ||
expect(autocompleteResult.suggestColumns).toEqual(columnSuggestions); | ||
}); | ||
|
||
test('cannot suggest if subquery with asterisk', () => { | ||
const autocompleteResult = parseYqlQueryWithCursor('SELECT | FROM (SELECT * FROM bar);'); | ||
const columnSuggestions: YQLColumnsSuggestion = { | ||
all: true, | ||
tables: [{columns: undefined, name: ''}], | ||
}; | ||
expect(autocompleteResult.suggestColumns).toEqual(columnSuggestions); | ||
}); | ||
|
||
test('should suggest columns from first subquery', () => { | ||
const autocompleteResult = parseYqlQueryWithCursor( | ||
'SELECT | FROM (SELECT id FROM (SELECT foo FROM bar b join baz c on b.id = c.id));', | ||
); | ||
const columnSuggestions: YQLColumnsSuggestion = { | ||
tables: [{name: '', columns: ['id']}], | ||
all: true, | ||
}; | ||
expect(autocompleteResult.suggestColumns).toEqual(columnSuggestions); | ||
}); | ||
|
||
test('should suggest columns from first subquery', () => { | ||
const autocompleteResult = parseYqlQueryWithCursor( | ||
'SELECT * FROM (SELECT | FROM (SELECT foo FROM bar b join baz c on b.id = c.id));', | ||
); | ||
const columnSuggestions: YQLColumnsSuggestion = { | ||
tables: [{name: '', columns: ['foo']}], | ||
all: true, | ||
}; | ||
expect(autocompleteResult.suggestColumns).toEqual(columnSuggestions); | ||
}); |
This file contains 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
This file contains 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
Oops, something went wrong.