Skip to content

Commit d84bdf7

Browse files
committed
Add sqlean.py for Sqlite3
1 parent 0e213b7 commit d84bdf7

4 files changed

Lines changed: 31 additions & 8 deletions

File tree

.github/workflows/run-test.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ on:
44
push:
55
branches:
66
- "*"
7-
pull_request:
8-
types: [opened, synchronize, reopened]
97

108
jobs:
119
pytest:
@@ -38,6 +36,7 @@ jobs:
3836
pip install tenacity
3937
pip install "sqlalchemy>=1.0.0,<2.0.0"
4038
pip install pyparsing
39+
pip install sqlean.py
4140
- name: black
4241
run: |
4342
pip install black

pydynamodb/superset_dynamodb/querydb_sqlite.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
import logging
3-
import sqlite3
3+
import sqlean as sqlite3
44
from datetime import datetime, date
55
from contextlib import closing
66
from typing import Any, Type
@@ -24,6 +24,7 @@ def __init__(
2424
@property
2525
def connection(self):
2626
if self._connection is None:
27+
sqlite3.extensions.enable("math", "regexp", "stats", "text")
2728
self._connection = sqlite3.connect(
2829
self.config.db_url,
2930
detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES,

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"botocore>=1.24.7",
1515
"tenacity>=4.1.0",
1616
"pyparsing>=3.0.0",
17+
"sqlean.py>=3.45.0",
1718
]
1819

1920
extras_require = {

tests/test_superset_dynamodb.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ def test_execute_select(self, superset_cursor):
182182
ret = superset_cursor.fetchall()
183183
assert len(ret) == 6
184184
assert [(d[0], d[1]) for d in superset_cursor.description] == [
185-
("col_list", None),
186-
("A", None),
185+
("col_list", "TEXT"),
186+
("A", "REAL"),
187187
]
188188

189189
def test_execute_nested_select(self, superset_cursor):
@@ -285,11 +285,33 @@ def test_string_functions_select_2(self, superset_cursor):
285285

286286
superset_cursor.execute(
287287
"""
288-
SELECT "col_list_1", "col_list_1_replace", "col_map_B_1_upper", "col_map_B_1_lower" FROM (
288+
SELECT "col_list_1", "col_list_1_replace", "col_map_B_1_upper",
289+
"col_map_B_1_lower", "col_map_B_1_substr" FROM (
289290
SELECT col_list_1,
290291
lower(replace(col_map_B_1, '-', '_')) col_list_1_replace,
291292
UPPER(TRIM(col_map_B_1)) col_map_B_1_upper,
292-
lower(col_map_B_1) col_map_B_1_lower
293+
lower(col_map_B_1) col_map_B_1_lower,
294+
SUBSTR(col_map_B_1, INSTR(col_map_B_1, '-')+1, 1) col_map_B_1_substr
295+
FROM (
296+
SELECT col_list[1] col_list_1, col_map.B[1] col_map_B_1
297+
FROM %s WHERE key_partition='row_1'
298+
) WHERE col_list_1 = 'F'
299+
)
300+
ORDER BY "col_list_1" DESC
301+
"""
302+
% TESTCASE04_TABLE
303+
)
304+
ret = superset_cursor.fetchall()
305+
assert len(ret) == 2
306+
assert ret[0] == ("F", "f_2", "F-2", "f-2", "2")
307+
308+
def test_sqlean_string_functions(self, superset_cursor):
309+
superset_cursor.execute(
310+
"""
311+
SELECT "col_list_1", "col_map_B_part1", "col_map_B_part2" FROM (
312+
SELECT col_list_1,
313+
text_split(col_map_B_1, '-', 1) col_map_B_part1,
314+
text_split(col_map_B_1, '-', 2) col_map_B_part2
293315
FROM (
294316
SELECT col_list[1] col_list_1, col_map.B[1] col_map_B_1
295317
FROM %s WHERE key_partition='row_1'
@@ -301,7 +323,7 @@ def test_string_functions_select_2(self, superset_cursor):
301323
)
302324
ret = superset_cursor.fetchall()
303325
assert len(ret) == 2
304-
assert ret[0] == ("F", "f_2", "F-2", "f-2")
326+
assert ret[0] == ("F", "F", "2")
305327

306328
def test_sqlalchemy_execute_nested_select(self, superset_engine):
307329
_, conn = superset_engine

0 commit comments

Comments
 (0)