-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from cratedb_sqlparse.parser import Metadata | ||
|
||
|
||
def test_table_metadata(): | ||
from cratedb_sqlparse import sqlparse | ||
|
||
query = "SELECT 1; SELECT 2;" | ||
stmts = sqlparse(query) | ||
for stmt in stmts: | ||
assert hasattr(stmt, "metadata") | ||
assert isinstance(stmt.metadata, Metadata) | ||
|
||
|
||
def test_table_name_statement(): | ||
from cratedb_sqlparse import sqlparse | ||
|
||
query = "CREATE TABLE doc.tbl2 (a TEXT)" | ||
|
||
stmts = sqlparse(query) | ||
stmt = stmts[0] | ||
|
||
assert stmt.metadata.schema == "doc" | ||
assert stmt.metadata.table_name == "tbl2" | ||
|
||
|
||
def test_table_name_statements(): | ||
from cratedb_sqlparse import sqlparse | ||
|
||
query = """ | ||
SELECT A,B,C,D,E FROM doc.tbl1; | ||
SELECT A,B FROM "doc"."tbl1"; | ||
SELECT A,B FROM "tbl1"; | ||
SELECT A,B FROM tbl1; | ||
""" | ||
|
||
stmts = sqlparse(query=query) | ||
|
||
assert stmts[0].metadata.schema == "doc" | ||
assert stmts[0].metadata.table_name == "tbl1" | ||
|
||
assert stmts[1].metadata.schema == "doc" | ||
assert stmts[1].metadata.table_name == "tbl1" | ||
|
||
assert stmts[2].metadata.schema is None | ||
assert stmts[2].metadata.table_name == "tbl1" | ||
|
||
assert stmts[3].metadata.schema is None | ||
assert stmts[3].metadata.table_name == "tbl1" |