Repository: reata/sqllineage

Issue:
multi-line sql causes AssertionError
```sql
SELECT * FROM
tab1
```
causes following exception

Traceback (most recent call last):
  File "/home/admin/.pyenv/versions/3.6.8/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/admin/.pyenv/versions/3.6.8/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/admin/repos/sqllineage/sqllineage/core.py", line 131, in <module>
    main()
  File "/home/admin/repos/sqllineage/sqllineage/core.py", line 119, in main
    print(LineageParser(sql))
  File "/home/admin/repos/sqllineage/sqllineage/core.py", line 23, in __init__
    self._extract_from_token(stmt)
  File "/home/admin/repos/sqllineage/sqllineage/core.py", line 75, in _extract_from_token
    assert isinstance(sub_token, Identifier)
AssertionError

Discussion:
codecov-io: # [Codecov](https://codecov.io/gh/reata/sqllineage/pull/19?src=pr&el=h1) Report
> Merging [#19](https://codecov.io/gh/reata/sqllineage/pull/19?src=pr&el=desc) into [master](https://codecov.io/gh/reata/sqllineage/commit/2901dd193c45e4ae0aab792ac0aaa11a04a2de1b?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/reata/sqllineage/pull/19/graphs/tree.svg?width=650&token=latkaw2Lx6&height=150&src=pr)](https://codecov.io/gh/reata/sqllineage/pull/19?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master      #19   +/-   ##
=======================================
  Coverage   79.38%   79.38%           
=======================================
  Files           1        1           
  Lines          97       97           
=======================================
  Hits           77       77           
  Misses         20       20
```


| [Impacted Files](https://codecov.io/gh/reata/sqllineage/pull/19?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [sqllineage/core.py](https://codecov.io/gh/reata/sqllineage/pull/19/diff?src=pr&el=tree#diff-c3FsbGluZWFnZS9jb3JlLnB5) | `79.38% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/reata/sqllineage/pull/19?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/reata/sqllineage/pull/19?src=pr&el=footer). Last update [2901dd1...9c8b269](https://codecov.io/gh/reata/sqllineage/pull/19?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/sqllineage/core.py b/sqllineage/core.py
index 2f5e0b6..fbf17f2 100644
--- a/sqllineage/core.py
+++ b/sqllineage/core.py
@@ -4,7 +4,7 @@ from typing import List, Set
 
 import sqlparse
 from sqlparse.sql import Function, Identifier, Parenthesis, Statement, TokenList
-from sqlparse.tokens import Keyword, Token, Whitespace
+from sqlparse.tokens import Keyword, Token
 
 SOURCE_TABLE_TOKENS = ('FROM', 'JOIN', 'INNER JOIN', 'LEFT JOIN', 'RIGHT JOIN', 'LEFT OUTER JOIN', 'RIGHT OUTER JOIN',
                        'FULL OUTER JOIN', 'CROSS JOIN')
@@ -69,7 +69,7 @@ Target Tables:
                 self._target_tables.add(sub_token.get_alias())
                 continue
             if source_table_token_flag:
-                if sub_token.ttype == Whitespace:
+                if sub_token.is_whitespace:
                     continue
                 else:
                     assert isinstance(sub_token, Identifier)
@@ -82,7 +82,7 @@ Target Tables:
                         self._source_tables.add(sub_token.get_real_name())
                     source_table_token_flag = False
             elif target_table_token_flag:
-                if sub_token.ttype == Whitespace:
+                if sub_token.is_whitespace:
                     continue
                 elif isinstance(sub_token, Function):
                     # insert into tab (col1, col2), tab (col1, col2) will be parsed as Function
@@ -95,7 +95,7 @@ Target Tables:
                     self._target_tables.add(sub_token.get_real_name())
                     target_table_token_flag = False
             elif temp_table_token_flag:
-                if sub_token.ttype == Whitespace:
+                if sub_token.is_whitespace:
                     continue
                 else:
                     assert isinstance(sub_token, Identifier)


Test patch:
diff --git a/tests/test_select.py b/tests/test_select.py
index 49fe323..8837091 100644
--- a/tests/test_select.py
+++ b/tests/test_select.py
@@ -5,6 +5,11 @@ def test_select():
     helper("SELECT col1 FROM tab1", {"tab1"})
 
 
+def test_select_multi_line():
+    helper("""SELECT col1 FROM
+tab1""", {"tab1"})
+
+
 def test_select_asterisk():
     helper("SELECT * FROM tab1", {"tab1"})