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

Commit

Permalink
add null table for smallint varbinary and varchar
Browse files Browse the repository at this point in the history
  • Loading branch information
Tianyi Chen authored and apavlo committed Dec 25, 2017
1 parent 1bacf49 commit ebaf6e4
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 19 deletions.
24 changes: 24 additions & 0 deletions src/codegen/proxy/date_functions_proxy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//===----------------------------------------------------------------------===//
//
// Peloton
//
// date_functions_proxy.cpp
//
// Identification: src/codegen/proxy/date_functions_proxy.cpp
//
// Copyright (c) 2015-2017, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

#include "codegen/proxy/date_functions_proxy.h"

#include "codegen/proxy/type_builder.h"
#include "function/date_functions.h"

namespace peloton {
namespace codegen {

DEFINE_METHOD(peloton::function, DateFunctions, Now);

} // namespace codegen
} // namespace peloton
8 changes: 6 additions & 2 deletions src/codegen/type/smallint_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,14 +468,18 @@ static std::vector<TypeSystem::BinaryOpInfo> kBinaryOperatorTable = {
// Nary operations
static std::vector<TypeSystem::NaryOpInfo> kNaryOperatorTable = {};

// NoArg operators
static std::vector<TypeSystem::NoArgOpInfo> kNoArgOperatorTable = {};

} // anonymous namespace

// Initialize the SMALLINT SQL type with the configured type system
SmallInt::SmallInt()
: SqlType(peloton::type::TypeId::SMALLINT),
type_system_(kImplicitCastingTable, kExplicitCastingTable,
kComparisonTable, kUnaryOperatorTable, kBinaryOperatorTable,
kNaryOperatorTable) {}
kComparisonTable, kUnaryOperatorTable,
kBinaryOperatorTable, kNaryOperatorTable,
kNoArgOperatorTable) {}

Value SmallInt::GetMinValue(CodeGen &codegen) const {
auto *raw_val = codegen.Const16(peloton::type::PELOTON_INT16_MIN);
Expand Down
13 changes: 8 additions & 5 deletions src/codegen/type/timestamp_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "codegen/type/timestamp_type.h"

#include "codegen/proxy/values_runtime_proxy.h"
#include "codegen/proxy/date_functions_proxy.h"
#include "codegen/type/boolean_type.h"
#include "codegen/type/date_type.h"
#include "codegen/type/integer_type.h"
Expand Down Expand Up @@ -113,11 +114,12 @@ struct CompareTimestamp : public TypeSystem::SimpleComparisonHandleNull {

struct Now : public TypeSystem::NoArgOperator {
Type ResultType(UNUSED_ATTRIBUTE const Type &val_type) const override {
return TimeStamp::Instance();
return Timestamp::Instance();
}

Value DoWork(CodeGen &codegen) const override {
llvm::Value *raw_ret = codegen.Call(StringFunctionsProxy::Now);
std::vector<llvm::Value *> dummy;
llvm::Value *raw_ret = codegen.Call(DateFunctionsProxy::Now, dummy);
return Value{Timestamp::Instance(), raw_ret};
}
};
Expand Down Expand Up @@ -146,16 +148,17 @@ static std::vector<TypeSystem::NaryOpInfo> kNaryOperatorTable = {};
static Now kNow;
static std::vector<TypeSystem::NoArgOpInfo> kNoArgOperatorTable = {
{OperatorId::Now, kNow}
}
};

} // anonymous namespace

// Initialize the TIMESTAMP SQL type with the configured type system
Timestamp::Timestamp()
: SqlType(peloton::type::TypeId::TIMESTAMP),
type_system_(kImplicitCastingTable, kExplicitCastingTable,
kComparisonTable, kUnaryOperatorTable, kBinaryOperatorTable,
kNaryOperatorTable) {}
kComparisonTable, kUnaryOperatorTable,
kBinaryOperatorTable, kNaryOperatorTable,
kNoArgOperatorTable) {}

Value Timestamp::GetMinValue(CodeGen &codegen) const {
auto *raw_val = codegen.Const64(peloton::type::PELOTON_TIMESTAMP_MIN);
Expand Down
8 changes: 6 additions & 2 deletions src/codegen/type/varbinary_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ static std::vector<TypeSystem::BinaryOpInfo> kBinaryOperatorTable = {};
// Nary operations
static std::vector<TypeSystem::NaryOpInfo> kNaryOperatorTable = {};

// NoArg operators
static std::vector<TypeSystem::NoArgOpInfo> kNoArgOperatorTable = {};

} // anonymous namespace

