Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
Mryange committed Oct 6, 2024
1 parent 970717c commit b5672e9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 41 deletions.
21 changes: 11 additions & 10 deletions be/src/olap/rowset/segment_v2/segment_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

// IWYU pragma: no_include <opentelemetry/common/threadlocal.h>
#include "cloud/config.h"
#include "common/cast_set.h"
#include "common/compiler_util.h" // IWYU pragma: keep
#include "common/config.h"
#include "common/logging.h" // LOG
Expand Down Expand Up @@ -74,7 +75,7 @@ namespace doris {
namespace segment_v2 {

using namespace ErrorCode;

#include "common/compile_check_begin.h"
const char* k_segment_magic = "D0R1";
const uint32_t k_segment_magic_length = 4;

Expand Down Expand Up @@ -153,7 +154,7 @@ void SegmentWriter::init_column_meta(ColumnMetaPB* meta, uint32_t column_id,
const TabletColumn& column, TabletSchemaSPtr tablet_schema) {
meta->set_column_id(column_id);
meta->set_type(int(column.type()));
meta->set_length(column.length());
meta->set_length(cast_set<int>(column.length()));
meta->set_encoding(DEFAULT_ENCODING);
meta->set_compression(_opts.compression_type);
meta->set_is_nullable(column.is_nullable());
Expand All @@ -180,7 +181,7 @@ void SegmentWriter::init_column_meta(ColumnMetaPB* meta, uint32_t column_id,

Status SegmentWriter::init() {
std::vector<uint32_t> column_ids;
int column_cnt = _tablet_schema->num_columns();
auto column_cnt = _tablet_schema->num_columns();
for (uint32_t i = 0; i < column_cnt; ++i) {
column_ids.emplace_back(i);
}
Expand Down Expand Up @@ -377,7 +378,7 @@ Status SegmentWriter::append_block_with_variant_subcolumns(vectorized::Block& da
continue;
}
CHECK(entry->data.is_finalized());
int current_column_id = column_id++;
auto current_column_id = cast_set<uint32_t>(column_id++);
TabletColumn tablet_column = generate_column_info(entry);
vectorized::schema_util::inherit_column_attributes(*parent_column, tablet_column,
_flush_schema);
Expand Down Expand Up @@ -471,16 +472,16 @@ Status SegmentWriter::probe_key_for_mow(
RowLocation loc;
// save rowset shared ptr so this rowset wouldn't delete
RowsetSharedPtr rowset;
auto st = _tablet->lookup_row_key(key, _tablet_schema.get(), have_input_seq_column,
specified_rowsets, &loc, _mow_context->max_version,
segment_caches, &rowset);
auto st = _tablet->lookup_row_key(
key, _tablet_schema.get(), have_input_seq_column, specified_rowsets, &loc,
cast_set<uint32_t>(_mow_context->max_version), segment_caches, &rowset);
if (st.is<KEY_NOT_FOUND>()) {
if (_opts.rowset_ctx->partial_update_info->is_strict_mode) {
++stats.num_rows_filtered;
// delete the invalid newly inserted row
_mow_context->delete_bitmap->add(
{_opts.rowset_ctx->rowset_id, _segment_id, DeleteBitmap::TEMP_VERSION_COMMON},
segment_pos);
cast_set<uint32_t>(segment_pos));
} else if (!have_delete_sign) {
RETURN_IF_ERROR(
_opts.rowset_ctx->partial_update_info->handle_non_strict_mode_not_found_error(
Expand Down Expand Up @@ -516,7 +517,7 @@ Status SegmentWriter::probe_key_for_mow(
// for this row, we need to ensure that each column is aligned
_mow_context->delete_bitmap->add(
{_opts.rowset_ctx->rowset_id, _segment_id, DeleteBitmap::TEMP_VERSION_COMMON},
segment_pos);
cast_set<uint32_t>(segment_pos));
++stats.num_rows_deleted;
} else {
_mow_context->delete_bitmap->add(
Expand Down Expand Up @@ -892,7 +893,7 @@ std::string SegmentWriter::_encode_keys(

template <typename RowType>
Status SegmentWriter::append_row(const RowType& row) {
for (size_t cid = 0; cid < _column_writers.size(); ++cid) {
for (uint32_t cid = 0; cid < _column_writers.size(); ++cid) {
auto cell = row.cell(cid);
RETURN_IF_ERROR(_column_writers[cid]->append(cell));
}
Expand Down
2 changes: 1 addition & 1 deletion be/src/util/coding.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ inline uint128_t decode_fixed128_le(const uint8_t* buf) {
}

template <typename T>
void put_fixed32_le(T* dst, uint32_t val) {
void put_fixed32_le(T* dst, uint64_t val) {
uint8_t buf[sizeof(val)];
encode_fixed32_le(buf, val);
dst->append((char*)buf, sizeof(buf));
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/jsonb/serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
namespace doris::vectorized {

void JsonbSerializeUtil::block_to_jsonb(const TabletSchema& schema, const Block& block,
ColumnString& dst, int num_cols,
ColumnString& dst, size_t num_cols,
const DataTypeSerDeSPtrs& serdes,
const std::unordered_set<int32_t>& row_store_cids) {
auto num_rows = block.rows();
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/jsonb/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class JsonbSerializeUtil {
// encode partial columns into jsonb
// empty row_store_cids means encode full schema columns for compability
static void block_to_jsonb(const TabletSchema& schema, const Block& block, ColumnString& dst,
int num_cols, const DataTypeSerDeSPtrs& serdes,
size_t num_cols, const DataTypeSerDeSPtrs& serdes,
const std::unordered_set<int32_t>& row_store_cids);
// batch rows
static void jsonb_to_block(const DataTypeSerDeSPtrs& serdes, const ColumnString& jsonb_column,
Expand Down
2 changes: 2 additions & 0 deletions be/src/vec/runtime/vdatetime_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

namespace doris {

#include "common/compile_check_begin.h"

static const char* s_ab_month_name[] = {"", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec", nullptr};

Expand Down
65 changes: 37 additions & 28 deletions be/src/vec/runtime/vdatetime_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <type_traits>
#include <utility>

#include "common/cast_set.h"
#include "util/hash_util.hpp"
#include "util/time_lut.h"
#include "util/timezone_utils.h"
Expand All @@ -47,7 +48,7 @@ class DataTypeDateTimeV2;
} // namespace doris::vectorized

namespace doris {

#include "common/compile_check_begin.h"
enum TimeUnit {
MICROSECOND,
MILLISECOND,
Expand Down Expand Up @@ -297,15 +298,17 @@ class VecDateTimeValue { // Now this type is a temp solution with little changes
_type = TIME_DATETIME;
uint64_t date = datetime / 1000000;
uint64_t time = datetime % 1000000;

auto [year, month, day, hour, minute, second] = std::tuple {0, 0, 0, 0, 0, 0};
year = date / 10000;
// uint32_t year, uint32_t month, uint32_t day, uint32_t hour,uint32_t minute, uint32_t second
auto [year, month, day, hour, minute, second] =
std::tuple<uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t> {0, 0, 0,
0, 0, 0};
cast_set(year, date / 10000);
date %= 10000;
month = date / 100;
cast_set(month, date / 100);
day = date % 100;
hour = time / 10000;
cast_set(hour, time / 10000);
time %= 10000;
minute = time / 100;
cast_set(minute, time / 100);
second = time % 100;

return check_range_and_set_time(year, month, day, hour, minute, second, _type);
Expand All @@ -320,14 +323,16 @@ class VecDateTimeValue { // Now this type is a temp solution with little changes
bool from_olap_date(uint64_t date) {
_neg = 0;
_type = TIME_DATE;

auto [year, month, day, hour, minute, second] = std::tuple {0, 0, 0, 0, 0, 0};
// uint32_t year, uint32_t month, uint32_t day, uint32_t hour,uint32_t minute, uint32_t second
auto [year, month, day, hour, minute, second] =
std::tuple<uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t> {0, 0, 0,
0, 0, 0};

day = date & 0x1f;
date >>= 5;
month = date & 0x0f;
date >>= 4;
year = date;
cast_set(year, date);

return check_range_and_set_time(year, month, day, hour, minute, second, _type);
}
Expand Down Expand Up @@ -623,7 +628,7 @@ class VecDateTimeValue { // Now this type is a temp solution with little changes

uint32_t hash(int seed) const { return HashUtil::hash(this, sizeof(*this), seed); }

int day_of_year() const { return daynr() - calc_daynr(_year, 1, 1) + 1; }
int64_t day_of_year() const { return daynr() - calc_daynr(_year, 1, 1) + 1; }

// TODO(zhaochun): local time ???
static VecDateTimeValue local_time();
Expand Down Expand Up @@ -786,31 +791,33 @@ class DateV2Value {
void set_microsecond(uint32_t microsecond);

bool from_olap_date(uint64_t date) {
auto [year, month, day] = std::tuple {0, 0, 0};
//uint16_t year, uint8_t month, uint8_t day
auto [year, month, day] = std::tuple<uint16_t, uint8_t, uint8_t> {0, 0, 0};

day = date & 0x1f;
date >>= 5;
month = date & 0x0f;
date >>= 4;
year = date;
cast_set(year, date);

return check_range_and_set_time(year, month, day, 0, 0, 0, 0);
}

bool from_olap_datetime(uint64_t datetime) {
uint64_t date = datetime / 1000000;
uint64_t time = datetime % 1000000;

auto [year, month, day, hour, minute, second] = std::tuple {0, 0, 0, 0, 0, 0};
year = date / 10000;
//uint16_t year, uint8_t month, uint8_t day,uint8_t hour, uint8_t minute, uint8_t second, uint32_t microsecond
auto [year, month, day, hour, minute, second] =
std::tuple<uint16_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t> {0, 0, 0,
0, 0, 0};
cast_set(year, date / 10000);
date %= 10000;
month = date / 100;
day = date % 100;
hour = time / 10000;
cast_set(month, date / 100);
cast_set(day, date % 100);
cast_set(hour, time / 10000);
time %= 10000;
minute = time / 100;
second = time % 100;

cast_set(minute, time / 100);
cast_set(second, time % 100);
return check_range_and_set_time(year, month, day, hour, minute, second, 0);
}

Expand Down Expand Up @@ -1116,7 +1123,7 @@ class DateV2Value {

uint32_t hash(int seed) const { return HashUtil::hash(this, sizeof(*this), seed); }

int day_of_year() const { return daynr() - calc_daynr(this->year(), 1, 1) + 1; }
int64_t day_of_year() const { return daynr() - calc_daynr(this->year(), 1, 1) + 1; }

std::string debug_string() const {
char buf[64];
Expand Down Expand Up @@ -1294,7 +1301,7 @@ class DateV2Value {

void format_datetime(uint32_t* date_v, bool* carry_bits) const;

void set_int_val(uint64_t val) { this->int_val_ = val; }
void set_int_val(underlying_value val) { this->int_val_ = val; }

private:
static uint8_t calc_week(const uint32_t& day_nr, const uint16_t& year, const uint8_t& month,
Expand Down Expand Up @@ -1369,7 +1376,7 @@ int64_t datetime_diff(const VecDateTimeValue& ts_value1, const VecDateTimeValue&
return month;
}
case WEEK: {
int day = ts_value2.daynr() - ts_value1.daynr();
int64_t day = ts_value2.daynr() - ts_value1.daynr();
if (day > 0) {
day -= ts_value2.time_part_diff(ts_value1) < 0;
} else if (day < 0) {
Expand All @@ -1378,7 +1385,7 @@ int64_t datetime_diff(const VecDateTimeValue& ts_value1, const VecDateTimeValue&
return day / 7;
}
case DAY: {
int day = ts_value2.daynr() - ts_value1.daynr();
int64_t day = ts_value2.daynr() - ts_value1.daynr();
if (day > 0) {
day -= ts_value2.time_part_diff(ts_value1) < 0;
} else if (day < 0) {
Expand Down Expand Up @@ -1493,7 +1500,7 @@ int64_t datetime_diff(const DateV2Value<T0>& ts_value1, const DateV2Value<T1>& t
return month;
}
case WEEK: {
int day = ts_value2.daynr() - ts_value1.daynr();
int64_t day = ts_value2.daynr() - ts_value1.daynr();
int64_t ms_diff = ts_value2.time_part_diff_microsecond(ts_value1);
if (day > 0 && ms_diff < 0) {
day--;
Expand All @@ -1503,7 +1510,7 @@ int64_t datetime_diff(const DateV2Value<T0>& ts_value1, const DateV2Value<T1>& t
return day / 7;
}
case DAY: {
int day = ts_value2.daynr() - ts_value1.daynr();
int64_t day = ts_value2.daynr() - ts_value1.daynr();
int64_t ms_diff = ts_value2.time_part_diff_microsecond(ts_value1);
if (day > 0 && ms_diff < 0) {
day--;
Expand Down Expand Up @@ -1634,3 +1641,5 @@ struct std::hash<doris::DateV2Value<doris::DateTimeV2ValueType>> {
return doris::hash_value(v);
}
};

#include "common/compile_check_end.h"

0 comments on commit b5672e9

Please sign in to comment.