-
Notifications
You must be signed in to change notification settings - Fork 28
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
feat: data frame with lazy relation AltrepDataFrameRelation
#960
Open
Antonov548
wants to merge
18
commits into
duckdb:main
Choose a base branch
from
Antonov548:feat/altrep-relation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6fa7109
feat: add `AltrepDataFrameRelation` class
Antonov548 c59db7e
add `rel_project2`
Antonov548 65e4a64
stop if no expressions
Antonov548 d3a250e
remove `as.data.frame`
Antonov548 45ae5e6
add `rel_filter2`
Antonov548 7e3bdb8
fix: remove `as.data.frame`
Antonov548 ca1ac17
Maybe this -- but doesn't work yet
krlmlr af84bd4
Strict
krlmlr eddf816
add `rapi_rel_from_any_df`
Antonov548 889af85
use `AltrepDataFrameRelation`
Antonov548 32a0eb8
add `EXTENSION_RELATION` type
Antonov548 5a89610
change `rapi_rel_to_altrep` to handle df
Antonov548 2a0c344
add connection
Antonov548 4d8b847
add rapi_rel_to_altrep2
Antonov548 dc1e31e
Throw exception
krlmlr 950f568
Catching exception, but it occurs elsewhere
krlmlr 43220c8
relation rebuild
Antonov548 bb46c8c
runtime_error
krlmlr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "altrepdataframe_relation.hpp" | ||
|
||
#include "R_ext/Random.h" | ||
|
||
namespace duckdb { | ||
|
||
AltrepDataFrameRelation::AltrepDataFrameRelation(duckdb::shared_ptr<Relation> p, cpp11::sexp df, duckdb::conn_eptr_t con, duckdb::shared_ptr<AltrepRelationWrapper> altrep) | ||
: Relation(p->context, RelationType::EXTENSION_RELATION) | ||
, altrep(std::move(altrep)) | ||
, dataframe(df) | ||
, connection(std::move(con)) | ||
, parent(std::move(p)) { | ||
TryBindRelation(columns); | ||
} | ||
|
||
const vector<ColumnDefinition> &AltrepDataFrameRelation::Columns() { | ||
return columns; | ||
} | ||
|
||
string AltrepDataFrameRelation::ToString(idx_t depth) { | ||
return GetParent().ToString(depth); | ||
} | ||
|
||
bool AltrepDataFrameRelation::IsReadOnly() { | ||
return GetParent().IsReadOnly(); | ||
} | ||
|
||
unique_ptr<QueryNode> AltrepDataFrameRelation::GetQueryNode() { | ||
return GetParent().GetQueryNode(); | ||
} | ||
|
||
Relation& AltrepDataFrameRelation::GetParent() { | ||
if (altrep->HasQueryResult()) { | ||
// here context mutex locked | ||
return GetTableRelation(); | ||
} else { | ||
return *parent; | ||
} | ||
} | ||
|
||
void AltrepDataFrameRelation::BuildTableRelation() { | ||
if (!table_function_relation) { | ||
named_parameter_map_t other_params; | ||
other_params["experimental"] = Value::BOOLEAN(false); | ||
auto alias = StringUtil::Format("dataframe_%d_%d", (uintptr_t)(SEXP)dataframe, | ||
(int32_t)(NumericLimits<int32_t>::Maximum() * unif_rand())); | ||
|
||
table_function_relation = connection->conn->TableFunction("r_dataframe_scan", {Value::POINTER((uintptr_t)(SEXP)dataframe)}, other_params)->Alias(alias); | ||
} | ||
} | ||
|
||
Relation& AltrepDataFrameRelation::GetTableRelation() { | ||
if (!table_function_relation) { | ||
throw RebuildRelationException(this); | ||
} | ||
|
||
return *table_function_relation; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "duckdb/main/relation.hpp" | ||
#include "rapi.hpp" | ||
#include "reltoaltrep.hpp" | ||
#include <exception> | ||
|
||
namespace duckdb { | ||
|
||
class AltrepDataFrameRelation final : public Relation { | ||
public: | ||
AltrepDataFrameRelation(duckdb::shared_ptr<Relation> p, cpp11::sexp df, duckdb::conn_eptr_t con, duckdb::shared_ptr<AltrepRelationWrapper> altrep); | ||
|
||
shared_ptr<Relation> table_function_relation; | ||
cpp11::sexp dataframe; | ||
duckdb::conn_eptr_t connection; | ||
duckdb::shared_ptr<AltrepRelationWrapper> altrep; | ||
duckdb::shared_ptr<Relation> parent; | ||
vector<ColumnDefinition> columns; | ||
public: | ||
unique_ptr<QueryNode> GetQueryNode() override; | ||
|
||
const vector<ColumnDefinition> &Columns() override; | ||
string ToString(idx_t depth) override; | ||
bool IsReadOnly() override; | ||
|
||
void BuildTableRelation(); | ||
|
||
private: | ||
Relation& GetTableRelation(); | ||
|
||
Relation& GetParent(); | ||
}; | ||
|
||
class RebuildRelationException : public std::runtime_error { | ||
public: | ||
RebuildRelationException(AltrepDataFrameRelation* target_) : std::runtime_error("RebuildRelationException"), target(target_) { | ||
} | ||
|
||
public: | ||
AltrepDataFrameRelation* target; | ||
}; | ||
|
||
} // namespace duckdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change? Can this still be
parent->...()
?