E.g. duckdb
has tables (relations to be precise) with methods that return a table, to which one can apply a method, which returns a table, to which one can apply a method, which returns a table, etc.
# Total salary of IT in Aug (I think, on mobile, no laptop)
(duckdb.table('employees')
.filter("department = 'IT'")
.join(duckdb.table('emp_salaries')
.filter("year_month = 202408"),
'emp_id')
.aggregate('sum(salary)')
.show()
)
With extra brackets this works (because they are methods).
Now suppose I have a function, e.g. natural_join()
that avoids specification of the join column:
def natural_join(t1, t2):
common = ', '.join(set(t1.columns) & set(t2.columns))
return t1.join(t2, common)
Then I cannot use the same style, but instead need to:
(natural_join(duckdb.table('employees')
.filter("department = 'IT'"),
duckdb.table('emp_salaries')
.filter("year_month = 202408"))
.aggregate('sum(salary)')
.show()
)
My understanding of the proposed syntax is that it allows something closer to the original:
(duckdb.table('employees')
.filter("department = 'IT'")
.natural_join(duckdb.table('emp_salaries')
.filter("year_month = 202408"))
.aggregate('sum(salary)')
.show()
)
While that’s attractive for this use case, object().print()
is not, so I’d like to know how to prevent such use.