Skip to content

Commit

Permalink
feat(tianmu): formate code #11
Browse files Browse the repository at this point in the history
  • Loading branch information
hustjieke authored and mergify[bot] committed Nov 22, 2022
1 parent 821e051 commit af9bed4
Show file tree
Hide file tree
Showing 49 changed files with 222 additions and 162 deletions.
21 changes: 11 additions & 10 deletions storage/tianmu/core/aggregation_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ void AggregationAlgorithm::Aggregate(bool just_distinct, int64_t &limit, int64_t
else if (cur_a.distinct) {
max_no_of_distinct = cur_a.term.vc->GetApproxDistVals(false); // no nulls included
if (tianmu_control_.isOn())
tianmu_control_.lock(m_conn->GetThreadID()) << "Adding dist. column, min = " << min_v << ", max = " << max_v
<< ", dist = " << max_no_of_distinct << system::unlock;
tianmu_control_.lock(m_conn->GetThreadID())
<< "Adding dist. column, min = " << min_v << ", max = " << max_v << ", dist = " << max_no_of_distinct
<< system::unlock;
}
}
if (max_no_of_distinct == 0)
Expand Down Expand Up @@ -271,7 +272,7 @@ void AggregationAlgorithm::MultiDimensionalGroupByScan(GroupByWrapper &gbw, int6
<< "Aggregating: " << mit.NumOfTuples() << " tuples left." << system::unlock;
else
tianmu_control_.lock(m_conn->GetThreadID()) << "Aggregating: " << gbw.TuplesNoOnes() << " tuples left, "
<< displayed_no_groups << " gr. found so far" << system::unlock;
<< displayed_no_groups << " gr. found so far" << system::unlock;
}
cur_tuple = 0;
gbw.ClearNoGroups(); // count groups locally created in this pass
Expand Down Expand Up @@ -343,7 +344,7 @@ void AggregationAlgorithm::MultiDimensionalGroupByScan(GroupByWrapper &gbw, int6
}
tianmu_control_.lock(m_conn->GetThreadID()) << "Group/Aggregate end. Begin generating output." << system::unlock;
tianmu_control_.lock(m_conn->GetThreadID()) << "Output rows: " << gbw.NumOfGroups() + gbw.TuplesNoOnes()
<< ", output table row limit: " << t->GetPageSize() << system::unlock;
<< ", output table row limit: " << t->GetPageSize() << system::unlock;
int64_t output_size = (gbw.NumOfGroups() + gbw.TuplesNoOnes()) * t->GetOneOutputRecordSize();
gbw.RewindRows();
if (t->GetPageSize() >= (gbw.NumOfGroups() + gbw.TuplesNoOnes()) && output_size > (1L << 29) &&
Expand Down Expand Up @@ -837,8 +838,8 @@ void AggregationAlgorithm::ParallelFillOutputWrapper(GroupByWrapper &gbw, int64_

utils::result_set<void> res;
for (auto &gb : vgbw) {
res.insert(ha_tianmu_engine_->query_thread_pool.add_task(&AggregationAlgorithm::TaskFillOutput, this, &gb, conn, offset,
limit));
res.insert(ha_tianmu_engine_->query_thread_pool.add_task(&AggregationAlgorithm::TaskFillOutput, this, &gb, conn,
offset, limit));
}
res.get_all_with_except();
}
Expand Down Expand Up @@ -922,8 +923,8 @@ void AggregationWorkerEnt::DistributeAggreTaskAverage(MIIterator &mit) {

utils::result_set<void> res;
for (int i = 0; i < loopcnt; ++i) {
res.insert(
ha_tianmu_engine_->query_thread_pool.add_task(&AggregationWorkerEnt::PrepShardingCopy, this, &mit, gb_main, &vGBW));
res.insert(ha_tianmu_engine_->query_thread_pool.add_task(&AggregationWorkerEnt::PrepShardingCopy, this, &mit,
gb_main, &vGBW));

int pack_start = i * num;
int pack_end = 0;
Expand Down Expand Up @@ -969,8 +970,8 @@ void AggregationWorkerEnt::DistributeAggreTaskAverage(MIIterator &mit) {

for (size_t i = 0; i < vTask.size(); ++i) {
GroupByWrapper *gbw = i == 0 ? gb_main : vGBW[i].get();
res1.insert(ha_tianmu_engine_->query_thread_pool.add_task(&AggregationWorkerEnt::TaskAggrePacks, this, &taskIterator[i],
&dims, &mit, &vTask[i], gbw, conn));
res1.insert(ha_tianmu_engine_->query_thread_pool.add_task(&AggregationWorkerEnt::TaskAggrePacks, this,
&taskIterator[i], &dims, &mit, &vTask[i], gbw, conn));
}
res1.get_all_with_except();

Expand Down
9 changes: 6 additions & 3 deletions storage/tianmu/core/aggregator_advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,26 @@ int64_t AggregatorStdSampD::GetValue64(unsigned char *buf) {
void AggregatorBitAnd::PutAggregatedValue(unsigned char *buf, const types::BString &v, int64_t factor) {
stats_updated = false;
types::TianmuNum val(common::CT::BIGINT);
if (!v.IsEmpty() && types::TianmuNum::Parse(v, val, common::CT::BIGINT) == common::ErrorCode::SUCCESS && !val.IsNull()) {
if (!v.IsEmpty() && types::TianmuNum::Parse(v, val, common::CT::BIGINT) == common::ErrorCode::SUCCESS &&
!val.IsNull()) {
PutAggregatedValue(buf, int64_t(val), factor);
}
}

void AggregatorBitOr::PutAggregatedValue(unsigned char *buf, const types::BString &v, int64_t factor) {
stats_updated = false;
types::TianmuNum val(common::CT::BIGINT);
if (!v.IsEmpty() && types::TianmuNum::Parse(v, val, common::CT::BIGINT) == common::ErrorCode::SUCCESS && !val.IsNull()) {
if (!v.IsEmpty() && types::TianmuNum::Parse(v, val, common::CT::BIGINT) == common::ErrorCode::SUCCESS &&
!val.IsNull()) {
PutAggregatedValue(buf, int64_t(val), factor);
}
}

void AggregatorBitXor::PutAggregatedValue(unsigned char *buf, const types::BString &v, int64_t factor) {
stats_updated = false;
types::TianmuNum val(common::CT::BIGINT);
if (!v.IsEmpty() && types::TianmuNum::Parse(v, val, common::CT::BIGINT) == common::ErrorCode::SUCCESS && !val.IsNull()) {
if (!v.IsEmpty() && types::TianmuNum::Parse(v, val, common::CT::BIGINT) == common::ErrorCode::SUCCESS &&
!val.IsNull()) {
PutAggregatedValue(buf, int64_t(val), factor);
}
}
Expand Down
6 changes: 4 additions & 2 deletions storage/tianmu/core/column_bin_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,8 @@ ColumnBinEncoder::EncoderDate::EncoderDate(vcolumn::VirtualColumn *vc, bool deco
bool ColumnBinEncoder::EncoderDate::SecondColumn(vcolumn::VirtualColumn *vc) {
// Possible conversions: only dates.
if (vc->Type().GetTypeName() != common::CT::DATE) {
tianmu_control_.lock(vc->ConnInfo()->GetThreadID()) << "Nontrivial comparison: date with non-date" << system::unlock;
tianmu_control_.lock(vc->ConnInfo()->GetThreadID())
<< "Nontrivial comparison: date with non-date" << system::unlock;
return false;
}
int64_t new_min_val = types::DT::DateSortEncoding(vc->RoughMin());
Expand Down Expand Up @@ -662,7 +663,8 @@ ColumnBinEncoder::EncoderYear::EncoderYear(vcolumn::VirtualColumn *vc, bool deco
bool ColumnBinEncoder::EncoderYear::SecondColumn(vcolumn::VirtualColumn *vc) {
// Possible conversions: only years.
if (vc->Type().GetTypeName() != common::CT::YEAR) {
tianmu_control_.lock(vc->ConnInfo()->GetThreadID()) << "Nontrivial comparison: year with non-year" << system::unlock;
tianmu_control_.lock(vc->ConnInfo()->GetThreadID())
<< "Nontrivial comparison: year with non-year" << system::unlock;
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion storage/tianmu/core/column_share.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include "common/exception.h"
#include "core/column_share.h"
#include "core/engine.h"
#include "system/tianmu_system.h"
#include "system/tianmu_file.h"
#include "system/tianmu_system.h"

namespace Tianmu {
namespace core {
Expand Down
6 changes: 3 additions & 3 deletions storage/tianmu/core/condition_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ void ConditionEncoder::TransformINs() {
desc->val2 = CQTerm();
desc->val2.vc =
new vcolumn::ConstColumn(ValueOrNull(types::TianmuNum(attr->EncodeValue64(mvc.GetSetMin(mit), sharp),
static_cast<short>(in_type.GetTypeName()))),
static_cast<short>(in_type.GetTypeName()))),
in_type);
desc->val2.vc_id = desc->table->AddVirtColumn(desc->val2.vc);
} else {
Expand Down Expand Up @@ -650,12 +650,12 @@ void ConditionEncoder::TransformINs() {
&& span == mvc.AtLeastNoDistinctValues(mit, span + 1)) {
desc->val2.vc = new vcolumn::ConstColumn(
ValueOrNull(types::TianmuNum(val_max, attr->Type().GetScale(), ATI::IsRealType(in_type.GetTypeName()),
in_type.GetTypeName())),
in_type.GetTypeName())),
in_type);
desc->val2.vc_id = desc->table->AddVirtColumn(desc->val2.vc);
desc->val1.vc = new vcolumn::ConstColumn(
ValueOrNull(types::TianmuNum(val_min, attr->Type().GetScale(), ATI::IsRealType(in_type.GetTypeName()),
in_type.GetTypeName())),
in_type.GetTypeName())),
in_type);
desc->val1.vc_id = desc->table->AddVirtColumn(desc->val1.vc);
if (desc->op == common::Operator::O_IN)
Expand Down
35 changes: 20 additions & 15 deletions storage/tianmu/core/descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,40 +262,45 @@ bool Descriptor::operator<=(const Descriptor &sec) const {
if ((sec.op == common::Operator::O_LESS || sec.op == common::Operator::O_LESS_EQ ||
sec.op == common::Operator::O_MORE || sec.op == common::Operator::O_MORE_EQ ||
sec.op == common::Operator::O_EQ) &&
types::TianmuValueObject::compare(val1.vc->GetValue(dummy_mit), sec.val1.vc->GetValue(dummy_mit), sec.op, '\\'))
types::TianmuValueObject::compare(val1.vc->GetValue(dummy_mit), sec.val1.vc->GetValue(dummy_mit), sec.op,
'\\'))
return true;
break;
case common::Operator::O_LESS_EQ:
if ((sec.op == common::Operator::O_LESS || sec.op == common::Operator::O_LESS_EQ) &&
types::TianmuValueObject::compare(val1.vc->GetValue(dummy_mit), sec.val1.vc->GetValue(dummy_mit), sec.op, '\\'))
types::TianmuValueObject::compare(val1.vc->GetValue(dummy_mit), sec.val1.vc->GetValue(dummy_mit), sec.op,
'\\'))
return true;
break;
case common::Operator::O_MORE_EQ:
if ((sec.op == common::Operator::O_MORE || sec.op == common::Operator::O_MORE_EQ) &&
types::TianmuValueObject::compare(val1.vc->GetValue(dummy_mit), sec.val1.vc->GetValue(dummy_mit), sec.op, '\\'))
types::TianmuValueObject::compare(val1.vc->GetValue(dummy_mit), sec.val1.vc->GetValue(dummy_mit), sec.op,
'\\'))
return true;
break;
case common::Operator::O_LESS:
if ((sec.op == common::Operator::O_LESS || sec.op == common::Operator::O_LESS_EQ) &&
types::TianmuValueObject::compare(val1.vc->GetValue(dummy_mit), sec.val1.vc->GetValue(dummy_mit),
common::Operator::O_LESS_EQ, '\\'))
common::Operator::O_LESS_EQ, '\\'))
return true;
break;
case common::Operator::O_MORE:
if ((sec.op == common::Operator::O_MORE || sec.op == common::Operator::O_MORE_EQ) &&
types::TianmuValueObject::compare(val1.vc->GetValue(dummy_mit), sec.val1.vc->GetValue(dummy_mit),
common::Operator::O_MORE_EQ, '\\'))
common::Operator::O_MORE_EQ, '\\'))
return true;
break;
case common::Operator::O_BETWEEN:
if (sec.op == common::Operator::O_BETWEEN && val1.vc->GetValue(dummy_mit) >= sec.val1.vc->GetValue(dummy_mit) &&
val2.vc->GetValue(dummy_mit) <= sec.val2.vc->GetValue(dummy_mit))
return true;
if ((sec.op == common::Operator::O_LESS || sec.op == common::Operator::O_LESS_EQ) &&
types::TianmuValueObject::compare(val2.vc->GetValue(dummy_mit), sec.val1.vc->GetValue(dummy_mit), sec.op, '\\'))
types::TianmuValueObject::compare(val2.vc->GetValue(dummy_mit), sec.val1.vc->GetValue(dummy_mit), sec.op,
'\\'))
return true;
if ((sec.op == common::Operator::O_MORE || sec.op == common::Operator::O_MORE_EQ) &&
types::TianmuValueObject::compare(val1.vc->GetValue(dummy_mit), sec.val1.vc->GetValue(dummy_mit), sec.op, '\\'))
types::TianmuValueObject::compare(val1.vc->GetValue(dummy_mit), sec.val1.vc->GetValue(dummy_mit), sec.op,
'\\'))
return true;
break;
case common::Operator::O_IN: {
Expand Down Expand Up @@ -1104,10 +1109,10 @@ bool Descriptor::CheckCondition(const MIIterator &mit) {
}
} else {
types::TianmuValueObject tianmu_value_obj1 = attr.vc->GetValue(mit, false);
val1_res =
val1.vc->IsNull(mit) ? common::TRIBOOL_UNKNOWN : common::Tribool(tianmu_value_obj1 >= val1.vc->GetValue(mit, false));
val2_res =
val2.vc->IsNull(mit) ? common::TRIBOOL_UNKNOWN : common::Tribool(tianmu_value_obj1 <= val2.vc->GetValue(mit, false));
val1_res = val1.vc->IsNull(mit) ? common::TRIBOOL_UNKNOWN
: common::Tribool(tianmu_value_obj1 >= val1.vc->GetValue(mit, false));
val2_res = val2.vc->IsNull(mit) ? common::TRIBOOL_UNKNOWN
: common::Tribool(tianmu_value_obj1 <= val2.vc->GetValue(mit, false));
}
if (op == common::Operator::O_BETWEEN) {
if (val1_res != true || val2_res != true)
Expand Down Expand Up @@ -1178,10 +1183,10 @@ bool Descriptor::IsNull(const MIIterator &mit) {
}
} else {
types::TianmuValueObject tianmu_value_obj1 = attr.vc->GetValue(mit, false);
val1_res =
val1.vc->IsNull(mit) ? common::TRIBOOL_UNKNOWN : common::Tribool(tianmu_value_obj1 >= val1.vc->GetValue(mit, false));
val2_res =
val2.vc->IsNull(mit) ? common::TRIBOOL_UNKNOWN : common::Tribool(tianmu_value_obj1 <= val2.vc->GetValue(mit, false));
val1_res = val1.vc->IsNull(mit) ? common::TRIBOOL_UNKNOWN
: common::Tribool(tianmu_value_obj1 >= val1.vc->GetValue(mit, false));
val2_res = val2.vc->IsNull(mit) ? common::TRIBOOL_UNKNOWN
: common::Tribool(tianmu_value_obj1 <= val2.vc->GetValue(mit, false));
}
if (common::Tribool::And(val1_res, val2_res) == common::TRIBOOL_UNKNOWN)
return true;
Expand Down
7 changes: 4 additions & 3 deletions storage/tianmu/core/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
#include "common/data_format.h"
#include "common/exception.h"
#include "common/mysql_gate.h"
#include "core/tianmu_mem_table.h"
#include "core/table_share.h"
#include "core/task_executor.h"
#include "core/temp_table.h"
#include "core/tianmu_mem_table.h"
#include "core/tools.h"
#include "core/transaction.h"
#include "mm/initializer.h"
Expand Down Expand Up @@ -808,8 +808,9 @@ void Engine::TruncateTable(const std::string &table_path, [[maybe_unused]] THD *
TIANMU_LOG(LogCtl_Level::INFO, "Truncated table %s, ID = %u", table_path.c_str(), id);
}

void Engine::GetTableIterator(const std::string &table_path, TianmuTable::Iterator &iter_begin, TianmuTable::Iterator &iter_end,
std::shared_ptr<TianmuTable> &table, const std::vector<bool> &attrs, THD *thd) {
void Engine::GetTableIterator(const std::string &table_path, TianmuTable::Iterator &iter_begin,
TianmuTable::Iterator &iter_end, std::shared_ptr<TianmuTable> &table,
const std::vector<bool> &attrs, THD *thd) {
table = GetTx(thd)->GetTableByPath(table_path);
iter_begin = table->Begin(attrs);
iter_end = table->End();
Expand Down
7 changes: 4 additions & 3 deletions storage/tianmu/core/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
#include "core/data_cache.h"
#include "core/object_cache.h"
#include "core/query.h"
#include "core/tianmu_table.h"
#include "core/table_share.h"
#include "core/temp_table.h"
#include "core/tianmu_table.h"
#include "exporter/data_exporter.h"
#include "exporter/export2file.h"
#include "index/tianmu_table_index.h"
Expand Down Expand Up @@ -100,8 +100,9 @@ class Engine final {
std::vector<AttrInfo> GetTableAttributesInfo(const std::string &table_path, TABLE_SHARE *table_share);
void UpdateAndStoreColumnComment(TABLE *table, int field_id, Field *source_field, int source_field_id,
CHARSET_INFO *cs);
void GetTableIterator(const std::string &table_path, TianmuTable::Iterator &iter_begin, TianmuTable::Iterator &iter_end,
std::shared_ptr<TianmuTable> &table, const std::vector<bool> &, THD *thd);
void GetTableIterator(const std::string &table_path, TianmuTable::Iterator &iter_begin,
TianmuTable::Iterator &iter_end, std::shared_ptr<TianmuTable> &table, const std::vector<bool> &,
THD *thd);
common::TianmuError RunLoader(THD *thd, sql_exchange *ex, TABLE_LIST *table_list, void *arg);
void CommitTx(THD *thd, bool all);
void Rollback(THD *thd, bool all, bool force_error_message = false);
Expand Down
4 changes: 2 additions & 2 deletions storage/tianmu/core/engine_convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ int Engine::Convert(int &is_null, String *value, types::TianmuDataType &rcitem,
if (types::TianmuDateTime *tianmu_dt = dynamic_cast<types::TianmuDateTime *>(&rcitem)) {
if (*tianmu_dt != types::kTianmuTimestampSpec) {
MYSQL_TIME local_time;
my_time_t secs = tianmu_sec_since_epoch(tianmu_dt->Year(), tianmu_dt->Month(), tianmu_dt->Day(), tianmu_dt->Hour(),
tianmu_dt->Minute(), tianmu_dt->Second());
my_time_t secs = tianmu_sec_since_epoch(tianmu_dt->Year(), tianmu_dt->Month(), tianmu_dt->Day(),
tianmu_dt->Hour(), tianmu_dt->Minute(), tianmu_dt->Second());
current_txn_->Thd()->variables.time_zone->gmt_sec_to_TIME(&local_time, secs);
char buf[32];
local_time.second_part = tianmu_dt->MicroSecond();
Expand Down
14 changes: 8 additions & 6 deletions storage/tianmu/core/engine_results.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,15 @@ void ResultSender::SendRecord(const std::vector<std::unique_ptr<types::TianmuDat
Engine::Convert(is_null, isum_hybrid_rcbase->dec_value(), tianmu_dt, item->decimals);
isum_hybrid_rcbase->null_value = is_null;
} else if (isum_hybrid_rcbase->result_type() == INT_RESULT) {
Engine::Convert(is_null, isum_hybrid_rcbase->int64_value(), tianmu_dt, isum_hybrid_rcbase->hybrid_field_type_);
Engine::Convert(is_null, isum_hybrid_rcbase->int64_value(), tianmu_dt,
isum_hybrid_rcbase->hybrid_field_type_);
isum_hybrid_rcbase->null_value = is_null;
} else if (isum_hybrid_rcbase->result_type() == REAL_RESULT) {
Engine::Convert(is_null, isum_hybrid_rcbase->real_value(), tianmu_dt);
isum_hybrid_rcbase->null_value = is_null;
} else if (isum_hybrid_rcbase->result_type() == STRING_RESULT) {
Engine::Convert(is_null, isum_hybrid_rcbase->string_value(), tianmu_dt, isum_hybrid_rcbase->hybrid_field_type_);
Engine::Convert(is_null, isum_hybrid_rcbase->string_value(), tianmu_dt,
isum_hybrid_rcbase->hybrid_field_type_);
isum_hybrid_rcbase->null_value = is_null;
}
break;
Expand Down Expand Up @@ -387,10 +389,10 @@ void ResultSender::Finalize(TempTable *result_table) {
auto &sctx = thd->m_main_security_ctx;
if (tianmu_querylog_.isOn())
tianmu_querylog_ << system::lock << "\tClientIp:" << (sctx.ip().length ? sctx.ip().str : "unkownn")
<< "\tClientHostName:" << (sctx.host().length ? sctx.host().str : "unknown")
<< "\tClientPort:" << thd->peer_port << "\tUser:" << sctx.user().str << global_serverinfo_
<< "\tAffectRows:" << affect_rows << "\tResultRows:" << rows_sent << "\tDBName:" << thd->db().str
<< "\tCosttime(ms):" << cost_time << "\tSQL:" << thd->query().str << system::unlock;
<< "\tClientHostName:" << (sctx.host().length ? sctx.host().str : "unknown")
<< "\tClientPort:" << thd->peer_port << "\tUser:" << sctx.user().str << global_serverinfo_
<< "\tAffectRows:" << affect_rows << "\tResultRows:" << rows_sent << "\tDBName:" << thd->db().str
<< "\tCosttime(ms):" << cost_time << "\tSQL:" << thd->query().str << system::unlock;
TIANMU_LOG(LogCtl_Level::DEBUG, "Result: %" PRId64 " Costtime(ms): %" PRId64, rows_sent, cost_time);
}

Expand Down
2 changes: 1 addition & 1 deletion storage/tianmu/core/ftree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#include <fstream>
#include <map>

#include "system/tianmu_system.h"
#include "system/tianmu_file.h"
#include "system/tianmu_system.h"

namespace Tianmu {
namespace core {
Expand Down
Loading

0 comments on commit af9bed4

Please sign in to comment.