Skip to content

Commit

Permalink
Merge branch 'master' of github.com:map-d/mapd2
Browse files Browse the repository at this point in the history
  • Loading branch information
mapdwei committed Jul 14, 2015
2 parents a8ae6b0 + a3e1727 commit 4ef9a1b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 7 deletions.
23 changes: 23 additions & 0 deletions MapDServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,28 @@ TDatumType::type type_to_thrift(const SQLTypeInfo& type_info) {
CHECK(false);
}

#define ENCODING_CASE(encoding) \
case kENCODING_##encoding: \
return TEncodingType::encoding;

TEncodingType::type encoding_to_thrift(const SQLTypeInfo& type_info) {
switch (type_info.get_compression()) {
ENCODING_CASE(NONE)
ENCODING_CASE(FIXED)
ENCODING_CASE(RL)
ENCODING_CASE(DIFF)
ENCODING_CASE(DICT)
ENCODING_CASE(SPARSE)
default:
CHECK(false);
}
CHECK(false);
}

#undef ENCODING_CASE

} // namespace

#define INVALID_SESSION_ID -1

class MapDHandler : virtual public MapDIf {
Expand Down Expand Up @@ -336,6 +356,7 @@ class MapDHandler : virtual public MapDIf {
}
const auto& target_ti = target->get_expr()->get_type_info();
proj_info.col_type.type = type_to_thrift(target_ti);
proj_info.col_type.encoding = encoding_to_thrift(target_ti);
proj_info.col_type.nullable = !target_ti.get_notnull();
proj_info.col_type.is_array = target_ti.get_type() == kARRAY;
_return.row_set.row_desc.push_back(proj_info);
Expand Down Expand Up @@ -385,6 +406,7 @@ class MapDHandler : virtual public MapDIf {
for (const auto cd : col_descriptors) {
TColumnType col_type;
col_type.col_type.type = type_to_thrift(cd->columnType);
col_type.col_type.encoding = encoding_to_thrift(cd->columnType);
col_type.col_type.nullable = !cd->columnType.get_notnull();
col_type.col_type.is_array = cd->columnType.get_type() == kARRAY;
_return.insert(std::make_pair(cd->columnName, col_type));
Expand Down Expand Up @@ -413,6 +435,7 @@ class MapDHandler : virtual public MapDIf {
TColumnType col_type;
col_type.col_name = cd->columnName;
col_type.col_type.type = type_to_thrift(cd->columnType);
col_type.col_type.encoding = encoding_to_thrift(cd->columnType);
col_type.col_type.nullable = !cd->columnType.get_notnull();
col_type.col_type.is_array = cd->columnType.get_type() == kARRAY;
_return.push_back(col_type);
Expand Down
40 changes: 33 additions & 7 deletions QueryEngine/Execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1424,9 +1424,12 @@ llvm::Value* Executor::codegenArith(const Analyzer::BinOper* bin_oper, const boo
const auto rhs = bin_oper->get_right_operand();
const auto& lhs_type = lhs->get_type_info();
const auto& rhs_type = rhs->get_type_info();
const auto lhs_lv = codegen(lhs, true, hoist_literals).front();
const auto rhs_lv = codegen(rhs, true, hoist_literals).front();
auto lhs_lv = codegen(lhs, true, hoist_literals).front();
auto rhs_lv = codegen(rhs, true, hoist_literals).front();
CHECK_EQ(lhs_type.get_type(), rhs_type.get_type());
if (lhs_type.is_decimal()) {
CHECK_EQ(lhs_type.get_scale(), rhs_type.get_scale());
}
const bool not_null { lhs_type.get_notnull() && rhs_type.get_notnull() };
if (lhs_type.is_integer() || lhs_type.is_decimal()) {
const std::string int_typename { "int" + std::to_string(get_bit_width(lhs_type)) + "_t" };
Expand All @@ -1445,15 +1448,38 @@ llvm::Value* Executor::codegenArith(const Analyzer::BinOper* bin_oper, const boo
return cgen_state_->emitCall("add_" + int_typename + "_nullable",
{ lhs_lv, rhs_lv, ll_int(inline_int_null_val(lhs_type)) });
}
case kMULTIPLY:
case kMULTIPLY: {
llvm::Value* result { nullptr };
bool dec_adjusted { false };
if (dynamic_cast<const Analyzer::Constant*>(rhs) && rhs_type.is_decimal()) {
rhs_lv = cgen_state_->ir_builder_.CreateSDiv(rhs_lv,
llvm::ConstantInt::get(rhs_lv->getType(), exp_to_scale(rhs_type.get_scale())));
dec_adjusted = true;
} else if (dynamic_cast<const Analyzer::Constant*>(lhs) && lhs_type.is_decimal()) {
lhs_lv = cgen_state_->ir_builder_.CreateSDiv(lhs_lv,
llvm::ConstantInt::get(lhs_lv->getType(), exp_to_scale(lhs_type.get_scale())));
dec_adjusted = true;
}
if (not_null) {
return cgen_state_->ir_builder_.CreateMul(lhs_lv, rhs_lv);
result = cgen_state_->ir_builder_.CreateMul(lhs_lv, rhs_lv);
} else {
return cgen_state_->emitCall("mul_" + int_typename + "_nullable",
result = cgen_state_->emitCall("mul_" + int_typename + "_nullable",
{ lhs_lv, rhs_lv, ll_int(inline_int_null_val(lhs_type)) });
}
case kDIVIDE:
return codegenDiv(lhs_lv, rhs_lv, not_null ? "" : int_typename, lhs_type);
if (lhs_type.is_decimal() && !dec_adjusted) {
result = cgen_state_->ir_builder_.CreateSDiv(result,
llvm::ConstantInt::get(result->getType(), exp_to_scale(lhs_type.get_scale())));
}
return result;
}
case kDIVIDE: {
auto result = codegenDiv(lhs_lv, rhs_lv, not_null ? "" : int_typename, lhs_type);
if (lhs_type.is_decimal()) {
result = cgen_state_->ir_builder_.CreateMul(result,
llvm::ConstantInt::get(result->getType(), exp_to_scale(lhs_type.get_scale())));
}
return result;
}
default:
CHECK(false);
}
Expand Down
1 change: 1 addition & 0 deletions Tests/ExecuteTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ TEST(Select, FilterAndSimpleAggregation) {
c("SELECT COUNT(*) FROM test WHERE dec > 111.1;", dt);
c("SELECT COUNT(*) FROM test WHERE dec > 222.2;", dt);
c("SELECT MAX(x + dec) FROM test;", dt);
c("SELECT MAX(x + 2 * dec), MIN(x + 2 * dec) FROM test;", dt);
ASSERT_EQ(v<int64_t>(run_simple_agg("SELECT MIN(x) FROM test WHERE x <> 7 AND x <> 8;", dt)), numeric_limits<int64_t>::max());
ASSERT_EQ(v<int64_t>(run_simple_agg("SELECT MIN(x) FROM test WHERE z <> 101 AND z <> 102;", dt)), numeric_limits<int64_t>::max());
ASSERT_EQ(v<int64_t>(run_simple_agg("SELECT MIN(x) FROM test WHERE t <> 1001 AND t <> 1002;", dt)), numeric_limits<int64_t>::max());
Expand Down
10 changes: 10 additions & 0 deletions mapd.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ enum TDatumType {
BOOL
}

enum TEncodingType {
NONE,
FIXED,
RL,
DIFF,
DICT,
SPARSE
}

enum TExecuteMode {
HYBRID,
GPU,
Expand All @@ -34,6 +43,7 @@ struct TStringValue {

struct TTypeInfo {
1: TDatumType type,
4: TEncodingType encoding,
2: bool nullable,
3: bool is_array
}
Expand Down

0 comments on commit 4ef9a1b

Please sign in to comment.