jupyter-duckdb 1.2.7__tar.gz → 1.2.100__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/PKG-INFO +2 -2
  2. jupyter_duckdb-1.2.100/setup.py +52 -0
  3. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/Difference.py +1 -1
  4. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/Divide.py +1 -1
  5. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/Division.py +0 -4
  6. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/FullOuterJoin.py +10 -3
  7. jupyter_duckdb-1.2.100/src/duckdb_kernel/tests/__init__.py +76 -0
  8. {jupyter_duckdb-1.2.7/test → jupyter_duckdb-1.2.100/src/duckdb_kernel/tests}/test_dc.py +141 -22
  9. {jupyter_duckdb-1.2.7/test → jupyter_duckdb-1.2.100/src/duckdb_kernel/tests}/test_ra.py +179 -53
  10. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/jupyter_duckdb.egg-info/PKG-INFO +2 -2
  11. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/jupyter_duckdb.egg-info/SOURCES.txt +6 -5
  12. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/jupyter_duckdb.egg-info/requires.txt +1 -1
  13. jupyter_duckdb-1.2.7/setup.py +0 -50
  14. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/README.md +0 -0
  15. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/setup.cfg +0 -0
  16. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/__init__.py +0 -0
  17. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/__main__.py +0 -0
  18. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/db/Column.py +0 -0
  19. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/db/Connection.py +0 -0
  20. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/db/Constraint.py +0 -0
  21. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/db/DatabaseError.py +0 -0
  22. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/db/ForeignKey.py +0 -0
  23. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/db/Table.py +0 -0
  24. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/db/__init__.py +0 -0
  25. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/db/error/EmptyResultError.py +0 -0
  26. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/db/error/__init__.py +0 -0
  27. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/db/implementation/duckdb/Connection.py +0 -0
  28. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/db/implementation/duckdb/__init__.py +0 -0
  29. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/db/implementation/postgres/Connection.py +0 -0
  30. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/db/implementation/postgres/__init__.py +0 -0
  31. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/db/implementation/postgres/util.py +0 -0
  32. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/db/implementation/sqlite/Connection.py +0 -0
  33. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/db/implementation/sqlite/__init__.py +0 -0
  34. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/kernel.json +0 -0
  35. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/kernel.py +0 -0
  36. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/magics/MagicCommand.py +0 -0
  37. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/magics/MagicCommandCallback.py +0 -0
  38. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/magics/MagicCommandException.py +0 -0
  39. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/magics/MagicCommandHandler.py +0 -0
  40. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/magics/StringWrapper.py +0 -0
  41. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/magics/__init__.py +0 -0
  42. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/DCParser.py +0 -0
  43. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/LogicParser.py +0 -0
  44. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/ParserError.py +0 -0
  45. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/RAParser.py +0 -0
  46. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/__init__.py +0 -0
  47. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/DCOperand.py +0 -0
  48. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/LogicElement.py +0 -0
  49. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/LogicOperand.py +0 -0
  50. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/LogicOperator.py +0 -0
  51. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/RABinaryOperator.py +0 -0
  52. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/RAElement.py +0 -0
  53. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/RAOperand.py +0 -0
  54. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/RAOperator.py +0 -0
  55. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/RAUnaryOperator.py +0 -0
  56. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/__init__.py +0 -0
  57. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/Add.py +0 -0
  58. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/And.py +0 -0
  59. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/ArrowLeft.py +0 -0
  60. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/ConditionalSet.py +0 -0
  61. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/Cross.py +0 -0
  62. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/Equal.py +0 -0
  63. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/GreaterThan.py +0 -0
  64. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/GreaterThanEqual.py +0 -0
  65. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/Intersection.py +0 -0
  66. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/Join.py +0 -0
  67. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/LeftOuterJoin.py +0 -0
  68. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/LessThan.py +0 -0
  69. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/LessThanEqual.py +0 -0
  70. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/Minus.py +0 -0
  71. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/Multiply.py +0 -0
  72. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/Or.py +0 -0
  73. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/RightOuterJoin.py +0 -0
  74. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/Unequal.py +0 -0
  75. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/Union.py +0 -0
  76. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/binary/__init__.py +0 -0
  77. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/unary/Not.py +0 -0
  78. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/unary/Projection.py +0 -0
  79. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/unary/Rename.py +0 -0
  80. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/unary/Selection.py +0 -0
  81. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/elements/unary/__init__.py +0 -0
  82. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/tokenizer/Token.py +0 -0
  83. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/tokenizer/Tokenizer.py +0 -0
  84. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/tokenizer/__init__.py +0 -0
  85. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/util/RenamableColumn.py +0 -0
  86. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/util/RenamableColumnList.py +0 -0
  87. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/parser/util/__init__.py +0 -0
  88. {jupyter_duckdb-1.2.7/test → jupyter_duckdb-1.2.100/src/duckdb_kernel/tests}/test_result_comparison.py +0 -0
  89. {jupyter_duckdb-1.2.7/test → jupyter_duckdb-1.2.100/src/duckdb_kernel/tests}/test_sql.py +0 -0
  90. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/util/ResultSetComparator.py +0 -0
  91. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/util/SQL.py +0 -0
  92. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/util/TestError.py +0 -0
  93. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/util/__init__.py +0 -0
  94. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/util/formatting.py +0 -0
  95. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/visualization/Drawer.py +0 -0
  96. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/visualization/RATreeDrawer.py +0 -0
  97. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/visualization/SchemaDrawer.py +0 -0
  98. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/duckdb_kernel/visualization/__init__.py +0 -0
  99. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/jupyter_duckdb.egg-info/dependency_links.txt +0 -0
  100. {jupyter_duckdb-1.2.7 → jupyter_duckdb-1.2.100}/src/jupyter_duckdb.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: jupyter-duckdb
