Skip to content
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

refactor(interactive): Rename two temporal types, Date and Day to TimeStamp and Date #3726

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions flex/codegen/src/graph_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
return "std::vector<int32_t>";
case common::DataType::DATE32:
return "Date";
case common::DataType::TIMESTAMP:
return "TimeStamp";
// TODO: support time32 and timestamp
default:
throw std::runtime_error(
Expand Down Expand Up @@ -174,43 +176,45 @@
}
}

static std::string data_type_2_string(const codegen::DataType& data_type) {
switch (data_type) {
case codegen::DataType::kInt32:
return "int32_t";
case codegen::DataType::kInt64:
return "int64_t";
case codegen::DataType::kDouble:
return "double";
case codegen::DataType::kString:
return "std::string_view";
case codegen::DataType::kInt64Array:
return "std::vector<int64_t>";
case codegen::DataType::kInt32Array:
return "std::vector<int32_t>";
case codegen::DataType::kBoolean:
return "bool";
case codegen::DataType::kGlobalVertexId:
return GLOBAL_VERTEX_ID_T;
case codegen::DataType::kLength:
return LENGTH_KEY_T;
case codegen::DataType::kEdgeId:
return EDGE_ID_T;
case codegen::DataType::kTimeStamp:
return "TimeStamp";
case codegen::DataType::kDate:
return "Date";
case codegen::DataType::kLabelId:
return "LabelKey";
case codegen::DataType::kEmpty:
return GRAPE_EMPTY_TYPE;
default:
// LOG(FATAL) << "unknown data type" << static_cast<int>(data_type);
throw std::runtime_error(
"unknown data type when convert inner data_type to string: " +
std::to_string(static_cast<int>(data_type)));
}
}

// for different type, generate get_type() call

Check notice on line 217 in flex/codegen/src/graph_types.h

View check run for this annotation

codefactor.io / CodeFactor

flex/codegen/src/graph_types.h#L179-L217

