MechanicalRabbit / FunSQL.jl

Julia library for compositional construction of SQL queries
https://mechanicalrabbit.github.io/FunSQL.jl
Other
146 stars 6 forks source link

[BUG] `Define` Not Creating New Column for SQL Query #17

Closed TheCedarPrince closed 2 years ago

TheCedarPrince commented 2 years ago

Describe the bug

I was using the documentation on the Define functionality in building a query that defines a new column. Currently, this function seems to be broken

To Reproduce

  1. Julia Version (i.e. output of julia -v): 1.6.1

  2. Operating system (Mac, Linux, Windows): macOS Catalina 10.15.7

  3. FunSQL Version: FunSQL v0.7.0

  4. Minimum working code example that led to bug:

using LibPQ

const conn = LibPQ.Connection("CREDENTIALS")

const person = SQLTable(:person, columns = [:person_id, :year_of_birth, :location_id])
const location = SQLTable(:location, columns = [:location_id, :city, :state])

q = From(person) |>
           Define(:age => 2021 .- Get.year_of_birth) |>
           Where(Get.age .> 16)

sql = render(q, dialect = :postgresql)
res = LibPQ.execute(conn, sql)
test = DataFrame(res)

Expected Behavior and Actual Behavior

I was expecting a final table that contains a new column named age but after SQL rendering, there is no new column being generated.

julia> print(sql)
SELECT "person_1"."person_id", "person_1"."year_of_birth", "person_1"."location_id",  [...other columns...] 
FROM "synpuf5"."person" AS "person_1" 
WHERE ((2021 - "person_1"."year_of_birth") > 16)     

Stacktrace (If Applicable)

No error available.

Screenshots

N/A

Additional context

N/A

TheCedarPrince commented 2 years ago

@xitology just informed me that this is fixed within the current master branch. I suppose I will leave this open (unless you want to close it sooner) for the upcoming tagged release.