Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functions to substrait extension #1

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft

Add functions to substrait extension #1

wants to merge 26 commits into from

Conversation

drin
Copy link
Owner

@drin drin commented Mar 23, 2024

This PR adds functions translate_mohair and execute_mohair to add more ways to interact with substrait:

  • translate_mohair converts the substrait plan to a DuckDB logical plan (duckdb::LogicalOperator), optimizes it, then converts it to a DuckDB physical plan (duckdb::PhysicalOperator).
  • execute_mohair calls translate_mohair, then executes the physical plan. This is potentially different execution path from from_substrait which goes directly to duckdb::Relation and executes that (which I believe does not go through the optimizer).

More functionality to come.

drin added 23 commits March 22, 2024 20:49
This reorganization is partially for my own benefit (readability and
internalizing the structure), though I did add some improvements such as
how substrait types are used in switch statements.

The other motivation for this reorganization is so that I can have a
better overall structure/framework for also "translating" a substrait
plan to a logical duckdb plan (instead of only a physical duckdb plan).

In this code, I use "translation" to refer to a _lowering_ from a
logical substrait plan to a physical duckdb plan.
In this code, which is an initial placeholder, I use "transpilation" to
refer to a translation (general sense of the word) from a logical
substrait plan to a logical duckdb plan. Thus, going forward I will be
using "translation" to refer to a lowering (e.g. logical to physical)
and "transpilation" to refer to a transformation to another language
(dialect?) of the same level (e.g. logical to logical).
This worked with the updated code for translation, but I have not yet
begun to work on code for transpilation, so this is certain to not work
at the moment (though, deleting everything transpilation related should
get it to work).
NOTE: these sources can potentially be dropped
NOTE: these can potentially be dropped in the future now that there's a
clear transformation path from duckdb::Relation to
duckdb::LogicalOperator
updated some types and changed TranspilePlanMessage to call
TranslateMessage then transform duckdb::Relation into
duckdb::LogicalOperator.

This makes the layers of abstraction I expected
("translation", "transpilation") basically wrong, but I will update that
when I get more clarity on it.
I still have to figure out how to execute a physical plan, but otherwise
I have updated to convert from duckdb::Relation to
duckdb::LogicalOperator, optimize duckdb::LogicalOperator, then create a
physical plan (duckdb::PhysicalOperator) from a logical plan
(duckdb::LogicalOperator).

Most of the above is to be sure that I'm correctly doing the
transformations, etc. and they will be migrated once I better figure out
the various interfaces to extensions (rather than just a TableFunction).
Since they aren't necessary at the moment
Now that the transpilation path goes from Relation -> LogicalOperator,
the transpilation functions are unnecessary.
This unused function caused linking issues, and it won't be needed in
the future
While transpilation (via transforming Relation -> LogicalOperator) was
straightforward, it was necessary to figure out how execution of the
logical plan is done. These changes include optimization of the logical
plan, transformation from logical to physical, and execution of the
physical plan.
This probably isn't necessary but I am making it just to make it
this way, plans.hpp and plans.cpp can provide a structure for
engine-agnostic hooks (though it doesn't seem very good right now)
this is because EnginePlan has been changed to SystemPlan and engine
specific code has been removed.
TableFunctions have been renamed to reflect a better understanding of
the process. Currently the added functions are "exec_mohair" and
"translate_mohair" where "mohair" is a reference to substrait plans as a
cross-engine plan representation
@drin drin self-assigned this Mar 23, 2024
I apparently merged in changes to substrait extension that depend on
duckdb v0.10.1. Instead of reverting the changes, I decided to update
duckdb dependency
In my branch of duckdb (coop-decomp) I added an `ExplainSubstrait`
function for the python API to show the physical plan generated from a
substrait plan (instead of just a single TableFunction node)
Debian 20240408-slim seems to have cmake 3.25.1, so I downgraded to that
version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant