Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
samansmink committed Jun 7, 2024
1 parent 048df0a commit ab9e7f1
Show file tree
Hide file tree
Showing 19 changed files with 546 additions and 533 deletions.
13 changes: 7 additions & 6 deletions src/include/storage/uc_catalog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,29 @@ namespace duckdb {
class UCSchemaEntry;

struct UCCredentials {
string endpoint;
string token;
string endpoint;
string token;

// Not really part of the credentials, but required to query s3 tables
string aws_region;
};

class UCClearCacheFunction : public TableFunction {
public:
UCClearCacheFunction();
UCClearCacheFunction();

static void ClearCacheOnSetting(ClientContext &context, SetScope scope, Value &parameter);
static void ClearCacheOnSetting(ClientContext &context, SetScope scope, Value &parameter);
};

class UCCatalog : public Catalog {
public:
explicit UCCatalog(AttachedDatabase &db_p, const string &internal_name, AccessMode access_mode, UCCredentials credentials);
explicit UCCatalog(AttachedDatabase &db_p, const string &internal_name, AccessMode access_mode,
UCCredentials credentials);
~UCCatalog();

string internal_name;
AccessMode access_mode;
UCCredentials credentials;
UCCredentials credentials;

public:
void Initialize(bool load_builtin) override;
Expand Down
5 changes: 3 additions & 2 deletions src/include/storage/uc_schema_entry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class UCTransaction;
class UCSchemaEntry : public SchemaCatalogEntry {
public:
UCSchemaEntry(Catalog &catalog, CreateSchemaInfo &info);
~UCSchemaEntry() override;
~UCSchemaEntry() override;

unique_ptr<UCAPISchema> schema_data;

unique_ptr<UCAPISchema> schema_data;
public:
optional_ptr<CatalogEntry> CreateTable(CatalogTransaction transaction, BoundCreateTableInfo &info) override;
optional_ptr<CatalogEntry> CreateFunction(CatalogTransaction transaction, CreateFunctionInfo &info) override;
Expand Down
3 changes: 2 additions & 1 deletion src/include/storage/uc_table_entry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class UCTableEntry : public TableCatalogEntry {
UCTableEntry(Catalog &catalog, SchemaCatalogEntry &schema, CreateTableInfo &info);
UCTableEntry(Catalog &catalog, SchemaCatalogEntry &schema, UCTableInfo &info);

unique_ptr<UCAPITable> table_data;
unique_ptr<UCAPITable> table_data;

public:
unique_ptr<BaseStatistics> GetStatistics(ClientContext &context, column_t column_id) override;

Expand Down
5 changes: 2 additions & 3 deletions src/include/storage/uc_table_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class UCTableSet : public UCInSchemaSet {
optional_ptr<CatalogEntry> CreateTable(ClientContext &context, BoundCreateTableInfo &info);

static unique_ptr<UCTableInfo> GetTableInfo(ClientContext &context, UCSchemaEntry &schema,
const string &table_name);
const string &table_name);
optional_ptr<CatalogEntry> RefreshTable(ClientContext &context, const string &table_name);

void AlterTable(ClientContext &context, AlterTableInfo &info);
Expand All @@ -37,8 +37,7 @@ class UCTableSet : public UCInSchemaSet {
void AlterTable(ClientContext &context, AddColumnInfo &info);
void AlterTable(ClientContext &context, RemoveColumnInfo &info);

static void AddColumn(ClientContext &context, UCResult &result, UCTableInfo &table_info,
idx_t column_offset = 0);
static void AddColumn(ClientContext &context, UCResult &result, UCTableInfo &table_info, idx_t column_offset = 0);
};

} // namespace duckdb
6 changes: 3 additions & 3 deletions src/include/storage/uc_transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ class UCTransaction : public Transaction {
void Commit();
void Rollback();

// UCConnection &GetConnection();
// unique_ptr<UCResult> Query(const string &query);
// UCConnection &GetConnection();
// unique_ptr<UCResult> Query(const string &query);
static UCTransaction &Get(ClientContext &context, Catalog &catalog);
AccessMode GetAccessMode() const {
return access_mode;
}

private:
// UCConnection connection;
// UCConnection connection;
UCTransactionState transaction_state;
AccessMode access_mode;
};
Expand Down
50 changes: 25 additions & 25 deletions src/include/uc_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,46 @@ namespace duckdb {
struct UCCredentials;

struct UCAPIColumnDefinition {
string name;
string type_text;
idx_t precision;
idx_t scale;
idx_t position;
string name;
string type_text;
idx_t precision;
idx_t scale;
idx_t position;
};

struct UCAPITable {
string table_id;
string table_id;

string name;
string catalog_name;
string schema_name;
string table_type;
string data_source_format;
string name;
string catalog_name;
string schema_name;
string table_type;
string data_source_format;

string storage_location;
string delta_last_commit_timestamp;
string delta_last_update_version;
string storage_location;
string delta_last_commit_timestamp;
string delta_last_update_version;

vector<UCAPIColumnDefinition> columns;
vector<UCAPIColumnDefinition> columns;
};

struct UCAPISchema {
string schema_name;
string catalog_name;
string schema_name;
string catalog_name;
};

struct UCAPITableCredentials {
string key_id;
string secret;
string session_token;
string key_id;
string secret;
string session_token;
};

class UCAPI {
public:
static UCAPITableCredentials GetTableCredentials(const string &table_id, UCCredentials credentials);
static vector<string> GetCatalogs(const string &catalog, UCCredentials credentials);
static vector<UCAPITable> GetTables(const string &catalog, const string &schema, UCCredentials credentials);
static vector<UCAPISchema> GetSchemas(const string &catalog, UCCredentials credentials);
static vector<UCAPITable> GetTablesInSchema(const string &catalog, const string &schema, UCCredentials credentials);
static UCAPITableCredentials GetTableCredentials(const string &table_id, UCCredentials credentials);
static vector<string> GetCatalogs(const string &catalog, UCCredentials credentials);
static vector<UCAPITable> GetTables(const string &catalog, const string &schema, UCCredentials credentials);
static vector<UCAPISchema> GetSchemas(const string &catalog, UCCredentials credentials);
static vector<UCAPITable> GetTablesInSchema(const string &catalog, const string &schema, UCCredentials credentials);
};
} // namespace duckdb
6 changes: 3 additions & 3 deletions src/include/uc_catalog_extension.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace duckdb {

class UcCatalogExtension : public Extension {
public:
void Load(DuckDB &db) override;
std::string Name() override;
std::string Version() const override;
void Load(DuckDB &db) override;
std::string Name() override;
std::string Version() const override;
};

} // namespace duckdb
30 changes: 15 additions & 15 deletions src/storage/uc_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@

namespace duckdb {

UCCatalog::UCCatalog(AttachedDatabase &db_p, const string &internal_name, AccessMode access_mode, UCCredentials credentials)
: Catalog(db_p), internal_name(internal_name),access_mode(access_mode), credentials(std::move(credentials)), schemas(*this) {
UCCatalog::UCCatalog(AttachedDatabase &db_p, const string &internal_name, AccessMode access_mode,
UCCredentials credentials)
: Catalog(db_p), internal_name(internal_name), access_mode(access_mode), credentials(std::move(credentials)),
schemas(*this) {
}

UCCatalog::~UCCatalog() = default;

void UCCatalog::Initialize(bool load_builtin) {

}

optional_ptr<CatalogEntry> UCCatalog::CreateSchema(CatalogTransaction transaction, CreateSchemaInfo &info) {
Expand All @@ -39,8 +40,7 @@ void UCCatalog::ScanSchemas(ClientContext &context, std::function<void(SchemaCat
}

optional_ptr<SchemaCatalogEntry> UCCatalog::GetSchema(CatalogTransaction transaction, const string &schema_name,
OnEntryNotFound if_not_found,
QueryErrorContext error_context) {
OnEntryNotFound if_not_found, QueryErrorContext error_context) {
if (schema_name == DEFAULT_SCHEMA) {
if (default_schema.empty()) {
throw InvalidInputException("Attempting to fetch the default schema - but no database was "
Expand Down Expand Up @@ -77,24 +77,24 @@ void UCCatalog::ClearCache() {
}

unique_ptr<PhysicalOperator> UCCatalog::PlanInsert(ClientContext &context, LogicalInsert &op,
unique_ptr<PhysicalOperator> plan) {
throw NotImplementedException("UCCatalog PlanInsert");
unique_ptr<PhysicalOperator> plan) {
throw NotImplementedException("UCCatalog PlanInsert");
}
unique_ptr<PhysicalOperator> UCCatalog::PlanCreateTableAs(ClientContext &context, LogicalCreateTable &op,
unique_ptr<PhysicalOperator> plan) {
throw NotImplementedException("UCCatalog PlanCreateTableAs");
unique_ptr<PhysicalOperator> plan) {
throw NotImplementedException("UCCatalog PlanCreateTableAs");
}
unique_ptr<PhysicalOperator> UCCatalog::PlanDelete(ClientContext &context, LogicalDelete &op,
unique_ptr<PhysicalOperator> plan) {
throw NotImplementedException("UCCatalog PlanDelete");
unique_ptr<PhysicalOperator> plan) {
throw NotImplementedException("UCCatalog PlanDelete");
}
unique_ptr<PhysicalOperator> UCCatalog::PlanUpdate(ClientContext &context, LogicalUpdate &op,
unique_ptr<PhysicalOperator> plan) {
throw NotImplementedException("UCCatalog PlanUpdate");
unique_ptr<PhysicalOperator> plan) {
throw NotImplementedException("UCCatalog PlanUpdate");
}
unique_ptr<LogicalOperator> UCCatalog::BindCreateIndex(Binder &binder, CreateStatement &stmt, TableCatalogEntry &table,
unique_ptr<LogicalOperator> plan) {
throw NotImplementedException("UCCatalog BindCreateIndex");
unique_ptr<LogicalOperator> plan) {
throw NotImplementedException("UCCatalog BindCreateIndex");
}

} // namespace duckdb
2 changes: 1 addition & 1 deletion src/storage/uc_catalog_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ optional_ptr<CatalogEntry> UCCatalogSet::GetEntry(ClientContext &context, const
}

void UCCatalogSet::DropEntry(ClientContext &context, DropInfo &info) {
throw NotImplementedException("UCCatalogSet::DropEntry");
throw NotImplementedException("UCCatalogSet::DropEntry");
}

void UCCatalogSet::EraseEntryInternal(const string &name) {
Expand Down
3 changes: 1 addition & 2 deletions src/storage/uc_clear_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ void UCClearCacheFunction::ClearCacheOnSetting(ClientContext &context, SetScope
ClearUCCaches(context);
}

UCClearCacheFunction::UCClearCacheFunction()
: TableFunction("uc_clear_cache", {}, ClearCacheFunction, ClearCacheBind) {
UCClearCacheFunction::UCClearCacheFunction() : TableFunction("uc_clear_cache", {}, ClearCacheFunction, ClearCacheBind) {
}
} // namespace duckdb
21 changes: 10 additions & 11 deletions src/storage/uc_schema_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ UCSchemaEntry::UCSchemaEntry(Catalog &catalog, CreateSchemaInfo &info)
: SchemaCatalogEntry(catalog, info), tables(*this) {
}

UCSchemaEntry::~UCSchemaEntry(){
UCSchemaEntry::~UCSchemaEntry() {
}

UCTransaction &GetUCTransaction(CatalogTransaction transaction) {
Expand Down Expand Up @@ -51,7 +51,7 @@ void UCUnqualifyColumnRef(ParsedExpression &expr) {
}

optional_ptr<CatalogEntry> UCSchemaEntry::CreateIndex(CatalogTransaction transaction, CreateIndexInfo &info,
TableCatalogEntry &table) {
TableCatalogEntry &table) {
throw NotImplementedException("CreateIndex");
}

Expand All @@ -71,11 +71,11 @@ optional_ptr<CatalogEntry> UCSchemaEntry::CreateView(CatalogTransaction transact
if (info.on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT) {
return current_entry;
}
throw NotImplementedException("REPLACE ON CONFLICT in CreateView");
throw NotImplementedException("REPLACE ON CONFLICT in CreateView");
}
}
auto &uc_transaction = GetUCTransaction(transaction);
// uc_transaction.Query(GetUCCreateView(info));
// uc_transaction.Query(GetUCCreateView(info));
return tables.RefreshTable(transaction.GetContext(), info.view_name);
}

Expand All @@ -88,22 +88,21 @@ optional_ptr<CatalogEntry> UCSchemaEntry::CreateSequence(CatalogTransaction tran
}

optional_ptr<CatalogEntry> UCSchemaEntry::CreateTableFunction(CatalogTransaction transaction,
CreateTableFunctionInfo &info) {
CreateTableFunctionInfo &info) {
throw BinderException("UC databases do not support creating table functions");
}

optional_ptr<CatalogEntry> UCSchemaEntry::CreateCopyFunction(CatalogTransaction transaction,
CreateCopyFunctionInfo &info) {
CreateCopyFunctionInfo &info) {
throw BinderException("UC databases do not support creating copy functions");
}

optional_ptr<CatalogEntry> UCSchemaEntry::CreatePragmaFunction(CatalogTransaction transaction,
CreatePragmaFunctionInfo &info) {
CreatePragmaFunctionInfo &info) {
throw BinderException("UC databases do not support creating pragma functions");
}

optional_ptr<CatalogEntry> UCSchemaEntry::CreateCollation(CatalogTransaction transaction,
CreateCollationInfo &info) {
optional_ptr<CatalogEntry> UCSchemaEntry::CreateCollation(CatalogTransaction transaction, CreateCollationInfo &info) {
throw BinderException("UC databases do not support creating collations");
}

Expand All @@ -127,7 +126,7 @@ bool CatalogTypeIsSupported(CatalogType type) {
}

void UCSchemaEntry::Scan(ClientContext &context, CatalogType type,
const std::function<void(CatalogEntry &)> &callback) {
const std::function<void(CatalogEntry &)> &callback) {
if (!CatalogTypeIsSupported(type)) {
return;
}
Expand All @@ -142,7 +141,7 @@ void UCSchemaEntry::DropEntry(ClientContext &context, DropInfo &info) {
}

optional_ptr<CatalogEntry> UCSchemaEntry::GetEntry(CatalogTransaction transaction, CatalogType type,
const string &name) {
const string &name) {
if (!CatalogTypeIsSupported(type)) {
return nullptr;
}
Expand Down
30 changes: 15 additions & 15 deletions src/storage/uc_schema_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ namespace duckdb {
UCSchemaSet::UCSchemaSet(Catalog &catalog) : UCCatalogSet(catalog) {
}

static bool IsInternalTable(const string & catalog, const string &schema) {
if (schema == "information_schema") {
return true;
}
return false;
static bool IsInternalTable(const string &catalog, const string &schema) {
if (schema == "information_schema") {
return true;
}
return false;
}
void UCSchemaSet::LoadEntries(ClientContext &context) {

auto &uc_catalog = catalog.Cast<UCCatalog>();
auto tables = UCAPI::GetSchemas(catalog.GetName(), uc_catalog.credentials);
auto &uc_catalog = catalog.Cast<UCCatalog>();
auto tables = UCAPI::GetSchemas(catalog.GetName(), uc_catalog.credentials);

for (const auto& schema: tables) {
CreateSchemaInfo info;
info.schema = schema.schema_name;
info.internal = IsInternalTable(schema.catalog_name, schema.schema_name);
auto schema_entry = make_uniq<UCSchemaEntry>(catalog, info);
schema_entry->schema_data = make_uniq<UCAPISchema>(schema);
CreateEntry(std::move(schema_entry));
}
for (const auto &schema : tables) {
CreateSchemaInfo info;
info.schema = schema.schema_name;
info.internal = IsInternalTable(schema.catalog_name, schema.schema_name);
auto schema_entry = make_uniq<UCSchemaEntry>(catalog, info);
schema_entry->schema_data = make_uniq<UCAPISchema>(schema);
CreateEntry(std::move(schema_entry));
}
}

optional_ptr<CatalogEntry> UCSchemaSet::CreateSchema(ClientContext &context, CreateSchemaInfo &info) {
Expand Down
Loading

0 comments on commit ab9e7f1

Please sign in to comment.