Skip to content

Fix vldbss 2025 CI problems #582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,3 @@ MacroBlockBegin: "
END_CATCH_ERROR$"
...


4 changes: 2 additions & 2 deletions src/observer/common/type/attr_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ enum class AttrType

const char *attr_type_to_string(AttrType type);
AttrType attr_type_from_string(const char *s);
bool is_numerical_type(AttrType type);
bool is_string_type(AttrType type);
bool is_numerical_type(AttrType type);
bool is_string_type(AttrType type);
158 changes: 69 additions & 89 deletions src/observer/common/type/string_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,111 +14,91 @@ See the Mulan PSL v2 for more details. */
#include <cstring>

using namespace std;
struct string_t {
struct string_t
{
public:
static constexpr int INLINE_LENGTH = 12;
static constexpr int INLINE_LENGTH = 12;

string_t() = default;
string_t() = default;

explicit string_t(uint32_t len) {
value.inlined.length = len;
}
explicit string_t(uint32_t len) { value.inlined.length = len; }

string_t(const char *data, uint32_t len) {
init(data, len);
}
string_t(const char *data, uint32_t len) { init(data, len); }

~string_t()
{
reset();
}
~string_t() { reset(); }

void init(const char *data, uint32_t len) {
void init(const char *data, uint32_t len)
{
value.inlined.length = len;
if (is_inlined()) {
memset(value.inlined.inlined, 0, INLINE_LENGTH);
if (size() == 0) {
return;
}
memcpy(value.inlined.inlined, data, size());
} else {
value.pointer.ptr = (char *)data;
}
if (is_inlined()) {
memset(value.inlined.inlined, 0, INLINE_LENGTH);
if (size() == 0) {
return;
}
memcpy(value.inlined.inlined, data, size());
} else {
value.pointer.ptr = (char *)data;
}
}

void reset() {
void reset()
{
if (is_inlined()) {
memset(value.inlined.inlined, 0, INLINE_LENGTH);
} else {
value.pointer.ptr = nullptr;
}
memset(value.inlined.inlined, 0, INLINE_LENGTH);
} else {
value.pointer.ptr = nullptr;
}
value.inlined.length = 0;
}

string_t(const char *data)
: string_t(data, strlen(data)) {
}
string_t(const string &value)
: string_t(value.c_str(), value.size()) {
}

bool is_inlined() const {
return size() <= INLINE_LENGTH;
}

const char *data() const {
return is_inlined() ? value.inlined.inlined : value.pointer.ptr;
}

char *get_data_writeable() const {
return is_inlined() ? (char *)value.inlined.inlined : value.pointer.ptr;
}

int size() const {
return value.inlined.length;
}

bool empty() const {
return value.inlined.length == 0;
}

string get_string() const {
return string(data(), size());
}

bool operator==(const string_t &r) const {
if (this->size() != r.size()) {
return false;
}
return (memcmp(this->data(), r.data(), this->size()) == 0);
}

bool operator!=(const string_t &r) const {
return !(*this == r);
}

bool operator>(const string_t &r) const {
const uint32_t left_length = this->size();
string_t(const char *data) : string_t(data, strlen(data)) {}
string_t(const string &value) : string_t(value.c_str(), value.size()) {}

bool is_inlined() const { return size() <= INLINE_LENGTH; }

const char *data() const { return is_inlined() ? value.inlined.inlined : value.pointer.ptr; }

char *get_data_writeable() const { return is_inlined() ? (char *)value.inlined.inlined : value.pointer.ptr; }

int size() const { return value.inlined.length; }

bool empty() const { return value.inlined.length == 0; }

string get_string() const { return string(data(), size()); }

bool operator==(const string_t &r) const
{
if (this->size() != r.size()) {
return false;
}
return (memcmp(this->data(), r.data(), this->size()) == 0);
}

bool operator!=(const string_t &r) const { return !(*this == r); }

bool operator>(const string_t &r) const
{
const uint32_t left_length = this->size();
const uint32_t right_length = r.size();
const uint32_t min_length = std::min<uint32_t>(left_length, right_length);
const uint32_t min_length = std::min<uint32_t>(left_length, right_length);

auto memcmp_res = memcmp(this->data(), r.data(), min_length);
return memcmp_res > 0 || (memcmp_res == 0 && left_length > right_length);
}
bool operator<(const string_t &r) const { return r > *this; }

}
bool operator<(const string_t &r) const {
return r > *this;
}

struct Inlined {
uint32_t length;
char inlined[12];
};
union {
struct {
uint32_t length;
char *ptr;
} pointer;
Inlined inlined;
} value;
struct Inlined
{
uint32_t length;
char inlined[12];
};
union
{
struct
{
uint32_t length;
char *ptr;
} pointer;
Inlined inlined;
} value;
};
2 changes: 1 addition & 1 deletion src/observer/common/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Value final
explicit Value(float val);
explicit Value(bool val);
explicit Value(const char *s, int len = 0);
explicit Value(const string_t& val);
explicit Value(const string_t &val);

Value(const Value &other);
Value(Value &&other);
Expand Down
7 changes: 3 additions & 4 deletions src/observer/sql/expr/aggregate_hash_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AggregateHashTable
*/
virtual RC next(Chunk &chunk) = 0;

virtual void close_scan(){};
virtual void close_scan() {}

protected:
AggregateHashTable *hash_table_;
Expand Down Expand Up @@ -65,7 +65,7 @@ class StandardAggregateHashTable : public AggregateHashTable
};

public:
using StandardHashTable = unordered_map<vector<Value>, vector<void*>, VectorHash, VectorEqual>;
using StandardHashTable = unordered_map<vector<Value>, vector<void *>, VectorHash, VectorEqual>;
class Scanner : public AggregateHashTable::Scanner
{
public:
Expand Down Expand Up @@ -98,14 +98,13 @@ class StandardAggregateHashTable : public AggregateHashTable
}
}


RC add_chunk(Chunk &groups_chunk, Chunk &aggrs_chunk) override;

StandardHashTable::iterator begin() { return aggr_values_.begin(); }
StandardHashTable::iterator end() { return aggr_values_.end(); }

/// group by values -> aggregate values
StandardHashTable aggr_values_;
StandardHashTable aggr_values_;
};

/**
Expand Down
23 changes: 8 additions & 15 deletions src/observer/sql/expr/aggregate_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ class SumState
SumState() : value(0) {}
T value;
void update(const T *values, int size);
void update(const T &value)
{
this->value += value;
}
void update(const T &value) { this->value += value; }
template <class U>
U finalize()
{
Expand All @@ -33,12 +30,9 @@ class CountState
{
public:
CountState() : value(0) {}
int value;
int value;
void update(const T *values, int size);
void update(const T &value)
{
this->value++;
}
void update(const T &value) { this->value++; }
template <class U>
U finalize()
{
Expand All @@ -50,7 +44,7 @@ template <class T>
class AvgState
{
public:
AvgState() : value(0),count(0) {}
AvgState() : value(0), count(0) {}
T value;
int count = 0;
void update(const T *values, int size);
Expand All @@ -64,12 +58,11 @@ class AvgState
{
return (U)((float)value / (float)count);
}

};

void* create_aggregate_state(AggregateExpr::Type aggr_type, AttrType attr_type);
void *create_aggregate_state(AggregateExpr::Type aggr_type, AttrType attr_type);

RC aggregate_state_update_by_value(void *state, AggregateExpr::Type aggr_type, AttrType attr_type, const Value& val);
RC aggregate_state_update_by_column(void *state, AggregateExpr::Type aggr_type, AttrType attr_type, Column& col);
RC aggregate_state_update_by_value(void *state, AggregateExpr::Type aggr_type, AttrType attr_type, const Value &val);
RC aggregate_state_update_by_column(void *state, AggregateExpr::Type aggr_type, AttrType attr_type, Column &col);

RC finialize_aggregate_state(void *state, AggregateExpr::Type aggr_type, AttrType attr_type, Column& col);
RC finialize_aggregate_state(void *state, AggregateExpr::Type aggr_type, AttrType attr_type, Column &col);
2 changes: 1 addition & 1 deletion src/observer/sql/expr/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ RC ValueExpr::get_value(const Tuple &tuple, Value &value) const

RC ValueExpr::get_column(Chunk &chunk, Column &column)
{
column.init(value_, chunk.rows());
column.init(value_, std::max(chunk.rows(), 1));
return RC::SUCCESS;
}

Expand Down
11 changes: 5 additions & 6 deletions src/observer/sql/expr/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,7 @@ class ArithmeticExpr : public Expression
ExprType type() const override { return ExprType::ARITHMETIC; }

AttrType value_type() const override;
int value_length() const override
{
return std::max(left_->value_length(), right_ ? right_->value_length() : 0);
};
int value_length() const override { return std::max(left_->value_length(), right_ ? right_->value_length() : 0); };

RC get_value(const Tuple &tuple, Value &value) const override;

Expand Down Expand Up @@ -491,7 +488,8 @@ class AggregateExpr : public Expression

ExprType type() const override { return ExprType::AGGREGATION; }

AttrType value_type() const override {
AttrType value_type() const override
{
if (aggregate_type_ == Type::COUNT) {
return AttrType::INTS;
} else if (aggregate_type_ == Type::AVG) {
Expand All @@ -500,7 +498,8 @@ class AggregateExpr : public Expression
return child_->value_type();
}
}
int value_length() const override {
int value_length() const override
{
if (aggregate_type_ == Type::COUNT) {
return sizeof(int);
} else if (aggregate_type_ == Type::AVG) {
Expand Down
2 changes: 1 addition & 1 deletion src/observer/sql/parser/parse_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ struct LoadDataSqlNode
string relation_name;
string file_name;
string terminated = ",";
string enclosed = "\"";
string enclosed = "\"";
};

/**
Expand Down
14 changes: 7 additions & 7 deletions src/observer/sql/stmt/load_data_stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ class Table;
class LoadDataStmt : public Stmt
{
public:
LoadDataStmt(Table *table, const char *filename,
const char terminated, const char enclosed)
: table_(table), filename_(filename), terminated_(terminated), enclosed_(enclosed) {}
LoadDataStmt(Table *table, const char *filename, const char terminated, const char enclosed)
: table_(table), filename_(filename), terminated_(terminated), enclosed_(enclosed)
{}
virtual ~LoadDataStmt() = default;

StmtType type() const override { return StmtType::LOAD_DATA; }

Table *table() const { return table_; }
const char *filename() const { return filename_.c_str(); }
const char terminated() const { return terminated_; }
const char enclosed() const { return enclosed_; }
const char terminated() const { return terminated_; }
const char enclosed() const { return enclosed_; }

static RC create(Db *db, const LoadDataSqlNode &load_data, Stmt *&stmt);

private:
Table *table_ = nullptr;
string filename_;
char terminated_;
char enclosed_;
char terminated_;
char enclosed_;
};
3 changes: 2 additions & 1 deletion src/observer/storage/buffer/disk_buffer_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ struct BPFileHeader
/**
* 能够分配的最大的页面个数,即bitmap的字节数 乘以8
*/
static const int MAX_PAGE_NUM = (BP_PAGE_DATA_SIZE - sizeof(buffer_pool_id) - sizeof(page_count) - sizeof(allocated_pages)) * 8;
static const int MAX_PAGE_NUM =
(BP_PAGE_DATA_SIZE - sizeof(buffer_pool_id) - sizeof(page_count) - sizeof(allocated_pages)) * 8;

string to_string() const;
};
Expand Down
Loading