-
Notifications
You must be signed in to change notification settings - Fork 47
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 PostgresViewEntry #183
Draft
Tishj
wants to merge
15
commits into
duckdb:main
Choose a base branch
from
Tishj:add_view_entry
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.
+743
−106
Draft
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d9b3c13
add detection for the relkind, create a PostgresViewInfo and a Postgr…
Tishj 67a2c87
format
Tishj 28e2fd8
add a view to the 'create-postgres-tables.sh' script, adjust test
Tishj 84511fb
override the destructor
Tishj 8894e28
updated test
Tishj 09269a6
initial tests for views
Tishj 8faa76f
more view tests
Tishj 326e6f6
fix issue caused by adding the relkind to the projection
Tishj 2be2eda
revert changes to duckdb
Tishj 392ad8e
get the view definition, use it to make a select statement
Tishj 1c1a0b6
Merge remote-tracking branch 'upstream/main' into add_view_entry
Tishj 27ca896
rename from v1, suspecting naming conflict between tests
Tishj 02ea183
Merge remote-tracking branch 'upstream/main' into add_view_entry
Tishj 191779f
Merge remote-tracking branch 'upstream/main' into add_view_entry
Tishj 91462b1
replace the '?column?' postgres names to avoid a binder exception
Tishj 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//===----------------------------------------------------------------------===// | ||
// DuckDB | ||
// | ||
// storage/postgres_create_info.hpp | ||
// | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp" | ||
#include "duckdb/parser/parsed_data/create_table_info.hpp" | ||
#include "postgres_utils.hpp" | ||
|
||
namespace duckdb { | ||
|
||
struct PostgresCreateInfo { | ||
public: | ||
PostgresCreateInfo() { | ||
} | ||
virtual ~PostgresCreateInfo() { | ||
} | ||
|
||
public: | ||
virtual CreateInfo &GetCreateInfo() = 0; | ||
virtual const string &GetName() const = 0; | ||
virtual void AddColumn(ColumnDefinition def, PostgresType pg_type, const string &pg_name) = 0; | ||
virtual void GetColumnNamesAndTypes(vector<string> &names, vector<LogicalType> &types) = 0; | ||
|
||
public: | ||
template <class TARGET> | ||
TARGET &Cast() { | ||
D_ASSERT(dynamic_cast<TARGET *>(this)); | ||
return reinterpret_cast<TARGET &>(*this); | ||
} | ||
|
||
template <class TARGET> | ||
const TARGET &Cast() const { | ||
D_ASSERT(dynamic_cast<const TARGET *>(this)); | ||
return reinterpret_cast<const TARGET &>(*this); | ||
} | ||
|
||
public: | ||
idx_t approx_num_pages = 0; | ||
vector<PostgresType> postgres_types; | ||
vector<string> postgres_names; | ||
}; | ||
|
||
} // 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
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,80 @@ | ||
//===----------------------------------------------------------------------===// | ||
// DuckDB | ||
// | ||
// storage/postgres_view_entry.hpp | ||
// | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include "duckdb/catalog/catalog_entry/view_catalog_entry.hpp" | ||
#include "duckdb/parser/parsed_data/create_view_info.hpp" | ||
#include "storage/postgres_create_info.hpp" | ||
|
||
namespace duckdb { | ||
|
||
struct PostgresViewInfo : public PostgresCreateInfo { | ||
public: | ||
PostgresViewInfo(const string &select_stmt) { | ||
create_info = make_uniq<CreateViewInfo>(); | ||
create_info->query = CreateViewInfo::ParseSelect(select_stmt); | ||
// create_info->columns.SetAllowDuplicates(true); | ||
} | ||
PostgresViewInfo(const string &schema, const string &view, const string &select_stmt) { | ||
create_info = make_uniq<CreateViewInfo>(string(), schema, view); | ||
create_info->query = CreateViewInfo::ParseSelect(select_stmt); | ||
// create_info->columns.SetAllowDuplicates(true); | ||
} | ||
PostgresViewInfo(const SchemaCatalogEntry &schema, const string &view, const string &select_stmt) { | ||
create_info = make_uniq<CreateViewInfo>((SchemaCatalogEntry &)schema, view); | ||
create_info->query = CreateViewInfo::ParseSelect(select_stmt); | ||
// create_info->columns.SetAllowDuplicates(true); | ||
} | ||
~PostgresViewInfo() override { | ||
} | ||
|
||
public: | ||
const string &GetName() const override { | ||
return create_info->view_name; | ||
} | ||
|
||
CreateInfo &GetCreateInfo() override { | ||
return *create_info; | ||
} | ||
|
||
void AddColumn(ColumnDefinition def, PostgresType pg_type, const string &pg_name) override { | ||
postgres_types.push_back(std::move(pg_type)); | ||
D_ASSERT(!pg_name.empty()); | ||
postgres_names.push_back(pg_name); | ||
create_info->types.push_back(def.Type()); | ||
create_info->names.push_back(def.Name()); | ||
} | ||
|
||
void GetColumnNamesAndTypes(vector<string> &names, vector<LogicalType> &types) override { | ||
names = create_info->names; | ||
types = create_info->types; | ||
} | ||
|
||
public: | ||
unique_ptr<CreateViewInfo> create_info; | ||
}; | ||
|
||
class PostgresViewEntry : public ViewCatalogEntry { | ||
public: | ||
PostgresViewEntry(Catalog &catalog, SchemaCatalogEntry &schema, CreateViewInfo &info); | ||
PostgresViewEntry(Catalog &catalog, SchemaCatalogEntry &schema, PostgresViewInfo &info); | ||
~PostgresViewEntry() override; | ||
|
||
public: | ||
//! Postgres type annotations | ||
vector<PostgresType> postgres_types; | ||
//! Column names as they are within Postgres | ||
//! We track these separately because of case sensitivity - Postgres allows e.g. the columns "ID" and "id" together | ||
//! We would in this case remap them to "ID" and "id_1", while postgres_names store the original names | ||
vector<string> postgres_names; | ||
//! The approximate number of pages a table consumes in Postgres | ||
idx_t approx_num_pages; | ||
}; | ||
|
||
} // 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
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.
I'm not sure about this, the Table has a ColumnsList which provides this option, but no such option exists for views because we don't have a ColumnsList, we instead just store the types+names separately