3
- Version: 1.2.7
3
+ Version: 1.2.100
4
4
  Summary: a basic wrapper kernel for DuckDB
5
5
  Home-page: https://github.com/erictroebs/jupyter-duckdb
6
6
  Author: Eric Tröbs
@@ -14,7 +14,7 @@ Description-Content-Type: text/markdown
14
14
  Requires-Dist: jupyter
15
15
  Requires-Dist: graphviz==0.20.3
16
16
  Requires-Dist: checkmarkandcross
17
- Requires-Dist: duckdb==1.2.0
17
+ Requires-Dist: duckdb==1.2.1
18
18
  Dynamic: author
19
19
  Dynamic: author-email
20
20
  Dynamic: classifier
@@ -0,0 +1,52 @@
1
+ import os
2
+
3
+ # configuration
4
+ PACKAGE_VERSION = '1.2.100'
5
+ DUCKDB_VERSION = '1.2.1'
6
+
7
+ DEPENDENCIES = [
8
+ 'jupyter',
9
+ 'graphviz==0.20.3',
10
+ 'checkmarkandcross'
11
+ ]
12
+
13
+ if os.getenv('SQLITE') != '1' and os.getenv('DUCKDB') != '0':
14
+ DEPENDENCIES += [f'duckdb=={DUCKDB_VERSION}']
15
+
16
+ # main setup
17
+ if __name__ == '__main__':
18
+ from setuptools import setup, find_namespace_packages
19
+
20
+ # load README.md as long_description
21
+ with open('README.md', 'r', encoding='utf-8') as file:
22
+ long_description = file.read()
23
+
24
+ # main setup call
25
+ setup(
26
+ name='jupyter-duckdb',
27
+ version=PACKAGE_VERSION,
28
+ python_requires='>=3.10',
29
+ install_requires=DEPENDENCIES,
30
+ author='Eric Tröbs',
31
+ author_email='eric.troebs@tu-ilmenau.de',
32
+ description='a basic wrapper kernel for DuckDB',
33
+ long_description=long_description,
34
+ long_description_content_type='text/markdown',
35
+ url='https://github.com/erictroebs/jupyter-duckdb',
36
+ project_urls={
37
+ 'Bug Tracker': 'https://github.com/erictroebs/jupyter-duckdb/issues',
38
+ },
39
+ classifiers=[
40
+ 'Programming Language :: Python :: 3',
41
+ 'License :: OSI Approved :: MIT License',
42
+ 'Operating System :: OS Independent',
43
+ ],
44
+ package_dir={'': 'src'},
45
+ packages=find_namespace_packages(where='src'),
46
+ include_package_data=True,
47
+ package_data={
48
+ 'duckdb_kernel': [
49
+ 'kernel.json'
50
+ ]
51
+ }
52
+ )
@@ -8,7 +8,7 @@ from ...util.RenamableColumnList import RenamableColumnList
8
8
  class Difference(RABinaryOperator):
