Skip to content

Commit

Permalink
Merge pull request #253 from hawkfish/hawkfish-distributive
Browse files Browse the repository at this point in the history
Hawkfish distributive
  • Loading branch information
Mytherin committed Jul 31, 2019
2 parents 6f21c2a + c35a100 commit 7259cab
Show file tree
Hide file tree
Showing 39 changed files with 1,085 additions and 421 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Tab indentation (no size specified)
[*.{cpp,hpp}]
indent_style = tab
12 changes: 12 additions & 0 deletions src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "parser/expression/function_expression.hpp"
#include "parser/parsed_data/alter_table_info.hpp"
#include "parser/parsed_data/create_index_info.hpp"
#include "parser/parsed_data/create_aggregate_function_info.hpp"
#include "parser/parsed_data/create_scalar_function_info.hpp"
#include "parser/parsed_data/create_schema_info.hpp"
#include "parser/parsed_data/create_sequence_info.hpp"
Expand Down Expand Up @@ -115,11 +116,22 @@ TableFunctionCatalogEntry *Catalog::GetTableFunction(Transaction &transaction, F
return schema->GetTableFunction(transaction, expression);
}

void Catalog::CreateAggregateFunction(Transaction &transaction, CreateAggregateFunctionInfo *info) {
auto schema = GetSchema(transaction, info->schema);
schema->CreateAggregateFunction(transaction, info);
}

void Catalog::CreateScalarFunction(Transaction &transaction, CreateScalarFunctionInfo *info) {
auto schema = GetSchema(transaction, info->schema);
schema->CreateScalarFunction(transaction, info);
}

AggregateFunctionCatalogEntry *Catalog::GetAggregateFunction(Transaction &transaction, const string &schema_name,
const string &name, bool if_exists) {
auto schema = GetSchema(transaction, schema_name);
return schema->GetAggregateFunction(transaction, name, if_exists);
}

ScalarFunctionCatalogEntry *Catalog::GetScalarFunction(Transaction &transaction, const string &schema_name,
const string &name) {
auto schema = GetSchema(transaction, schema_name);
Expand Down
32 changes: 31 additions & 1 deletion src/catalog/catalog_entry/schema_catalog_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "catalog/catalog.hpp"
#include "catalog/catalog_entry/index_catalog_entry.hpp"
#include "catalog/catalog_entry/aggregate_function_catalog_entry.hpp"
#include "catalog/catalog_entry/scalar_function_catalog_entry.hpp"
#include "catalog/catalog_entry/sequence_catalog_entry.hpp"
#include "catalog/catalog_entry/table_catalog_entry.hpp"
Expand All @@ -26,7 +27,7 @@ using namespace std;

SchemaCatalogEntry::SchemaCatalogEntry(Catalog *catalog, string name)
: CatalogEntry(CatalogType::SCHEMA, catalog, name), tables(*catalog), indexes(*catalog), table_functions(*catalog),
scalar_functions(*catalog), sequences(*catalog) {
aggregate_functions(*catalog), scalar_functions(*catalog), sequences(*catalog) {
}

void SchemaCatalogEntry::CreateTable(Transaction &transaction, BoundCreateTableInfo *info) {
Expand Down Expand Up @@ -177,6 +178,27 @@ void SchemaCatalogEntry::CreateTableFunction(Transaction &transaction, CreateTab
}
}

void SchemaCatalogEntry::CreateAggregateFunction(Transaction &transaction, CreateAggregateFunctionInfo *info) {
auto aggregate_function = make_unique_base<CatalogEntry, AggregateFunctionCatalogEntry>(catalog, this, info);
unordered_set<CatalogEntry *> dependencies{this};

if (!aggregate_functions.CreateEntry(transaction, info->name, move(aggregate_function), dependencies)) {
if (!info->or_replace) {
throw CatalogException("Aggregate function with name \"%s\" already exists!", info->name.c_str());
} else {
auto aggregate_function = make_unique_base<CatalogEntry, AggregateFunctionCatalogEntry>(catalog, this, info);
// function already exists: replace it
if (!aggregate_functions.DropEntry(transaction, info->name, false)) {
throw CatalogException("CREATE OR REPLACE was specified, but "
"aggregate function could not be dropped!");
}
if (!aggregate_functions.CreateEntry(transaction, info->name, move(aggregate_function), dependencies)) {
throw CatalogException("Error in recreating aggregate function in CREATE OR REPLACE");
}
}
}
}

void SchemaCatalogEntry::CreateScalarFunction(Transaction &transaction, CreateScalarFunctionInfo *info) {
auto scalar_function = make_unique_base<CatalogEntry, ScalarFunctionCatalogEntry>(catalog, this, info);
unordered_set<CatalogEntry *> dependencies{this};
Expand All @@ -198,6 +220,14 @@ void SchemaCatalogEntry::CreateScalarFunction(Transaction &transaction, CreateSc
}
}

AggregateFunctionCatalogEntry *SchemaCatalogEntry::GetAggregateFunction(Transaction &transaction, const string &name, bool if_exists) {
auto entry = aggregate_functions.GetEntry(transaction, name);
if (!entry && !if_exists) {
throw CatalogException("Aggregate Function with name %s does not exist!", name.c_str());
}
return (AggregateFunctionCatalogEntry *)entry;
}

ScalarFunctionCatalogEntry *SchemaCatalogEntry::GetScalarFunction(Transaction &transaction, const string &name) {
auto entry = scalar_functions.GetEntry(transaction, name);
if (!entry) {
Expand Down
24 changes: 4 additions & 20 deletions src/common/enums/expression_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,8 @@ string ExpressionTypeToString(ExpressionType type) {
return "VECTOR";
case ExpressionType::VALUE_SCALAR:
return "SCALAR";
case ExpressionType::AGGREGATE_COUNT:
return "COUNT";
case ExpressionType::AGGREGATE_COUNT_STAR:
return "COUNT_STAR";
case ExpressionType::AGGREGATE_COUNT_DISTINCT:
return "COUNT_DISTINCT";
case ExpressionType::AGGREGATE_SUM:
return "SUM";
case ExpressionType::AGGREGATE_SUM_DISTINCT:
return "SUM_DISTINCT";
case ExpressionType::AGGREGATE_MIN:
return "MIN";
case ExpressionType::AGGREGATE_MAX:
return "MAX";
case ExpressionType::AGGREGATE_AVG:
return "AVG";
case ExpressionType::AGGREGATE_FIRST:
return "FIRST";
case ExpressionType::AGGREGATE_STDDEV_SAMP:
return "AGGREGATE_STDDEV_SAMP";
case ExpressionType::AGGREGATE:
return "AGGREGATE";
case ExpressionType::WINDOW_SUM:
return "SUM";
case ExpressionType::WINDOW_COUNT_STAR:
Expand Down Expand Up @@ -158,6 +140,8 @@ string ExpressionTypeToString(ExpressionType type) {
return "BOUND_COLUMN_REF";
case ExpressionType::BOUND_FUNCTION:
return "BOUND_FUNCTION";
case ExpressionType::BOUND_AGGREGATE:
return "BOUND_AGGREGATE";
case ExpressionType::INVALID:
default:
return "INVALID";
Expand Down
Loading

0 comments on commit 7259cab

Please sign in to comment.