Complex Method
static std::string decode_type_as_str(const codegen::DataType& data_type) {
switch (data_type) {
case codegen::DataType::kInt32:
Expand Down
8 changes: 4 additions & 4 deletions flex/engines/graph_db/database/transaction_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ inline void serialize_field(grape::InArchive& arc, const Any& prop) {
arc << prop.value.i;
} else if (prop.type == PropertyType::UInt32()) {
arc << prop.value.ui;
} else if (prop.type == PropertyType::Date()) {
} else if (prop.type == PropertyType::TimeStamp()) {
arc << prop.value.d.milli_second;
} else if (prop.type == PropertyType::Day()) {
} else if (prop.type == PropertyType::Date()) {
arc << prop.value.day.to_u32();
} else if (prop.type == PropertyType::String()) {
arc << prop.value.s;
Expand All @@ -59,11 +59,11 @@ inline void deserialize_field(grape::OutArchive& arc, Any& prop) {
arc >> prop.value.i;
} else if (prop.type == PropertyType::UInt32()) {
arc >> prop.value.ui;
} else if (prop.type == PropertyType::Date()) {
} else if (prop.type == PropertyType::TimeStamp()) {
int64_t date_val;
arc >> date_val;
prop.value.d.milli_second = date_val;
} else if (prop.type == PropertyType::Day()) {
} else if (prop.type == PropertyType::Date()) {
uint32_t val;
arc >> val;
prop.value.day.from_u32(val);
Expand Down
11 changes: 10 additions & 1 deletion flex/engines/hqps_db/core/null_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,19 @@ struct NullRecordCreator<std::string_view> {
static inline std::string_view GetNull() { return ""; }
};

template <>
struct NullRecordCreator<TimeStamp> {
static inline TimeStamp GetNull() {
return TimeStamp(std::numeric_limits<int64_t>::max());
}
};

template <>
struct NullRecordCreator<Date> {
static inline Date GetNull() {
return Date(std::numeric_limits<int64_t>::max());
Date date;
date.from_u32(std::numeric_limits<int32_t>::max());
return date;
}
};

Expand Down
14 changes: 10 additions & 4 deletions flex/engines/hqps_db/core/operator/sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,16 @@ void template_set_value(common::Value* value, T v) {
value->set_f64(v);
}

template <typename T, typename std::enable_if<
(std::is_same_v<T, gs::TimeStamp>)>::type* = nullptr>
void template_set_value(common::Value* value, gs::TimeStamp v) {
value->set_i64(v.milli_second);
}

template <typename T, typename std::enable_if<
(std::is_same_v<T, gs::Date>)>::type* = nullptr>
void template_set_value(common::Value* value, gs::Date v) {
value->set_i64(v.milli_second);
value->set_i64(v.to_timestamp());
}

template <size_t Is = 0, typename... T>
Expand Down Expand Up @@ -210,7 +216,7 @@ void set_any_to_element(const Any& any, results::Element* element) {
element->mutable_object()->set_f64(any.value.db);
} else if (any.type == PropertyType::Float()) {
element->mutable_object()->set_f64(any.value.f);
} else if (any.type == PropertyType::Date()) {
} else if (any.type == PropertyType::TimeStamp()) {
element->mutable_object()->set_i64(any.value.d.milli_second);
} else if (any.type == PropertyType::String()) {
element->mutable_object()->mutable_str()->assign(any.value.s.data(),
Expand Down Expand Up @@ -258,7 +264,7 @@ void set_any_to_common_value(const Any& any, common::Value* value) {
value->set_f64(any.value.db);
} else if (any.type == PropertyType::Float()) {
value->set_f64(any.value.f);
} else if (any.type == PropertyType::Date()) {
} else if (any.type == PropertyType::TimeStamp()) {
value->set_i64(any.value.d.milli_second);
} else if (any.type == PropertyType::String()) {
value->mutable_str()->assign(any.value.s.data(), any.value.s.size());
Expand Down Expand Up @@ -292,7 +298,7 @@ void set_edge_property(results::Edge* edge, const std::string& prop_name,
}
// set date
void set_edge_property(results::Edge* edge, const std::string& prop_name,
const std::tuple<gs::Date>& value) {
const std::tuple<gs::TimeStamp>& value) {
auto prop = edge->add_properties();
prop->mutable_value()->set_i64(std::get<0>(value).milli_second);
prop->mutable_key()->set_name(prop_name);
Expand Down
20 changes: 13 additions & 7 deletions flex/engines/hqps_db/core/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,41 +385,47 @@ enum Interval {
template <Interval interval>
struct DateTimeExtractor;

// Extract Year, month, day, hour, minute, second from Date
// Extract Year, month, day, hour, minute, second from TimeStamp

template <>
struct DateTimeExtractor<Interval::YEAR> {
static int32_t extract(const Date& date) {
static int32_t extract(const TimeStamp& date) {
auto micro_second = date.milli_second / 1000;
struct tm tm;
gmtime_r((time_t*) (&micro_second), &tm);
return tm.tm_year + 1900;
}

static int32_t extract(const Date& date) { return date.year(); }
};

template <>
struct DateTimeExtractor<Interval::MONTH> {
static int32_t extract(const Date& date) {
static int32_t extract(const TimeStamp& date) {
auto micro_second = date.milli_second / 1000;
struct tm tm;
gmtime_r((time_t*) (&micro_second), &tm);
return tm.tm_mon + 1;
}

static int32_t extract(const Date& date) { return date.month(); }
};

template <>
struct DateTimeExtractor<Interval::DAY> {
static int32_t extract(const Date& date) {
static int32_t extract(const TimeStamp& date) {
auto micro_second = date.milli_second / 1000;
struct tm tm;
gmtime_r((time_t*) (&micro_second), &tm);
return tm.tm_mday;
}

static int32_t extract(const Date& date) { return date.day(); }
};

template <>
struct DateTimeExtractor<Interval::HOUR> {
static int32_t extract(const Date& date) {
static int32_t extract(const TimeStamp& date) {
auto micro_second = date.milli_second / 1000;
struct tm tm;
gmtime_r((time_t*) (&micro_second), &tm);
Expand All @@ -429,7 +435,7 @@ struct DateTimeExtractor<Interval::HOUR> {

template <>
struct DateTimeExtractor<Interval::MINUTE> {
static int32_t extract(const Date& date) {
static int32_t extract(const TimeStamp& date) {
auto micro_second = date.milli_second / 1000;
struct tm tm;
gmtime_r((time_t*) (&micro_second), &tm);
Expand All @@ -439,7 +445,7 @@ struct DateTimeExtractor<Interval::MINUTE> {

template <>
struct DateTimeExtractor<Interval::SECOND> {
static int32_t extract(const Date& date) {
static int32_t extract(const TimeStamp& date) {
auto micro_second = date.milli_second / 1000;
struct tm tm;
gmtime_r((time_t*) (&micro_second), &tm);
Expand Down
4 changes: 2 additions & 2 deletions flex/engines/hqps_db/core/utils/hqps_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,8 @@ struct to_string_impl<Dist> {
};

template <>
struct to_string_impl<Date> {
static inline std::string to_string(const Date& empty) {
struct to_string_impl<TimeStamp> {
static inline std::string to_string(const TimeStamp& empty) {
return std::to_string(empty.milli_second);
}
};
Expand Down
9 changes: 6 additions & 3 deletions flex/engines/hqps_db/database/mutable_csr_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -880,15 +880,18 @@ class MutableCSRInterface {
} else if (type == PropertyType::kUInt64) {
return std::make_shared<TypedRefColumn<uint64_t>>(
*std::dynamic_pointer_cast<TypedColumn<uint64_t>>(column));
} else if (type == PropertyType::kDate) {
return std::make_shared<TypedRefColumn<Date>>(
*std::dynamic_pointer_cast<TypedColumn<Date>>(column));
} else if (type == PropertyType::kTimeStamp) {
return std::make_shared<TypedRefColumn<TimeStamp>>(
*std::dynamic_pointer_cast<TypedColumn<TimeStamp>>(column));
} else if (type == PropertyType::kString) {
return std::make_shared<TypedRefColumn<std::string_view>>(
*std::dynamic_pointer_cast<TypedColumn<std::string_view>>(column));
} else if (type == PropertyType::kFloat) {
return std::make_shared<TypedRefColumn<float>>(
*std::dynamic_pointer_cast<TypedColumn<float>>(column));
} else if (type == PropertyType::kDate) {
return std::make_shared<TypedRefColumn<Date>>(
*std::dynamic_pointer_cast<TypedColumn<Date>>(column));
} else {
LOG(FATAL) << "unexpected type to create column, "
<< static_cast<int>(type.type_enum);
Expand Down
4 changes: 2 additions & 2 deletions flex/storages/rt_mutable_graph/csr/mutable_csr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ template class MutableCsr<int32_t>;
template class SingleMutableCsr<uint32_t>;
template class MutableCsr<uint32_t>;

template class SingleMutableCsr<Date>;
template class MutableCsr<Date>;
template class SingleMutableCsr<TimeStamp>;
template class MutableCsr<TimeStamp>;

template class SingleMutableCsr<int64_t>;
template class MutableCsr<int64_t>;
Expand Down
8 changes: 4 additions & 4 deletions flex/storages/rt_mutable_graph/csr/nbr.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct ImmutableNbr {
};

template <>
struct __attribute__((packed)) ImmutableNbr<Date> {
struct __attribute__((packed)) ImmutableNbr<TimeStamp> {
ImmutableNbr() = default;
ImmutableNbr(const ImmutableNbr& rhs)
: neighbor(rhs.neighbor), data(rhs.data) {}
Expand All @@ -62,16 +62,16 @@ struct __attribute__((packed)) ImmutableNbr<Date> {
return *this;
}

const Date& get_data() const { return data; }
const TimeStamp& get_data() const { return data; }
vid_t get_neighbor() const { return neighbor; }

void set_data(const Date& val) { data = val; }
void set_data(const TimeStamp& val) { data = val; }
void set_neighbor(vid_t neighbor) { this->neighbor = neighbor; }

bool exists() const { return neighbor != std::numeric_limits<vid_t>::max(); }

vid_t neighbor;
Date data;
TimeStamp data;
};

template <>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ void set_vertex_properties(gs::ColumnBase* col,
set_single_vertex_column<float>(col, array, vids);
} else if (col_type == PropertyType::kStringMap) {
set_vertex_column_from_string_array(col, array, vids);
} else if (col_type == PropertyType::kDate) {
} else if (col_type == PropertyType::kTimeStamp) {
set_vertex_column_from_timestamp_array(col, array, vids);
} else if (col_type == PropertyType::kDay) {
set_vertex_column_from_timestamp_array_to_day(col, array, vids);
} else if (col_type == PropertyType::kDate) {
set_vertex_column_from_timestamp_array_to_date(col, array, vids);
} else if (col_type.type_enum == impl::PropertyTypeImpl::kVarChar) {
set_vertex_column_from_string_array(col, array, vids);
} else {
Expand All @@ -104,8 +104,9 @@ void set_vertex_column_from_timestamp_array(
auto casted =
std::static_pointer_cast<arrow::TimestampArray>(array->chunk(j));
for (auto k = 0; k < casted->length(); ++k) {
col->set_any(vids[cur_ind++],
std::move(AnyConverter<Date>::to_any(casted->Value(k))));
col->set_any(
vids[cur_ind++],
std::move(AnyConverter<TimeStamp>::to_any(casted->Value(k))));
}
}
} else {
Expand All @@ -114,7 +115,7 @@ void set_vertex_column_from_timestamp_array(
}
}

void set_vertex_column_from_timestamp_array_to_day(
void set_vertex_column_from_timestamp_array_to_date(
gs::ColumnBase* col, std::shared_ptr<arrow::ChunkedArray> array,
const std::vector<vid_t>& vids) {
auto type = array->type();
Expand All @@ -126,7 +127,7 @@ void set_vertex_column_from_timestamp_array_to_day(
std::static_pointer_cast<arrow::TimestampArray>(array->chunk(j));
for (auto k = 0; k < casted->length(); ++k) {
col->set_any(vids[cur_ind++],
std::move(AnyConverter<Day>::to_any(casted->Value(k))));
std::move(AnyConverter<Date>::to_any(casted->Value(k))));
}
}
} else {
Expand Down Expand Up @@ -247,13 +248,13 @@ void AbstractArrowFragmentLoader::AddEdgesRecordBatch(
addEdgesRecordBatchImpl<bool>(src_label_i, dst_label_i, edge_label_i,
filenames, supplier_creator);
}
} else if (property_types[0] == PropertyType::kDate) {
} else if (property_types[0] == PropertyType::kTimeStamp) {
if (filenames.empty()) {
basic_fragment_loader_.AddNoPropEdgeBatch<Date>(src_label_i, dst_label_i,
edge_label_i);
basic_fragment_loader_.AddNoPropEdgeBatch<TimeStamp>(
src_label_i, dst_label_i, edge_label_i);
} else {
addEdgesRecordBatchImpl<Date>(src_label_i, dst_label_i, edge_label_i,
filenames, supplier_creator);
addEdgesRecordBatchImpl<TimeStamp>(src_label_i, dst_label_i, edge_label_i,
filenames, supplier_creator);
}
} else if (property_types[0] == PropertyType::kInt32) {
if (filenames.empty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void set_vertex_column_from_timestamp_array(
gs::ColumnBase* col, std::shared_ptr<arrow::ChunkedArray> array,
const std::vector<vid_t>& vids);

void set_vertex_column_from_timestamp_array_to_day(
void set_vertex_column_from_timestamp_array_to_date(
gs::ColumnBase* col, std::shared_ptr<arrow::ChunkedArray> array,
const std::vector<vid_t>& vids);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ inline DualCsrBase* create_csr(EdgeStrategy oes, EdgeStrategy ies,
} else if (properties[0] == PropertyType::kUInt32) {
return new DualCsr<uint32_t>(oes, ies, oe_mutable, ie_mutable);
} else if (properties[0] == PropertyType::kDate) {
return new DualCsr<Date>(oes, ies, oe_mutable, ie_mutable);
return new DualCsr<TimeStamp>(oes, ies, oe_mutable, ie_mutable);
} else if (properties[0] == PropertyType::kInt64) {
return new DualCsr<int64_t>(oes, ies, oe_mutable, ie_mutable);
} else if (properties[0] == PropertyType::kUInt64) {
Expand Down
12 changes: 6 additions & 6 deletions flex/storages/rt_mutable_graph/schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ std::string PropertyTypeToString(PropertyType type) {
return DT_BOOL;
} else if (type == PropertyType::kDate) {
return DT_DATE;
} else if (type == PropertyType::kDay) {
return DT_DAY;
} else if (type == PropertyType::kTimeStamp) {
return DT_TIMESTAMP;
} else if (type == PropertyType::kString) {
return DT_STRING;
} else if (type == PropertyType::kStringMap) {
Expand All @@ -470,10 +470,10 @@ PropertyType StringToPropertyType(const std::string& str) {
return PropertyType::kUInt32;
} else if (str == "bool" || str == "BOOL" || str == DT_BOOL) {
return PropertyType::kBool;
} else if (str == "TimeStamp" || str == DT_TIMESTAMP) {
return PropertyType::kTimeStamp;
} else if (str == "Date" || str == DT_DATE) {
return PropertyType::kDate;
} else if (str == "Day" || str == DT_DAY) {
return PropertyType::kDay;
} else if (str == "String" || str == "STRING" || str == DT_STRING) {
// DT_STRING is a alias for VARCHAR(STRING_DEFAULT_MAX_LENGTH);
return PropertyType::Varchar(PropertyType::STRING_DEFAULT_MAX_LENGTH);
Expand Down Expand Up @@ -545,10 +545,10 @@ static bool parse_property_type(YAML::Node node, PropertyType& type) {
return true;
} else if (node["date"]) {
auto format = node["date"].as<std::string>();
prop_type_str = DT_DATE;
prop_type_str = DT_TIMESTAMP;
} else if (node["day"]) {
auto format = node["day"].as<std::string>();
prop_type_str = DT_DAY;
prop_type_str = DT_DATE;
} else {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion flex/storages/rt_mutable_graph/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static constexpr const char* DT_DOUBLE = "DT_DOUBLE";
static constexpr const char* DT_STRING = "DT_STRING";
static constexpr const char* DT_STRINGMAP = "DT_STRINGMAP";
static constexpr const char* DT_DATE = "DT_DATE32";
static constexpr const char* DT_DAY = "DT_DAY32";
static constexpr const char* DT_TIMESTAMP = "TIMESTAMP";

} // namespace gs

Expand Down
Loading
Loading