9
9
  @staticmethod
10
10
  def symbols() -> Tuple[str, ...]:
11
- return '\\',
11
+ return '-', '\\'
12
12
 
13
13
  def to_sql(self, tables: Dict[str, Table]) -> Tuple[str, RenamableColumnList]:
14
14
  # execute subqueries
@@ -8,7 +8,7 @@ class Divide(LogicOperator):
8
8
 
9
9
  @staticmethod
10
10
  def symbols() -> Tuple[str, ...]:
11
- return '÷', '/'
11
+ return '/', '÷'
12
12
 
13
13
  @property
14
14
  def sql_symbol(self) -> str:
@@ -27,10 +27,6 @@ class Division(RABinaryOperator):
27
27
  # inter_name_left = ', '.join(l.current_name for l, _ in inter_cols)
28
28
  inter_name_right = ', '.join(r.current_name for _, r in inter_cols)
29
29
 
30
- print('-', diff_name)
31
- print(inter_name)
32
- print(inter_name_right)
33
-
34
30
  # create sql
35
31
  return f'''
36
32
  SELECT {diff_name}
@@ -1,7 +1,9 @@
1
+ from typing import Optional
1
2
  from typing import Tuple, Dict
2
3
 
3
4
  from duckdb_kernel.db import Table
4
5
  from ..RABinaryOperator import RABinaryOperator
6
+ from ...util.RenamableColumn import RenamableColumn
5
7
  from ...util.RenamableColumnList import RenamableColumnList
6
8
 
7
9
 
@@ -10,6 +12,13 @@ class FullOuterJoin(RABinaryOperator):
10
12
  def symbols() -> Tuple[str, ...]:
11
13
  return chr(10199), 'fjoin', 'ojoin'
12
14
 
15
+ @staticmethod
16
+ def _coalesce(c1: RenamableColumn, c2: Optional[RenamableColumn]) -> str:
17
+ if c2 is not None:
18
+ return f'COALESCE({c1.current_name}, {c2.current_name}) AS {c1.current_name}'
19
+ else:
20
+ return c1.current_name
21
+
13
22
  def to_sql(self, tables: Dict[str, Table]) -> Tuple[str, RenamableColumnList]:
14
23
  # execute subqueries
15
24
  lq, lcols = self.left.to_sql(tables)
@@ -19,9 +28,7 @@ class FullOuterJoin(RABinaryOperator):
19
28
  join_cols, all_cols = lcols.intersect(rcols)
20
29
 
21
30
  replacements = {c1: c2 for c1, c2 in join_cols}
22
- select_cols = [
23
- f'COALESCE({c.current_name}, {replacements.get(c).current_name})' if c in replacements else c.current_name
24
- for c in all_cols]
31
+ select_cols = [self._coalesce(c, replacements.get(c)) for c in all_cols]
25
32
  select_clause = ', '.join(select_cols)
26
33
 
27
34
  on_clause = ' AND '.join(f'{l.current_name} = {r.current_name}' for l, r in join_cols)
@@ -0,0 +1,76 @@
1
+ import os
2
+ from typing import Dict, List, Tuple
3
+
4
+ from duckdb_kernel.db import Connection as DB, Table
5
+ from duckdb_kernel.db.error import EmptyResultError
6
+ from duckdb_kernel.parser.elements import RAElement
7
+ from duckdb_kernel.parser.elements.binary import ConditionalSet
8
+
9
+ with open('examples/tables.sql', 'r', encoding='utf-8') as file:
10
+ EXAMPLE_STMTS = [stmt
11
+ for stmt in file.read().split(';')
12
+ if stmt.strip()]
13
+
14
+
15
+ class Connection:
16
+ def __enter__(self):
17
+ db_type = os.environ.get('DB_TYPE')
18
+ if db_type == 'postgres':
19
+ host = os.environ.get('POSTGRES_HOST', 'localhost')
20
+ port = int(os.environ.get('POSTGRES_PORT', 5432))
21
+ username = os.environ.get('POSTGRES_USER', 'postgres')
22
+ password = os.environ.get('POSTGRES_PASSWORD', 'postgres')
23
+
24
+ from duckdb_kernel.db.implementation.postgres import Connection as PostgreSQL
25
+ self.con: DB = PostgreSQL(host, port, username, password, None)
26
+ elif db_type == 'sqlite':
27
+ from duckdb_kernel.db.implementation.sqlite import Connection as SQLite
28
+ self.con: DB = SQLite(':memory:')
29
+ else:
30
+ from duckdb_kernel.db.implementation.duckdb import Connection as DuckDB
31
+ self.con: DB = DuckDB(':memory:')
32
+
33
+ for stmt in EXAMPLE_STMTS:
34
+ try:
35
+ self.con.execute(stmt)
36
+ except EmptyResultError:
37
+ pass
38
+
39
+ return self
40
+
41
+ def __exit__(self, exc_type, exc_val, exc_tb):
42
+ self.con.close()
43
+
44
+ @property
45
+ def tables(self) -> Dict[str, Table]:
46
+ return self.con.analyze()
47
+
48
+ def execute_sql_return_cols(self, query: str) -> Tuple[List, List]:
49
+ return self.con.execute(query)
50
+
51
+ def execute_sql(self, query: str) -> List:
52
+ _, rows = self.execute_sql_return_cols(query)
53
+ return rows
54
+
55
+ def execute_ra_return_cols(self, root: RAElement) -> Tuple[List, List]:
56
+ sql = root.to_sql_with_renamed_columns(self.tables)
57
+ cols, rows = self.execute_sql_return_cols(sql)
58
+
59
+ return cols, sorted(rows, key=lambda t: tuple(-1 if x is None else x for x in t))
60
+
61
+ def execute_ra(self, root: RAElement) -> List:
62
+ _, rows = self.execute_ra_return_cols(root)
63
+ return rows
64
+
65
+ def execute_dc_return_cols(self, root: ConditionalSet) -> Tuple[List, List]:
66
+ sql, cnm = root.to_sql_with_renamed_columns(self.tables)
67
+ cols, rows = self.execute_sql_return_cols(sql)
68
+
69
+ return [cnm.get(c, c) for c in cols], sorted(rows)
70
+
71
+ def execute_dc(self, root: ConditionalSet) -> List:
72
+ _, rows = self.execute_dc_return_cols(root)
73
+ return rows
74
+
75
+
76
+ __all__ = ['Connection']
@@ -13,7 +13,12 @@ def test_case_insensitivity():
13
13
 
14
14
  # execute to test case insensitivity
15
15
  with Connection() as con:
16
- assert con.execute_dc(root) == [
16
+ cols, rows = con.execute_dc_return_cols(root)
17
+
18
+ assert [c.lower() for c in cols] == [
19
+ 'username'
20
+ ]
21
+ assert rows == [
17
22
  ('Alice',),
18
23
  ('Bob',),
19
24
  ('Charlie',)
@@ -29,7 +34,12 @@ def test_case_insensitivity():
29
34
 
30
35
  # execute to test case insensitivity
31
36
  with Connection() as con:
32
- assert con.execute_dc(root) == [
37
+ cols, rows = con.execute_dc_return_cols(root)
38
+
39
+ assert [c.lower() for c in cols] == [
40
+ 'username'
41
+ ]
42
+ assert rows == [
33
43
  ('Alice',),
34
44
  ('Bob',),
35
45
  ('Charlie',)
@@ -46,7 +56,12 @@ def test_simple_queries():
46
56
  'id | Users (id ,_)',
47
57
  ]:
48
58
  root = DCParser.parse_query(query)
49
- assert con.execute_dc(root) == [
59
+ cols, rows = con.execute_dc_return_cols(root)
60
+
61
+ assert [c.lower() for c in cols] == [
62
+ 'id'
63
+ ]
64
+ assert rows == [
50
65
  (1,),
51
66
  (2,),
52
67
  (3,)
@@ -57,7 +72,13 @@ def test_simple_queries():
57
72
  '{ id,name | Users(id, name) }'
58
73
  ]:
59
74
  root = DCParser.parse_query(query)
60
- assert con.execute_dc(root) == [
75
+ cols, rows = con.execute_dc_return_cols(root)
76
+
77
+ assert [c.lower() for c in cols] == [
78
+ 'id',
79
+ 'name'
80
+ ]
81
+ assert rows == [
61
82
  (1, 'Alice'),
62
83
  (2, 'Bob'),
63
84
  (3, 'Charlie')
@@ -67,14 +88,25 @@ def test_simple_queries():
67
88
  def test_asterisk_projection():
68
89
  with Connection() as con:
69
90
  root = DCParser.parse_query('{ * | Users(id, _) }')
70
- assert con.execute_dc(root) == [
91
+ cols, rows = con.execute_dc_return_cols(root)
92
+
93
+ assert [c.lower() for c in cols] == [
94
+ 'id'
95
+ ]
96
+ assert rows == [
71
97
  (1,),
72
98
  (2,),
73
99
  (3,)
74
100
  ]
75
101
 
76
102
  root = DCParser.parse_query('{ * | Users(id, name) }')
77
- assert con.execute_dc(root) == [
103
+ cols, rows = con.execute_dc_return_cols(root)
104
+
105
+ assert [c.lower() for c in cols] == [
106
+ 'id',
107
+ 'name'
108
+ ]
109
+ assert rows == [
78
110
  (1, 'Alice'),
79
111
  (2, 'Bob'),
80
112
  (3, 'Charlie')
@@ -89,7 +121,12 @@ def test_conditions():
89
121
  '{ name | Users(id, name) ∧ (id = 2 ∨ id = 3) }'
90
122
  ]:
91
123
  root = DCParser.parse_query(query)
92
- assert con.execute_dc(root) == [
124
+ cols, rows = con.execute_dc_return_cols(root)
125
+
126
+ assert [c.lower() for c in cols] == [
127
+ 'name'
128
+ ]
129
+ assert rows == [
93
130
  ('Bob',),
94
131
  ('Charlie',)
95
132
  ]
@@ -99,7 +136,12 @@ def test_conditions():
99
136
  '{ id | Users(id, name) ∧ name > "B" ∧ name < "C" }',
100
137
  ]:
101
138
  root = DCParser.parse_query(query)
102
- assert con.execute_dc(root) == [
139
+ cols, rows = con.execute_dc_return_cols(root)
140
+
141
+ assert [c.lower() for c in cols] == [
142
+ 'id'
143
+ ]
144
+ assert rows == [
103
145
  (2,)
104
146
  ]
105
147
 
@@ -111,7 +153,12 @@ def test_shortcut_conditions():
111
153
  '{ name | Users(1, name) }'
112
154
  ]:
113
155
  root = DCParser.parse_query(query)
114
- assert con.execute_dc(root) == [
156
+ cols, rows = con.execute_dc_return_cols(root)
157
+
158
+ assert [c.lower() for c in cols] == [
159
+ 'name'
160
+ ]
161
+ assert rows == [
115
162
  ('Alice',)
116
163
  ]
117
164
 
@@ -119,7 +166,12 @@ def test_shortcut_conditions():
119
166
  '{ season_name | Seasons(1, 1, season_name) }'
120
167
  ]:
121
168
  root = DCParser.parse_query(query)
122
- assert con.execute_dc(root) == [
169
+ cols, rows = con.execute_dc_return_cols(root)
170
+
171
+ assert [c.lower() for c in cols] == [
172
+ 'season_name'
173
+ ]
174
+ assert rows == [
123
175
  ('Show 1 / Season 1',)
124
176
  ]
125
177
 
@@ -128,7 +180,13 @@ def test_shortcut_conditions():
128
180
  '{ sname, ename | Seasons(snum, 2, sname) ∧ Episodes(enum, snum, 2, ename) }'
129
181
  ]:
130
182
  root = DCParser.parse_query(query)
131
- assert con.execute_dc(root) == [
183
+ cols, rows = con.execute_dc_return_cols(root)
184
+
185
+ assert [c.lower() for c in cols] == [
186
+ 'sname',
187
+ 'ename'
188
+ ]
189
+ assert rows == [
132
190
  ('Show 2 / Season 1', 'Show 2 / Season 1 / Episode 1'),
133
191
  ('Show 2 / Season 1', 'Show 2 / Season 1 / Episode 2'),
134
192
  ('Show 2 / Season 1', 'Show 2 / Season 1 / Episode 3'),
@@ -146,7 +204,12 @@ def test_joins():
146
204
  '{ sename | Shows(shid, shname) ∧ Seasons(senum, shid, sename) }'
147
205
  ]:
148
206
  root = DCParser.parse_query(query)
149
- assert con.execute_dc(root) == [
207
+ cols, rows = con.execute_dc_return_cols(root)
208
+
209
+ assert [c.lower() for c in cols] == [
210
+ 'sename'
211
+ ]
212
+ assert rows == [
150
213
  ('Show 1 / Season 1',),
151
214
  ('Show 1 / Season 2',),
152
215
  ('Show 2 / Season 1',),
@@ -158,7 +221,12 @@ def test_joins():
158
221
  '{ sename | Seasons(senum, shid, sename) ∧ Shows(shid, "Show 1") }'
159
222
  ]:
160
223
  root = DCParser.parse_query(query)
161
- assert con.execute_dc(root) == [
224
+ cols, rows = con.execute_dc_return_cols(root)
225
+
226
+ assert [c.lower() for c in cols] == [
227
+ 'sename'
228
+ ]
229
+ assert rows == [
162
230
  ('Show 1 / Season 1',),
163
231
  ('Show 1 / Season 2',)
164
232
  ]
@@ -168,7 +236,13 @@ def test_joins():
168
236
  '{ sname, ename | Seasons(snum, shid, sname) ∧ Episodes(enum, snum, shid, ename) ∧ shid = 2 }'
169
237
  ]:
170
238
  root = DCParser.parse_query(query)
171
- assert con.execute_dc(root) == [
239
+ cols, rows = con.execute_dc_return_cols(root)
240
+
241
+ assert [c.lower() for c in cols] == [
242
+ 'sname',
243
+ 'ename'
244
+ ]
245
+ assert rows == [
172
246
  ('Show 2 / Season 1', 'Show 2 / Season 1 / Episode 1'),
173
247
  ('Show 2 / Season 1', 'Show 2 / Season 1 / Episode 2'),
174
248
  ('Show 2 / Season 1', 'Show 2 / Season 1 / Episode 3'),
@@ -183,13 +257,24 @@ def test_joins():
183
257
  '{ s2,c5 | Shows(s1,s2) ∧ Episodes(e1,e2,s1,e4) ∧ Characters(c1,e1,c3,s1,c5) ∧ s1=2 ∧ e4="Show 2 / Season 1 / Episode 2" }'
184
258
  ]:
185
259
  root = DCParser.parse_query(query)
186
- assert con.execute_dc(root) == [
260
+ cols, rows = con.execute_dc_return_cols(root)
261
+
262
+ assert [c.lower() for c in cols] == [
263
+ 's2',
264
+ 'c5'
265
+ ]
266
+ assert rows == [
187
267
  ('Show 2', 'Actor F')
188
268
  ]
189
269
 
190
270
  # cross join
191
271
  root = DCParser.parse_query('{ sename | Shows(shid1, shname) ∧ Seasons(senum, shid2, sename) ∧ shid1 = shid2 }')
192
- assert con.execute_dc(root) == [
272
+ cols, rows = con.execute_dc_return_cols(root)
273
+
274
+ assert [c.lower() for c in cols] == [
275
+ 'sename'
276
+ ]
277
+ assert rows == [
193
278
  ('Show 1 / Season 1',),
194
279
  ('Show 1 / Season 2',),
195
280
  ('Show 2 / Season 1',),
@@ -201,7 +286,13 @@ def test_joins():
201
286
  '{ s2,c5 | Shows(sa1,s2) ∧ Episodes(e1,e2,sb1,e4) ∧ Characters(c1,e1,c3,sc1,c5) ∧ sa1=2 ∧ sa1 = sb1 ∧ sb1 = sc1 ∧ e4="Show 2 / Season 1 / Episode 2" }'
202
287
  ]:
203
288
  root = DCParser.parse_query(query)
204
- assert con.execute_dc(root) == [
289
+ cols, rows = con.execute_dc_return_cols(root)
290
+
291
+ assert [c.lower() for c in cols] == [
292
+ 's2',
293
+ 'c5'
294
+ ]
295
+ assert rows == [
205
296
  ('Show 2', 'Actor F')
206
297
  ]
207
298
 
@@ -213,7 +304,14 @@ def test_disjunction_joins():
213
304
  "{ enum, snum, sid | Episodes(enum, snum, sid, ename) ∧ (Characters(cname1, enum, snum, sid, _) ∧ cname1 = 'Character B' ∨ Characters(cname2, enum, snum, sid, _) ∧ cname2 = 'Character D') }",
214
305
  ]:
215
306
  root = DCParser.parse_query(query)
216
- assert con.execute_dc(root) == [
307
+ cols, rows = con.execute_dc_return_cols(root)
308
+
309
+ assert [c.lower() for c in cols] == [
310
+ 'enum',
311
+ 'snum',
312
+ 'sid'
313
+ ]
314
+ assert rows == [
217
315
  (1, 1, 1),
218
316
  (2, 1, 1)
219
317
  ]
@@ -225,7 +323,13 @@ def test_cross_join():
225
323
  "{ cname1, cname2 | Characters(cname1, _, _, 2, _) ∧ Characters(cname2, _, _, 2, _) }",
226
324
  ]:
227
325
  root = DCParser.parse_query(query)
228
- assert con.execute_dc(root) == [
326
+ cols, rows = con.execute_dc_return_cols(root)
327
+
328
+ assert [c.lower() for c in cols] == [
329
+ 'cname1',
330
+ 'cname2'
331
+ ]
332
+ assert rows == [
229
333
  ('Character E', 'Character E'),
230
334
  ('Character E', 'Character F'),
231
335
  ('Character F', 'Character E'),
@@ -243,7 +347,12 @@ def test_underscores():
243
347
  '{ ename | Seasons(snum, shid, sname) ∧ Episodes(_, __, shid, ename) ∧ shid = 2 }'
244
348
  ]:
245
349
  root = DCParser.parse_query(query)
246
- assert con.execute_dc(root) == [
350
+ cols, rows = con.execute_dc_return_cols(root)
351
+
352
+ assert [c.lower() for c in cols] == [
353
+ 'ename'
354
+ ]
355
+ assert rows == [
247
356
  ('Show 2 / Season 1 / Episode 1',),
248
357
  ('Show 2 / Season 1 / Episode 2',),
249
358
  ('Show 2 / Season 1 / Episode 3',),
@@ -258,7 +367,12 @@ def test_underscores():
258
367
  '{ ename | Seasons(snum, shid, sname) ∧ Episodes(_, _, shid, ename) ∧ shid = 2 }'
259
368
  ]:
260
369
  root = DCParser.parse_query(query)
261
- assert con.execute_dc(root) == [
370
+ cols, rows = con.execute_dc_return_cols(root)
371
+
372
+ assert [c.lower() for c in cols] == [
373
+ 'ename'
374
+ ]
375
+ assert rows == [
262
376
  ('Show 2 / Season 1 / Episode 1',),
263
377
  ('Show 2 / Season 1 / Episode 2',),
264
378
  ('Show 2 / Season 1 / Episode 3',),
@@ -274,7 +388,12 @@ def test_underscores():
274
388
  '{ ename | Seasons(_, shid, __) ∧ Episodes(_, __, shid, ename) ∧ shid = 2 }'
275
389
  ]:
276
390
  root = DCParser.parse_query(query)
277
- assert con.execute_dc(root) == [
391
+ cols, rows = con.execute_dc_return_cols(root)
392
+
393
+ assert [c.lower() for c in cols] == [
394
+ 'ename'
395
+ ]
396
+ assert rows == [
278
397
  ('Show 2 / Season 1 / Episode 1',),
279
398
  ('Show 2 / Season 1 / Episode 2',),
280
399
  ('Show 2 / Season 1 / Episode 3',),