Skip to content

Commit db53773

Browse files
committed
90%??
1 parent 707497d commit db53773

File tree

3 files changed

+7
-53
lines changed

3 files changed

+7
-53
lines changed

src/TidierDB.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function finalize_query(sqlquery::SQLQuery)
178178
"SELECT SELECT SELECT " => "SELECT ", "PARTITION BY GROUP BY" => "PARTITION BY", "GROUP BY GROUP BY" => "GROUP BY", "HAVING HAVING" => "HAVING",
179179
r"var\"(.*?)\"" => s"\1", r"\"\\\$" => "\"\$", "WHERE \"" => "WHERE ", "WHERE \"NOT" => "WHERE NOT", "%')\"" =>"%\")", "NULL)\"" => "NULL)",
180180
"NULL))\"" => "NULL))", r"(?i)INTERVAL(\d+)([a-zA-Z]+)" => s"INTERVAL \1 \2", "SELECT SUMMARIZE " => "SUMMARIZE ", "\"(__(" => "(", ")__(\"" => ")"
181-
, "***\"" => " ", "***" => " ")
181+
, "***\"" => " ", "***" => " ", "WHERE WHERE " => "WHERE ")
182182
complete_query = replace(complete_query, ", AS " => " AS ", "OR \"" => "OR ")
183183
if current_sql_mode[] == postgres() || current_sql_mode[] == duckdb() || current_sql_mode[] == mysql() || current_sql_mode[] == mssql() || current_sql_mode[] == clickhouse() || current_sql_mode[] == athena() || current_sql_mode[] == gbq() || current_sql_mode[] == oracle() || current_sql_mode[] == snowflake() || current_sql_mode[] == databricks()
184184
complete_query = replace(complete_query, "\"" => "'", "==" => "=")
@@ -219,7 +219,7 @@ function get_table_metadata(conn::Union{DuckDB.DB, DuckDB.Connection}, table_nam
219219
else
220220
table_name = table_name
221221
end
222-
222+
223223
table_name = occursin("-", table_name) ? replace(table_name, "-" => "_") : table_name
224224

225225
result[!, :table_name] .= table_name

src/slices_sq.jl

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,8 @@ macro slice_min(sqlquery, column, n=1)
3838
#rank_clause = "RANK() OVER (ORDER BY " * $(string(column)) *" ASC) AS rank_col"
3939
partition_by_clause = !isempty(sq.groupBy) && !sq.is_aggregated ? "PARTITION BY " * sq.groupBy : ""
4040
# partition_by_clause = isempty(sq.groupBy) && !sq.is_aggregated ? "PARTITION BY " * most_recent_groupBy : ""
41-
if isempty(sq.groupBy) && !sq.is_aggregated
42-
for cte in reverse(sq.ctes)
43-
if !isempty(cte.groupBy)
44-
most_recent_groupBy = cte.groupBy
45-
# println(most_recent_groupBy)
46-
partition_by_clause = "PARTITION BY " * most_recent_groupBy
47-
48-
break
49-
#else
50-
end
51-
end
52-
# partition_by_clause = "PARTITION BY " * most_recent_groupBy
53-
else
54-
nothing
55-
end
56-
if !isempty(partition_by_clause)
57-
sq.groupBy = ""
58-
end
41+
42+
if !isempty(partition_by_clause) sq.groupBy = ""; end
5943

6044
# Update rank_clause to correctly order by column in ASCENDING order for slice_min
6145
rank_clause = "RANK() OVER (" * partition_by_clause * " ORDER BY " * $(string(column)) * " ASC) AS rank_col"
@@ -124,24 +108,8 @@ macro slice_max(sqlquery, column, n=1)
124108
sq.cte_count += 1
125109
partition_by_clause = !isempty(sq.groupBy) && !sq.is_aggregated ? "PARTITION BY " * sq.groupBy : ""
126110
# partition_by_clause = isempty(sq.groupBy) && !sq.is_aggregated ? "PARTITION BY " * most_recent_groupBy : ""
127-
if isempty(sq.groupBy) && !sq.is_aggregated
128-
for cte in reverse(sq.ctes)
129-
if !isempty(cte.groupBy)
130-
most_recent_groupBy = cte.groupBy
131-
# println(most_recent_groupBy)
132-
partition_by_clause = "PARTITION BY " * most_recent_groupBy
133-
134-
break
135-
#else
136-
end
137-
end
138-
# partition_by_clause = "PARTITION BY " * most_recent_groupBy
139-
else
140-
nothing
141-
end
142-
if !isempty(partition_by_clause)
143-
sq.groupBy = ""
144-
end
111+
112+
if !isempty(partition_by_clause) sq.groupBy = ""; end
145113

146114
# Update rank_clause to correctly order by column in ASCENDING order for slice_min
147115
rank_clause = "RANK() OVER (" * partition_by_clause * " ORDER BY " * $(string(column)) * " DESC) AS rank_col"

test/comp_tests.jl

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@
260260
@test all(isequal.(Array(TDF_3), Array(TDB_3)))
261261
@test all(isequal.(Array(TDF_4), Array(TDB_4)))
262262
@test all(isequal.(Array(TDF_5), Array(TDB_5)))
263+
@test !isempty(@chain DB.t(test_db) DB.@mutate(test2 = dmy("06-12-2023")) DB.@collect)
263264
end
264265
@testset "Distinct" begin
265266
query = DB.@chain DB.t(test_db) DB.@mutate(value = value *2) DB.@filter(value > 5)
@@ -294,20 +295,5 @@
294295
@test all(isequal.(Array(TDB_3), Array(TDB_3_)))
295296
end
296297

297-
@testset "Code coverage misc" begin
298-
@test !isempty(@chain DB.t(test_db) begin
299-
DB.@mutate(aa = MAP(ARRAY["value", "percent"], ARRAY[value, percent]))
300-
DB.@mutate(aaa = aa[percent])
301-
DB.@head(6)
302-
# @aside DB.@show_query _
303-
DB.@collect
304-
end)
305-
test = @chain DB.t(test_db) DB.@summarize(mean = mean(value) * 4)
306-
@test !isempty(@eval @chain DB.t(test_db) DB.@mutate(new = $test * value) DB.@collect)
307-
308-
@test !isempty(@chain DB.t(test_db) DB.@mutate(test2 = dmy("06-12-2023")) DB.@collect)
309-
310-
end
311-
312298

313299

0 commit comments

Comments
 (0)