Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

Commit

Permalink
Merge 9718a39 into f25ff8d
Browse files Browse the repository at this point in the history
  • Loading branch information
pmenon committed Jan 17, 2018
2 parents f25ff8d + 9718a39 commit 1f9bfff
Show file tree
Hide file tree
Showing 10 changed files with 631 additions and 424 deletions.
137 changes: 67 additions & 70 deletions src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "concurrency/transaction_manager_factory.h"
#include "function/date_functions.h"
#include "function/decimal_functions.h"
#include "function/string_functions.h"
#include "function/old_engine_string_functions.h"
#include "function/timestamp_functions.h"
#include "index/index_factory.h"
#include "storage/storage_manager.h"
Expand Down Expand Up @@ -208,8 +208,8 @@ ResultType Catalog::CreateDatabase(const std::string &database_name,
ResultType Catalog::CreateTable(const std::string &database_name,
const std::string &table_name,
std::unique_ptr<catalog::Schema> schema,
concurrency::TransactionContext *txn, bool is_catalog,
oid_t tuples_per_tilegroup) {
concurrency::TransactionContext *txn,
bool is_catalog, oid_t tuples_per_tilegroup) {
if (txn == nullptr)
throw CatalogException("Do not have transaction to create table " +
table_name);
Expand Down Expand Up @@ -395,13 +395,11 @@ ResultType Catalog::CreateIndex(const std::string &database_name,
return success;
}

ResultType Catalog::CreateIndex(oid_t database_oid, oid_t table_oid,
const std::vector<oid_t> &key_attrs,
const std::string &index_name,
IndexType index_type,
IndexConstraintType index_constraint,
bool unique_keys, concurrency::TransactionContext *txn,
bool is_catalog) {
ResultType Catalog::CreateIndex(
oid_t database_oid, oid_t table_oid, const std::vector<oid_t> &key_attrs,
const std::string &index_name, IndexType index_type,
IndexConstraintType index_constraint, bool unique_keys,
concurrency::TransactionContext *txn, bool is_catalog) {
if (txn == nullptr)
throw CatalogException("Do not have transaction to create index " +
index_name);
Expand Down Expand Up @@ -572,7 +570,8 @@ ResultType Catalog::DropTable(oid_t database_oid, oid_t table_oid,
* @param txn TransactionContext
* @return TransactionContext ResultType(SUCCESS or FAILURE)
*/
ResultType Catalog::DropIndex(oid_t index_oid, concurrency::TransactionContext *txn) {
ResultType Catalog::DropIndex(oid_t index_oid,
concurrency::TransactionContext *txn) {
if (txn == nullptr)
throw CatalogException("Do not have transaction to drop index " +
std::to_string(index_oid));
Expand Down Expand Up @@ -616,7 +615,8 @@ ResultType Catalog::DropIndex(oid_t index_oid, concurrency::TransactionContext *
* throw exception and abort txn if not exists/invisible
* */
storage::Database *Catalog::GetDatabaseWithName(
const std::string &database_name, concurrency::TransactionContext *txn) const {
const std::string &database_name,
concurrency::TransactionContext *txn) const {
PL_ASSERT(txn != nullptr);

// Check in pg_database using txn
Expand All @@ -635,9 +635,9 @@ storage::Database *Catalog::GetDatabaseWithName(
* get it from storage layer using table_oid,
* throw exception and abort txn if not exists/invisible
* */
storage::DataTable *Catalog::GetTableWithName(const std::string &database_name,
const std::string &table_name,
concurrency::TransactionContext *txn) {
storage::DataTable *Catalog::GetTableWithName(
const std::string &database_name, const std::string &table_name,
concurrency::TransactionContext *txn) {
PL_ASSERT(txn != nullptr);

LOG_TRACE("Looking for table %s in database %s", table_name.c_str(),
Expand Down Expand Up @@ -894,87 +894,88 @@ void Catalog::InitializeFunctions() {
"ascii", {type::TypeId::VARCHAR}, type::TypeId::INTEGER,
internal_lang, "Ascii",
function::BuiltInFuncType{OperatorId::Ascii,
function::StringFunctions::_Ascii},
function::OldEngineStringFunctions::Ascii},
txn);
AddBuiltinFunction(
"chr", {type::TypeId::INTEGER}, type::TypeId::VARCHAR, internal_lang,
"Chr",
function::BuiltInFuncType{OperatorId::Chr,
function::OldEngineStringFunctions::Chr},
txn);
AddBuiltinFunction("chr", {type::TypeId::INTEGER}, type::TypeId::VARCHAR,
internal_lang, "Chr",
function::BuiltInFuncType{
OperatorId::Chr, function::StringFunctions::Chr},
txn);
AddBuiltinFunction(
"concat", {type::TypeId::VARCHAR, type::TypeId::VARCHAR},
type::TypeId::VARCHAR, internal_lang, "Concat",
function::BuiltInFuncType{OperatorId::Concat,
function::StringFunctions::Concat},
function::OldEngineStringFunctions::Concat},
txn);
AddBuiltinFunction(
"substr",
{type::TypeId::VARCHAR, type::TypeId::INTEGER, type::TypeId::INTEGER},
type::TypeId::VARCHAR, internal_lang, "Substr",
function::BuiltInFuncType{OperatorId::Substr,
function::StringFunctions::_Substr},
txn);
AddBuiltinFunction(
"char_length", {type::TypeId::VARCHAR}, type::TypeId::INTEGER,
internal_lang, "CharLength",
function::BuiltInFuncType{OperatorId::CharLength,
function::StringFunctions::CharLength},
txn);
AddBuiltinFunction(
"octet_length", {type::TypeId::VARCHAR}, type::TypeId::INTEGER,
internal_lang, "OctetLength",
function::BuiltInFuncType{OperatorId::OctetLength,
function::StringFunctions::OctetLength},
function::OldEngineStringFunctions::Substr},
txn);
AddBuiltinFunction("char_length", {type::TypeId::VARCHAR},
type::TypeId::INTEGER, internal_lang, "CharLength",
function::BuiltInFuncType{
OperatorId::CharLength,
function::OldEngineStringFunctions::CharLength},
txn);
AddBuiltinFunction("octet_length", {type::TypeId::VARCHAR},
type::TypeId::INTEGER, internal_lang, "OctetLength",
function::BuiltInFuncType{
OperatorId::OctetLength,
function::OldEngineStringFunctions::OctetLength},
txn);
AddBuiltinFunction(
"length", {type::TypeId::VARCHAR}, type::TypeId::INTEGER,
internal_lang, "Length",
function::BuiltInFuncType{OperatorId::Length,
function::StringFunctions::_Length},
function::OldEngineStringFunctions::Length},
txn);
AddBuiltinFunction(
"repeat", {type::TypeId::VARCHAR, type::TypeId::INTEGER},
type::TypeId::VARCHAR, internal_lang, "Repeat",
function::BuiltInFuncType{OperatorId::Repeat,
function::StringFunctions::Repeat},
function::OldEngineStringFunctions::Repeat},
txn);
AddBuiltinFunction(
"replace",
{type::TypeId::VARCHAR, type::TypeId::VARCHAR, type::TypeId::VARCHAR},
type::TypeId::VARCHAR, internal_lang, "Replace",
function::BuiltInFuncType{OperatorId::Replace,
function::StringFunctions::Replace},
function::BuiltInFuncType{
OperatorId::Replace, function::OldEngineStringFunctions::Replace},
txn);
AddBuiltinFunction(
"ltrim", {type::TypeId::VARCHAR, type::TypeId::VARCHAR},
type::TypeId::VARCHAR, internal_lang, "LTrim",
function::BuiltInFuncType{OperatorId::LTrim,
function::StringFunctions::_LTrim},
function::OldEngineStringFunctions::LTrim},
txn);
AddBuiltinFunction(
"rtrim", {type::TypeId::VARCHAR, type::TypeId::VARCHAR},
type::TypeId::VARCHAR, internal_lang, "RTrim",
function::BuiltInFuncType{OperatorId::RTrim,
function::StringFunctions::_RTrim},
function::OldEngineStringFunctions::RTrim},
txn);
AddBuiltinFunction(
"btrim", {type::TypeId::VARCHAR, type::TypeId::VARCHAR},
type::TypeId::VARCHAR, internal_lang, "btrim",
function::BuiltInFuncType{OperatorId::BTrim,
function::StringFunctions::_BTrim},
function::OldEngineStringFunctions::BTrim},
txn);
// Trim
AddBuiltinFunction(
"btrim", {type::TypeId::VARCHAR},
type::TypeId::VARCHAR, internal_lang, "trim",
"btrim", {type::TypeId::VARCHAR}, type::TypeId::VARCHAR,
internal_lang, "trim",
function::BuiltInFuncType{OperatorId::Trim,
function::StringFunctions::_Trim},
function::OldEngineStringFunctions::Trim},
txn);
AddBuiltinFunction(
"like", {type::TypeId::VARCHAR, type::TypeId::VARCHAR},
type::TypeId::VARCHAR, internal_lang, "like",
function::BuiltInFuncType{OperatorId::Like,
function::StringFunctions::_Like},
function::OldEngineStringFunctions::Like},
txn);

/**
Expand All @@ -986,9 +987,10 @@ void Catalog::InitializeFunctions() {
function::DecimalFunctions::Sqrt},
txn);
AddBuiltinFunction(
"sqrt", {type::TypeId::SMALLINT}, type::TypeId::DECIMAL, internal_lang,
"Sqrt", function::BuiltInFuncType{OperatorId::Sqrt,
function::DecimalFunctions::Sqrt},
"sqrt", {type::TypeId::SMALLINT}, type::TypeId::DECIMAL,
internal_lang, "Sqrt",
function::BuiltInFuncType{OperatorId::Sqrt,
function::DecimalFunctions::Sqrt},
txn);
AddBuiltinFunction(
"sqrt", {type::TypeId::INTEGER}, type::TypeId::DECIMAL, internal_lang,
Expand Down Expand Up @@ -1048,37 +1050,33 @@ void Catalog::InitializeFunctions() {

AddBuiltinFunction(
"ceil", {type::TypeId::DECIMAL}, type::TypeId::DECIMAL, internal_lang,
"Ceil",
function::BuiltInFuncType{OperatorId::Ceil,
function::DecimalFunctions::_Ceil},
"Ceil", function::BuiltInFuncType{OperatorId::Ceil,
function::DecimalFunctions::_Ceil},
txn);

AddBuiltinFunction(
"ceil", {type::TypeId::TINYINT}, type::TypeId::DECIMAL, internal_lang,
"Ceil",
function::BuiltInFuncType{OperatorId::Ceil,
function::DecimalFunctions::_Ceil},
"Ceil", function::BuiltInFuncType{OperatorId::Ceil,
function::DecimalFunctions::_Ceil},
txn);

AddBuiltinFunction(
"ceil", {type::TypeId::SMALLINT}, type::TypeId::DECIMAL, internal_lang,
"Ceil",
"ceil", {type::TypeId::SMALLINT}, type::TypeId::DECIMAL,
internal_lang, "Ceil",
function::BuiltInFuncType{OperatorId::Ceil,
function::DecimalFunctions::_Ceil},
txn);

AddBuiltinFunction(
"ceil", {type::TypeId::INTEGER}, type::TypeId::DECIMAL, internal_lang,
"Ceil",
function::BuiltInFuncType{OperatorId::Ceil,
function::DecimalFunctions::_Ceil},
"Ceil", function::BuiltInFuncType{OperatorId::Ceil,
function::DecimalFunctions::_Ceil},
txn);

AddBuiltinFunction(
"ceil", {type::TypeId::BIGINT}, type::TypeId::DECIMAL, internal_lang,
"Ceil",
function::BuiltInFuncType{OperatorId::Ceil,
function::DecimalFunctions::_Ceil},
"Ceil", function::BuiltInFuncType{OperatorId::Ceil,
function::DecimalFunctions::_Ceil},
txn);

/**
Expand All @@ -1097,14 +1095,13 @@ void Catalog::InitializeFunctions() {
function::BuiltInFuncType{OperatorId::DateTrunc,
function::TimestampFunctions::_DateTrunc},
txn);

// add now()
AddBuiltinFunction(
"now", {},
type::TypeId::TIMESTAMP, internal_lang, "Now",
function::BuiltInFuncType{OperatorId::Now,
function::DateFunctions::_Now},
txn);
AddBuiltinFunction("now", {}, type::TypeId::TIMESTAMP, internal_lang,
"Now",
function::BuiltInFuncType{
OperatorId::Now, function::DateFunctions::_Now},
txn);

} catch (CatalogException &e) {
txn_manager.AbortTransaction(txn);
Expand Down
14 changes: 11 additions & 3 deletions src/codegen/expression/comparison_translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
// Identification: src/codegen/expression/comparison_translator.cpp
//
// Copyright (c) 2015-2017, Carnegie Mellon University Database Group
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

Expand Down Expand Up @@ -48,8 +48,16 @@ codegen::Value ComparisonTranslator::DeriveValue(CodeGen &codegen,
case ExpressionType::COMPARE_GREATERTHANOREQUALTO:
return left.CompareGte(codegen, right);
case ExpressionType::COMPARE_LIKE: {
return left.CallBinaryOp(codegen, OperatorId::Like, right,
OnError::Exception);
type::TypeSystem::InvocationContext ctx{
.on_error = OnError::Exception,
.executor_context = context_.GetExecutorContextPtr()};

type::Type left_type = left.GetType(), right_type = right.GetType();
auto *binary_op = type::TypeSystem::GetBinaryOperator(
OperatorId::Like, left_type, left_type, right_type, right_type);
PL_ASSERT(binary_op);
return binary_op->Eval(codegen, left.CastTo(codegen, left_type),
right.CastTo(codegen, right_type), ctx);
}
default: {
throw Exception{"Invalid expression type for translation " +
Expand Down
6 changes: 3 additions & 3 deletions src/codegen/proxy/string_functions_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@

#include "codegen/proxy/string_functions_proxy.h"

#include "codegen/proxy/type_builder.h"
#include "function/string_functions.h"
#include "codegen/proxy/executor_context_proxy.h"

namespace peloton {
namespace codegen {

// StrWithLen Struct (Used by Substr function)
// StrWithLen struct
DEFINE_TYPE(StrWithLen, "peloton::StrWithLen", MEMBER(str), MEMBER(length));

// String Function
DEFINE_METHOD(peloton::function, StringFunctions, Ascii);
DEFINE_METHOD(peloton::function, StringFunctions, Like);
DEFINE_METHOD(peloton::function, StringFunctions, Length);
DEFINE_METHOD(peloton::function, StringFunctions, Substr);
DEFINE_METHOD(peloton::function, StringFunctions, Repeat);

// Trim-related functions
DEFINE_METHOD(peloton::function, StringFunctions, BTrim);
Expand Down

0 comments on commit 1f9bfff

Please sign in to comment.