Skip to content

Commit 51c1708

Browse files
committed
work on new SQL cdata example
1 parent f7b3546 commit 51c1708

File tree

9 files changed

+344
-19
lines changed

9 files changed

+344
-19
lines changed

Examples/cdata/cdata.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,13 +1228,13 @@
12281228
"pycharm": {
12291229
"stem_cell": {
12301230
"cell_type": "raw",
1231+
"source": [],
12311232
"metadata": {
12321233
"collapsed": false
1233-
},
1234-
"source": []
1234+
}
12351235
}
12361236
}
12371237
},
12381238
"nbformat": 4,
12391239
"nbformat_minor": 4
1240-
}
1240+
}

Examples/cdata/ranking_pivot_example.ipynb

Lines changed: 325 additions & 0 deletions
Large diffs are not rendered by default.

build/lib/data_algebra/data_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2035,7 +2035,7 @@ def to_sql_implementation(self, db_model, *, using, temp_id_source):
20352035
db_model=db_model, using=None, temp_id_source=temp_id_source
20362036
)
20372037
# claims to use all columns
2038-
query = sub_query.to_sql(columns=self.columns_used_from_sources(), db_model=db_model)
2038+
query = sub_query.to_sql(columns=self.columns_used_from_sources()[0], db_model=db_model)
20392039
blocks_out_table = None
20402040
if self.record_map.blocks_in is not None:
20412041
query = db_model.blocks_to_row_recs_query(

build/lib/data_algebra/db_model.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -716,10 +716,10 @@ def row_recs_to_blocks_query(
716716
if not (isnull[i]):
717717
source_col = col[i]
718718
col_sql = (
719-
" WHEN b."
719+
" WHEN CAST(b."
720720
+ self.quote_identifier(result_col)
721-
+ " = "
722-
+ self.quote_literal(source_col)
721+
+ " AS VARCHAR) = "
722+
+ self.quote_string(str(source_col))
723723
+ " THEN a."
724724
+ self.quote_identifier(source_col)
725725
+ "\n"
@@ -773,10 +773,10 @@ def blocks_to_row_recs_query(
773773
clauses = []
774774
for cc in record_spec.control_table_keys:
775775
clauses.append(
776-
" ( "
776+
" ( CAST("
777777
+ self.quote_identifier(cc)
778-
+ " = "
779-
+ self.quote_literal(record_spec.control_table[cc][i])
778+
+ " AS VARCHAR) = "
779+
+ self.quote_string(str(record_spec.control_table[cc][i]))
780780
+ " ) "
781781
)
782782
cstmt = (

coverage.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
============================= test session starts ==============================
2-
platform darwin -- Python 3.7.5, pytest-5.3.1, py-1.8.0, pluggy-0.13.1
2+
platform darwin -- Python 3.7.5, pytest-5.2.4, py-1.8.0, pluggy-0.13.0
33
rootdir: /Users/johnmount/Documents/work/data_algebra
44
plugins: cov-2.8.1
55
collected 85 items
@@ -82,4 +82,4 @@ data_algebra/yaml.py 95 11 88%
8282
TOTAL 3961 909 77%
8383

8484

85-
============================= 85 passed in 17.96s ==============================
85+
============================== 85 passed in 8.56s ==============================

data_algebra/data_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2035,7 +2035,7 @@ def to_sql_implementation(self, db_model, *, using, temp_id_source):
20352035
db_model=db_model, using=None, temp_id_source=temp_id_source
20362036
)
20372037
# claims to use all columns
2038-
query = sub_query.to_sql(columns=self.columns_used_from_sources(), db_model=db_model)
2038+
query = sub_query.to_sql(columns=self.columns_used_from_sources()[0], db_model=db_model)
20392039
blocks_out_table = None
20402040
if self.record_map.blocks_in is not None:
20412041
query = db_model.blocks_to_row_recs_query(

data_algebra/db_model.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -716,10 +716,10 @@ def row_recs_to_blocks_query(
716716
if not (isnull[i]):
717717
source_col = col[i]
718718
col_sql = (
719-
" WHEN b."
719+
" WHEN CAST(b."
720720
+ self.quote_identifier(result_col)
721-
+ " = "
722-
+ self.quote_literal(source_col)
721+
+ " AS VARCHAR) = "
722+
+ self.quote_string(str(source_col))
723723
+ " THEN a."
724724
+ self.quote_identifier(source_col)
725725
+ "\n"
@@ -773,10 +773,10 @@ def blocks_to_row_recs_query(
773773
clauses = []
774774
for cc in record_spec.control_table_keys:
775775
clauses.append(
776-
" ( "
776+
" ( CAST("
777777
+ self.quote_identifier(cc)
778-
+ " = "
779-
+ self.quote_literal(record_spec.control_table[cc][i])
778+
+ " AS VARCHAR) = "
779+
+ self.quote_string(str(record_spec.control_table[cc][i]))
780780
+ " ) "
781781
)
782782
cstmt = (
20 Bytes
Binary file not shown.

dist/data_algebra-0.4.4.tar.gz

114 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)