Permalink
Browse files

Merge branch 'master' into round_func

  • Loading branch information...
hzxa21 committed Dec 7, 2017
2 parents f7e0e8c + 0afeb62 commit 4a1cbf4d8e1ca1e4db97891b9d6d68cd6e653ae2
View
@@ -8,3 +8,9 @@ TabWidth: 2
# No tabs
UseTab: Never
# Don't automatically derive the alignment of & and *
DerivePointerAlignment: false
# Always align pointer and reference to the right
PointerAlignment: Right
@@ -10,15 +10,16 @@
//
//===----------------------------------------------------------------------===//
#include "catalog/catalog.h"
#include "binder/bind_node_visitor.h"
#include "catalog/catalog.h"
#include "type/type_id.h"
#include "expression/aggregate_expression.h"
#include "expression/case_expression.h"
#include "expression/tuple_value_expression.h"
#include "expression/function_expression.h"
#include "expression/operator_expression.h"
#include "expression/aggregate_expression.h"
#include "expression/star_expression.h"
#include "expression/tuple_value_expression.h"
namespace peloton {
namespace binder {
@@ -161,7 +162,8 @@ void BindNodeVisitor::Visit(expression::TupleValueExpression *expr) {
// Find the corresponding table in the context
if (!BinderContext::GetTableIdTuple(context_, table_name,
&table_id_tuple))
throw BinderException("Invalid table reference " + expr->GetTableName());
throw BinderException("Invalid table reference " +
expr->GetTableName());
// Find the column offset in that table
if (!BinderContext::GetColumnPosTuple(col_name, table_id_tuple,
col_pos_tuple, value_type, txn_))
@@ -209,6 +211,20 @@ void BindNodeVisitor::Visit(expression::FunctionExpression *expr) {
LOG_DEBUG("Argument num: %ld", func_data.argument_types_.size());
expr->SetFunctionExpressionParameters(func_data.func_, func_data.return_type_,
func_data.argument_types_);
// Look into the OperatorId for built-in functions to check the first argument
// for timestamp functions.
// TODO(LM): The OperatorId might need to be changed to global ID after we
// rewrite the function identification logic.
auto func_operator_id = func_data.func_.op_id;
if (func_operator_id == OperatorId::DateTrunc ||
func_operator_id == OperatorId::Extract) {
auto date_part = expr->GetChild(0);
// Test whether the first argument is a correct DatePartType
StringToDatePartType(
date_part->Evaluate(nullptr, nullptr, nullptr).ToString());
}
}
} // namespace binder
View
@@ -13,21 +13,22 @@
#include "catalog/catalog.h"
#include "catalog/column_catalog.h"
#include "catalog/index_catalog.h"
#include "catalog/database_catalog.h"
#include "catalog/database_metrics_catalog.h"
#include "catalog/table_catalog.h"
#include "catalog/table_metrics_catalog.h"
#include "catalog/index_catalog.h"
#include "catalog/index_metrics_catalog.h"
#include "catalog/language_catalog.h"
#include "catalog/proc_catalog.h"
#include "catalog/query_metrics_catalog.h"
#include "catalog/settings_catalog.h"
#include "concurrency/transaction_manager_factory.h"
#include "catalog/table_catalog.h"
#include "catalog/table_metrics_catalog.h"
#include "catalog/trigger_catalog.h"
#include "catalog/proc_catalog.h"
#include "catalog/language_catalog.h"
#include "concurrency/transaction_manager_factory.h"
#include "function/date_functions.h"
#include "function/decimal_functions.h"
#include "function/string_functions.h"
#include "function/timestamp_functions.h"
#include "index/index_factory.h"
#include "storage/storage_manager.h"
#include "storage/table_factory.h"
@@ -1031,6 +1032,12 @@ void Catalog::InitializeFunctions() {
function::BuiltInFuncType{OperatorId::Extract,
function::DateFunctions::Extract},
txn);
AddBuiltinFunction(
"date_trunc", {type::TypeId::VARCHAR, type::TypeId::TIMESTAMP},
type::TypeId::TIMESTAMP, internal_lang, "DateTrunc",
function::BuiltInFuncType{OperatorId::DateTrunc,
function::TimestampFunctions::_DateTrunc},
txn);
} catch (CatalogException &e) {
txn_manager.AbortTransaction(txn);
throw & e;
@@ -0,0 +1,23 @@
//===----------------------------------------------------------------------===//
//
// Peloton
//
// timestamp_functions_proxy.cpp
//
// Identification: src/codegen/proxy/timestamp_functions_proxy.cpp
//
// Copyright (c) 2015-2017, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//
#include "function/timestamp_functions.h"
#include "codegen/proxy/timestamp_functions_proxy.h"
#include "codegen/proxy/type_builder.h"
namespace peloton {
namespace codegen {
DEFINE_METHOD(peloton::function, TimestampFunctions, DateTrunc);
} // namespace codegen
} // namespace peloton
@@ -13,9 +13,9 @@
#include "codegen/type/integer_type.h"
#include "codegen/lang/if.h"
#include "codegen/value.h"
#include "codegen/proxy/values_runtime_proxy.h"
#include "codegen/type/boolean_type.h"
#include "codegen/value.h"
#include "common/exception.h"
#include "type/limits.h"
#include "util/string_util.h"
@@ -420,7 +420,8 @@ static std::vector<TypeSystem::BinaryOpInfo> kBinaryOperatorTable = {
{OperatorId::Sub, kSubOp},
{OperatorId::Mul, kMulOp},
{OperatorId::Div, kDivOp},
{OperatorId::Mod, kModuloOp}};
{OperatorId::Mod, kModuloOp},
};
// Nary operations
static std::vector<TypeSystem::NaryOpInfo> kNaryOperatorTable = {};
@@ -435,8 +436,8 @@ static std::vector<TypeSystem::NaryOpInfo> kNaryOperatorTable = {};
Integer::Integer()
: SqlType(peloton::type::TypeId::INTEGER),
type_system_(kImplicitCastingTable, kExplicitCastingTable,
kComparisonTable, kUnaryOperatorTable,
kBinaryOperatorTable, kNaryOperatorTable) {}
kComparisonTable, kUnaryOperatorTable, kBinaryOperatorTable,
kNaryOperatorTable) {}
Value Integer::GetMinValue(CodeGen &codegen) const {
auto *raw_val = codegen.Const32(peloton::type::PELOTON_INT32_MIN);
@@ -466,4 +467,4 @@ llvm::Function *Integer::GetOutputFunction(
} // namespace type
} // namespace codegen
} // namespace peloton
} // namespace peloton
@@ -12,11 +12,11 @@
#include "codegen/type/timestamp_type.h"
#include "codegen/value.h"
#include "codegen/proxy/values_runtime_proxy.h"
#include "codegen/type/boolean_type.h"
#include "codegen/type/date_type.h"
#include "codegen/type/integer_type.h"
#include "codegen/value.h"
#include "type/timestamp_type.h"
namespace peloton {
@@ -120,6 +120,7 @@ static std::vector<TypeSystem::ComparisonInfo> kComparisonTable = {
{kCompareTimestamp}};
static std::vector<TypeSystem::UnaryOpInfo> kUnaryOperatorTable = {};
static std::vector<TypeSystem::BinaryOpInfo> kBinaryOperatorTable = {};
// Nary operations
@@ -131,8 +132,8 @@ static std::vector<TypeSystem::NaryOpInfo> kNaryOperatorTable = {};
Timestamp::Timestamp()
: SqlType(peloton::type::TypeId::TIMESTAMP),
type_system_(kImplicitCastingTable, kExplicitCastingTable,
kComparisonTable, kUnaryOperatorTable,
kBinaryOperatorTable, kNaryOperatorTable) {}
kComparisonTable, kUnaryOperatorTable, kBinaryOperatorTable,
kNaryOperatorTable) {}
Value Timestamp::GetMinValue(CodeGen &codegen) const {
auto *raw_val = codegen.Const64(peloton::type::PELOTON_TIMESTAMP_MIN);
@@ -163,4 +164,4 @@ llvm::Function *Timestamp::GetOutputFunction(
} // namespace type
} // namespace codegen
} // namespace peloton
} // namespace peloton
@@ -17,6 +17,8 @@
#include "codegen/proxy/values_runtime_proxy.h"
#include "codegen/type/boolean_type.h"
#include "codegen/type/integer_type.h"
#include "codegen/type/timestamp_type.h"
#include "codegen/proxy/timestamp_functions_proxy.h"
namespace peloton {
namespace codegen {
@@ -196,6 +198,31 @@ struct Length : public TypeSystem::UnaryOperator {
}
};
// DateTrunc
// TODO(lma): Move this to the Timestamp type once the function lookup logic is
// corrected.
struct DateTrunc : public TypeSystem::BinaryOperator {
bool SupportsTypes(const Type &left_type,
const Type &right_type) const override {
return left_type.GetSqlType() == Varchar::Instance() &&
right_type.GetSqlType() == Timestamp::Instance();
}
Type ResultType(UNUSED_ATTRIBUTE const Type &left_type,
UNUSED_ATTRIBUTE const Type &right_type) const override {
return Type{Timestamp::Instance()};
}
Value DoWork(CodeGen &codegen, const Value &left, const Value &right,
UNUSED_ATTRIBUTE OnError on_error) const override {
PL_ASSERT(SupportsTypes(left.GetType(), right.GetType()));
llvm::Value *raw_ret = codegen.Call(TimestampFunctionsProxy::DateTrunc,
{left.GetValue(), right.GetValue()});
return Value{Timestamp::Instance(), raw_ret};
}
};
//===----------------------------------------------------------------------===//
// TYPE SYSTEM CONSTRUCTION
//===----------------------------------------------------------------------===//
@@ -220,8 +247,9 @@ static std::vector<TypeSystem::UnaryOpInfo> kUnaryOperatorTable = {
// Binary operations
static Like kLike;
static DateTrunc kDateTrunc;
static std::vector<TypeSystem::BinaryOpInfo> kBinaryOperatorTable = {
{OperatorId::Like, kLike}};
{OperatorId::Like, kLike}, {OperatorId::DateTrunc, kDateTrunc}};
// Nary operations
static std::vector<TypeSystem::NaryOpInfo> kNaryOperatorTable = {};
@@ -10,12 +10,11 @@
//
//===----------------------------------------------------------------------===//
#include "function/date_functions.h"
#include <date/date.h>
#include <inttypes.h>
#include <date/iso_week.h>
#include <inttypes.h>
#include "common/logger.h"
#include "type/types.h"
Oops, something went wrong.

0 comments on commit 4a1cbf4

Please sign in to comment.