//===----------------------------------------------------------------------===//
Expand All @@ -151,8 +154,9 @@ static std::vector<TypeSystem::NaryOpInfo> kNaryOperatorTable = {};
Varbinary::Varbinary()
: SqlType(peloton::type::TypeId::VARBINARY),
type_system_(kImplicitCastingTable, kExplicitCastingTable,
kComparisonTable, kUnaryOperatorTable, kBinaryOperatorTable,
kNaryOperatorTable) {}
kComparisonTable, kUnaryOperatorTable,
kBinaryOperatorTable, kNaryOperatorTable,
kNoArgOperatorTable) {}

Value Varbinary::GetMinValue(UNUSED_ATTRIBUTE CodeGen &codegen) const {
throw Exception{"The VARBINARY type does not have a minimum value ..."};
Expand Down
8 changes: 5 additions & 3 deletions src/codegen/type/varchar_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "codegen/proxy/string_functions_proxy.h"
#include "codegen/proxy/timestamp_functions_proxy.h"
#include "codegen/proxy/values_runtime_proxy.h"
#include "codegen/proxy/date_functions_proxy.h"
#include "codegen/type/boolean_type.h"
#include "codegen/type/integer_type.h"
#include "codegen/type/timestamp_type.h"
Expand Down Expand Up @@ -375,9 +376,10 @@ static Substr kSubstr;
static std::vector<TypeSystem::NaryOpInfo> kNaryOperatorTable = {
{OperatorId::Substr, kSubstr}};

} // anonymous namespace
// NoArg operators
static std::vector<TypeSystem::NoArgOpInfo> kNoArgOperatorTable = {};

static std::vector<TypeSystem::NoArgOpInfo> kOfknasdlkf = {};
} // anonymous namespace

//===----------------------------------------------------------------------===//
// TINYINT TYPE CONFIGURATION
Expand All @@ -388,7 +390,7 @@ Varchar::Varchar()
: SqlType(peloton::type::TypeId::VARCHAR),
type_system_(kImplicitCastingTable, kExplicitCastingTable,
kComparisonTable, kUnaryOperatorTable, kBinaryOperatorTable,
kNaryOperatorTable) {}
kNaryOperatorTable, kNoArgOperatorTable) {}

Value Varchar::GetMinValue(UNUSED_ATTRIBUTE CodeGen &codegen) const {
throw Exception{"The VARCHAR type does not have a minimum value ..."};
Expand Down
9 changes: 5 additions & 4 deletions src/function/date_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <date/iso_week.h>
#include <inttypes.h>
#include <time.h>
#include <sys/time.h>

#include "common/logger.h"
#include "type/types.h"
Expand Down Expand Up @@ -150,12 +151,12 @@ type::Value DateFunctions::Extract(const std::vector<type::Value> &args) {
// Postgres is returning the time when the transaction begins
// We are here intead generating a new time when this function
// is called
int64_t StringFunctions::Now() {
int64_t DateFunctions::Now() {
// TODO there might be some cross platform casting problem
// by Tianyi
time_t now;
time(&now);
return now;
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_usec + tv.tv_sec * (uint64_t)1000000;
}

type::Value DateFunctions::_Now(const UNUSED_ATTRIBUTE std::vector<type::Value> &args) {
Expand Down
26 changes: 26 additions & 0 deletions src/include/codegen/proxy/date_functions_proxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===----------------------------------------------------------------------===//
//
// Peloton
//
// date_functions_proxy.h
//
// Identification: src/include/codegen/proxy/date_functions_proxy.h
//
// Copyright (c) 2015-2017, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

#pragma once

#include "codegen/proxy/proxy.h"

namespace peloton {
namespace codegen {

PROXY(DateFunctions) {
// Proxy everything in function::StringFunctions
DECLARE_METHOD(Now);
};

} // namespace codegen
} // namespace peloton
6 changes: 3 additions & 3 deletions src/include/codegen/type/type_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,6 @@ class TypeSystem {
// The comparison table
const std::vector<ComparisonInfo> &comparison_table_;

// The table of builti no-arg operators
const std::vector<NoArgOpInfo> &no_arg_op_table_;

// The table of builtin unary operators
const std::vector<UnaryOpInfo> &unary_op_table_;

Expand All @@ -449,6 +446,9 @@ class TypeSystem {
// The table of builtin nary operators
const std::vector<NaryOpInfo> &nary_op_table_;

// The table of builti no-arg operators
const std::vector<NoArgOpInfo> &no_arg_op_table_;

private:
DISALLOW_COPY_AND_MOVE(TypeSystem);
};
Expand Down

0 comments on commit ebaf6e4

Please sign in to comment.