diff --git a/flex/codegen/src/graph_types.h b/flex/codegen/src/graph_types.h index e38c5d3697f8..1688cc21e936 100644 --- a/flex/codegen/src/graph_types.h +++ b/flex/codegen/src/graph_types.h @@ -113,6 +113,8 @@ static std::string single_common_data_type_pb_2_str( return "std::vector"; case common::DataType::DATE32: return "Date"; + case common::DataType::TIMESTAMP: + return "TimeStamp"; // TODO: support time32 and timestamp default: throw std::runtime_error( @@ -196,6 +198,8 @@ static std::string data_type_2_string(const codegen::DataType& data_type) { 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: diff --git a/flex/engines/graph_db/database/transaction_utils.h b/flex/engines/graph_db/database/transaction_utils.h index df8af78d2e22..333793849f30 100644 --- a/flex/engines/graph_db/database/transaction_utils.h +++ b/flex/engines/graph_db/database/transaction_utils.h @@ -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; @@ -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); diff --git a/flex/engines/hqps_db/core/null_record.h b/flex/engines/hqps_db/core/null_record.h index bfb298492cd8..6efe97d9072e 100644 --- a/flex/engines/hqps_db/core/null_record.h +++ b/flex/engines/hqps_db/core/null_record.h @@ -44,10 +44,19 @@ struct NullRecordCreator { static inline std::string_view GetNull() { return ""; } }; +template <> +struct NullRecordCreator { + static inline TimeStamp GetNull() { + return TimeStamp(std::numeric_limits::max()); + } +}; + template <> struct NullRecordCreator { static inline Date GetNull() { - return Date(std::numeric_limits::max()); + Date date; + date.from_u32(std::numeric_limits::max()); + return date; } }; diff --git a/flex/engines/hqps_db/core/operator/sink.h b/flex/engines/hqps_db/core/operator/sink.h index 36b6816b86d8..0b2f959dac7c 100644 --- a/flex/engines/hqps_db/core/operator/sink.h +++ b/flex/engines/hqps_db/core/operator/sink.h @@ -145,10 +145,16 @@ void template_set_value(common::Value* value, T v) { value->set_f64(v); } +template )>::type* = nullptr> +void template_set_value(common::Value* value, gs::TimeStamp v) { + value->set_i64(v.milli_second); +} + template )>::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 @@ -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(), @@ -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()); @@ -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& value) { + const std::tuple& value) { auto prop = edge->add_properties(); prop->mutable_value()->set_i64(std::get<0>(value).milli_second); prop->mutable_key()->set_name(prop_name); diff --git a/flex/engines/hqps_db/core/params.h b/flex/engines/hqps_db/core/params.h index 291edece1e07..0bfdf3de4df2 100644 --- a/flex/engines/hqps_db/core/params.h +++ b/flex/engines/hqps_db/core/params.h @@ -385,41 +385,47 @@ enum Interval { template struct DateTimeExtractor; -// Extract Year, month, day, hour, minute, second from Date +// Extract Year, month, day, hour, minute, second from TimeStamp template <> struct DateTimeExtractor { - 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*) (µ_second), &tm); return tm.tm_year + 1900; } + + static int32_t extract(const Date& date) { return date.year(); } }; template <> struct DateTimeExtractor { - 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*) (µ_second), &tm); return tm.tm_mon + 1; } + + static int32_t extract(const Date& date) { return date.month(); } }; template <> struct DateTimeExtractor { - 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*) (µ_second), &tm); return tm.tm_mday; } + + static int32_t extract(const Date& date) { return date.day(); } }; template <> struct DateTimeExtractor { - 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*) (µ_second), &tm); @@ -429,7 +435,7 @@ struct DateTimeExtractor { template <> struct DateTimeExtractor { - 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*) (µ_second), &tm); @@ -439,7 +445,7 @@ struct DateTimeExtractor { template <> struct DateTimeExtractor { - 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*) (µ_second), &tm); diff --git a/flex/engines/hqps_db/core/utils/hqps_utils.h b/flex/engines/hqps_db/core/utils/hqps_utils.h index 6aed619e8978..d65a4ec944da 100644 --- a/flex/engines/hqps_db/core/utils/hqps_utils.h +++ b/flex/engines/hqps_db/core/utils/hqps_utils.h @@ -780,8 +780,8 @@ struct to_string_impl { }; template <> -struct to_string_impl { - static inline std::string to_string(const Date& empty) { +struct to_string_impl { + static inline std::string to_string(const TimeStamp& empty) { return std::to_string(empty.milli_second); } }; diff --git a/flex/engines/hqps_db/database/mutable_csr_interface.h b/flex/engines/hqps_db/database/mutable_csr_interface.h index 770831dde9b3..f0194387e4c6 100644 --- a/flex/engines/hqps_db/database/mutable_csr_interface.h +++ b/flex/engines/hqps_db/database/mutable_csr_interface.h @@ -880,15 +880,18 @@ class MutableCSRInterface { } else if (type == PropertyType::kUInt64) { return std::make_shared>( *std::dynamic_pointer_cast>(column)); - } else if (type == PropertyType::kDate) { - return std::make_shared>( - *std::dynamic_pointer_cast>(column)); + } else if (type == PropertyType::kTimeStamp) { + return std::make_shared>( + *std::dynamic_pointer_cast>(column)); } else if (type == PropertyType::kString) { return std::make_shared>( *std::dynamic_pointer_cast>(column)); } else if (type == PropertyType::kFloat) { return std::make_shared>( *std::dynamic_pointer_cast>(column)); + } else if (type == PropertyType::kDate) { + return std::make_shared>( + *std::dynamic_pointer_cast>(column)); } else { LOG(FATAL) << "unexpected type to create column, " << static_cast(type.type_enum); diff --git a/flex/storages/rt_mutable_graph/csr/mutable_csr.cc b/flex/storages/rt_mutable_graph/csr/mutable_csr.cc index 3949cd80f789..179f265b3264 100644 --- a/flex/storages/rt_mutable_graph/csr/mutable_csr.cc +++ b/flex/storages/rt_mutable_graph/csr/mutable_csr.cc @@ -32,8 +32,8 @@ template class MutableCsr; template class SingleMutableCsr; template class MutableCsr; -template class SingleMutableCsr; -template class MutableCsr; +template class SingleMutableCsr; +template class MutableCsr; template class SingleMutableCsr; template class MutableCsr; diff --git a/flex/storages/rt_mutable_graph/csr/nbr.h b/flex/storages/rt_mutable_graph/csr/nbr.h index 83cfbaec544a..4e4fd0941201 100644 --- a/flex/storages/rt_mutable_graph/csr/nbr.h +++ b/flex/storages/rt_mutable_graph/csr/nbr.h @@ -50,7 +50,7 @@ struct ImmutableNbr { }; template <> -struct __attribute__((packed)) ImmutableNbr { +struct __attribute__((packed)) ImmutableNbr { ImmutableNbr() = default; ImmutableNbr(const ImmutableNbr& rhs) : neighbor(rhs.neighbor), data(rhs.data) {} @@ -62,16 +62,16 @@ struct __attribute__((packed)) ImmutableNbr { 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::max(); } vid_t neighbor; - Date data; + TimeStamp data; }; template <> diff --git a/flex/storages/rt_mutable_graph/loader/abstract_arrow_fragment_loader.cc b/flex/storages/rt_mutable_graph/loader/abstract_arrow_fragment_loader.cc index dacaeef99c88..cb93333850a0 100644 --- a/flex/storages/rt_mutable_graph/loader/abstract_arrow_fragment_loader.cc +++ b/flex/storages/rt_mutable_graph/loader/abstract_arrow_fragment_loader.cc @@ -82,10 +82,10 @@ void set_vertex_properties(gs::ColumnBase* col, set_single_vertex_column(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 { @@ -104,8 +104,9 @@ void set_vertex_column_from_timestamp_array( auto casted = std::static_pointer_cast(array->chunk(j)); for (auto k = 0; k < casted->length(); ++k) { - col->set_any(vids[cur_ind++], - std::move(AnyConverter::to_any(casted->Value(k)))); + col->set_any( + vids[cur_ind++], + std::move(AnyConverter::to_any(casted->Value(k)))); } } } else { @@ -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 array, const std::vector& vids) { auto type = array->type(); @@ -126,7 +127,7 @@ void set_vertex_column_from_timestamp_array_to_day( std::static_pointer_cast(array->chunk(j)); for (auto k = 0; k < casted->length(); ++k) { col->set_any(vids[cur_ind++], - std::move(AnyConverter::to_any(casted->Value(k)))); + std::move(AnyConverter::to_any(casted->Value(k)))); } } } else { @@ -247,13 +248,13 @@ void AbstractArrowFragmentLoader::AddEdgesRecordBatch( addEdgesRecordBatchImpl(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(src_label_i, dst_label_i, - edge_label_i); + basic_fragment_loader_.AddNoPropEdgeBatch( + src_label_i, dst_label_i, edge_label_i); } else { - addEdgesRecordBatchImpl(src_label_i, dst_label_i, edge_label_i, - filenames, supplier_creator); + addEdgesRecordBatchImpl(src_label_i, dst_label_i, edge_label_i, + filenames, supplier_creator); } } else if (property_types[0] == PropertyType::kInt32) { if (filenames.empty()) { diff --git a/flex/storages/rt_mutable_graph/loader/abstract_arrow_fragment_loader.h b/flex/storages/rt_mutable_graph/loader/abstract_arrow_fragment_loader.h index 53f7ddb770ae..d315610e2d8d 100644 --- a/flex/storages/rt_mutable_graph/loader/abstract_arrow_fragment_loader.h +++ b/flex/storages/rt_mutable_graph/loader/abstract_arrow_fragment_loader.h @@ -69,7 +69,7 @@ void set_vertex_column_from_timestamp_array( gs::ColumnBase* col, std::shared_ptr array, const std::vector& 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 array, const std::vector& vids); diff --git a/flex/storages/rt_mutable_graph/mutable_property_fragment.cc b/flex/storages/rt_mutable_graph/mutable_property_fragment.cc index de2696eea769..84fff6d5a17c 100644 --- a/flex/storages/rt_mutable_graph/mutable_property_fragment.cc +++ b/flex/storages/rt_mutable_graph/mutable_property_fragment.cc @@ -88,7 +88,7 @@ inline DualCsrBase* create_csr(EdgeStrategy oes, EdgeStrategy ies, } else if (properties[0] == PropertyType::kUInt32) { return new DualCsr(oes, ies, oe_mutable, ie_mutable); } else if (properties[0] == PropertyType::kDate) { - return new DualCsr(oes, ies, oe_mutable, ie_mutable); + return new DualCsr(oes, ies, oe_mutable, ie_mutable); } else if (properties[0] == PropertyType::kInt64) { return new DualCsr(oes, ies, oe_mutable, ie_mutable); } else if (properties[0] == PropertyType::kUInt64) { diff --git a/flex/storages/rt_mutable_graph/schema.cc b/flex/storages/rt_mutable_graph/schema.cc index 13a80300b944..c11bc1c63ae8 100644 --- a/flex/storages/rt_mutable_graph/schema.cc +++ b/flex/storages/rt_mutable_graph/schema.cc @@ -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) { @@ -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); @@ -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(); - prop_type_str = DT_DATE; + prop_type_str = DT_TIMESTAMP; } else if (node["day"]) { auto format = node["day"].as(); - prop_type_str = DT_DAY; + prop_type_str = DT_DATE; } else { return false; } diff --git a/flex/storages/rt_mutable_graph/types.h b/flex/storages/rt_mutable_graph/types.h index 31cfb370b329..d5340a6a4cea 100644 --- a/flex/storages/rt_mutable_graph/types.h +++ b/flex/storages/rt_mutable_graph/types.h @@ -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 diff --git a/flex/tests/hqps/match_query.h b/flex/tests/hqps/match_query.h index bb6de8d169db..acd39b435f13 100644 --- a/flex/tests/hqps/match_query.h +++ b/flex/tests/hqps/match_query.h @@ -835,7 +835,7 @@ struct MatchQuery13Expr0 { using result_t = bool; MatchQuery13Expr0() {} - inline auto operator()(Date var0) const { + inline auto operator()(TimeStamp var0) const { return gs::DateTimeExtractor::extract(var0) == 7; } @@ -847,7 +847,7 @@ struct MatchQuery13Expr1 { using result_t = int64_t; MatchQuery13Expr1() {} - inline auto operator()(Date var1) const { + inline auto operator()(TimeStamp var1) const { return gs::DateTimeExtractor::extract(var1); } @@ -868,16 +868,16 @@ class MatchQuery13 : public AppBase { auto ctx1 = Engine::Project( graph, std::move(ctx0), std::tuple{gs::make_mapper_with_variable( - gs::PropertySelector("birthday"))}); + gs::PropertySelector("birthday"))}); auto expr0 = gs::make_filter(MatchQuery13Expr0(), - gs::PropertySelector("None")); + gs::PropertySelector("None")); auto ctx2 = Engine::template Select(graph, std::move(ctx1), std::move(expr0)); auto ctx3 = Engine::Project( graph, std::move(ctx2), std::tuple{gs::make_mapper_with_expr<0>( - MatchQuery13Expr1(), gs::PropertySelector("None"))}); + MatchQuery13Expr1(), gs::PropertySelector("None"))}); return Engine::Sink(graph, ctx3, std::array{2}); } // Wrapper query function for query class diff --git a/flex/utils/arrow_utils.cc b/flex/utils/arrow_utils.cc index 220f96881f1c..0cc23df99b10 100644 --- a/flex/utils/arrow_utils.cc +++ b/flex/utils/arrow_utils.cc @@ -30,9 +30,9 @@ std::shared_ptr PropertyTypeToArrowType(PropertyType type) { return arrow::float64(); } else if (type == PropertyType::Float()) { return arrow::float32(); - } else if (type == PropertyType::Date()) { + } else if (type == PropertyType::TimeStamp()) { return arrow::timestamp(arrow::TimeUnit::MILLI); - } else if (type == PropertyType::Day()) { + } else if (type == PropertyType::Date()) { return arrow::timestamp(arrow::TimeUnit::MILLI); } else if (type == PropertyType::String()) { return arrow::large_utf8(); diff --git a/flex/utils/arrow_utils.h b/flex/utils/arrow_utils.h index d17c00629136..7a049ac995a1 100644 --- a/flex/utils/arrow_utils.h +++ b/flex/utils/arrow_utils.h @@ -179,7 +179,8 @@ class LDBCLongDateParser : public arrow::TimestampParser { const char* format() const override { return "LongDateFormat"; } }; -// convert c++ type to arrow type. support other types likes emptyType, Date +// convert c++ type to arrow type. support other types likes emptyType, +// TimeStamp template struct TypeConverter; @@ -273,7 +274,7 @@ struct TypeConverter { }; template <> -struct TypeConverter { +struct TypeConverter { static PropertyType property_type() { return PropertyType::kDate; } using ArrowType = arrow::TimestampType; using ArrowArrayType = arrow::TimestampArray; @@ -283,8 +284,8 @@ struct TypeConverter { }; template <> -struct TypeConverter { - static PropertyType property_type() { return PropertyType::kDay; } +struct TypeConverter { + static PropertyType property_type() { return PropertyType::kDate; } using ArrowType = arrow::TimestampType; using ArrowArrayType = arrow::TimestampArray; static std::shared_ptr ArrowTypeValue() { diff --git a/flex/utils/property/column.cc b/flex/utils/property/column.cc index 5c09ad7fcc96..43e0472230b8 100644 --- a/flex/utils/property/column.cc +++ b/flex/utils/property/column.cc @@ -102,8 +102,8 @@ using IntEmptyColumn = TypedEmptyColumn; using UIntEmptyColumn = TypedEmptyColumn; using LongEmptyColumn = TypedEmptyColumn; using ULongEmptyColumn = TypedEmptyColumn; +using TimeStampEmptyColumn = TypedEmptyColumn; using DateEmptyColumn = TypedEmptyColumn; -using DayEmptyColumn = TypedEmptyColumn; using BoolEmptyColumn = TypedEmptyColumn; using FloatEmptyColumn = TypedEmptyColumn; using DoubleEmptyColumn = TypedEmptyColumn; @@ -128,8 +128,8 @@ std::shared_ptr CreateColumn(PropertyType type, return std::make_shared(); } else if (type == PropertyType::kDate) { return std::make_shared(); - } else if (type == PropertyType::kDay) { - return std::make_shared(); + } else if (type == PropertyType::kTimeStamp) { + return std::make_shared(); } else if (type == PropertyType::kStringMap) { return std::make_shared(); } else if (type.type_enum == impl::PropertyTypeImpl::kVarChar) { @@ -157,8 +157,8 @@ std::shared_ptr CreateColumn(PropertyType type, return std::make_shared(strategy); } else if (type == PropertyType::kDate) { return std::make_shared(strategy); - } else if (type == PropertyType::kDay) { - return std::make_shared(strategy); + } else if (type == PropertyType::kTimeStamp) { + return std::make_shared(strategy); } else if (type == PropertyType::kStringMap) { return std::make_shared>(strategy); } else if (type == PropertyType::kString) { diff --git a/flex/utils/property/column.h b/flex/utils/property/column.h index 85d27e4f765e..d48fd5c087f9 100644 --- a/flex/utils/property/column.h +++ b/flex/utils/property/column.h @@ -227,7 +227,7 @@ using UIntColumn = TypedColumn; using LongColumn = TypedColumn; using ULongColumn = TypedColumn; using DateColumn = TypedColumn; -using DayColumn = TypedColumn; +using TimeStampColumn = TypedColumn; using DoubleColumn = TypedColumn; using FloatColumn = TypedColumn; diff --git a/flex/utils/property/types.cc b/flex/utils/property/types.cc index 4ffc33ad1169..3d1cd97b1003 100644 --- a/flex/utils/property/types.cc +++ b/flex/utils/property/types.cc @@ -42,8 +42,8 @@ const PropertyType PropertyType::kDouble = PropertyType(impl::PropertyTypeImpl::kDouble); const PropertyType PropertyType::kDate = PropertyType(impl::PropertyTypeImpl::kDate); -const PropertyType PropertyType::kDay = - PropertyType(impl::PropertyTypeImpl::kDay); +const PropertyType PropertyType::kTimeStamp = + PropertyType(impl::PropertyTypeImpl::kTimeStamp); const PropertyType PropertyType::kString = PropertyType(impl::PropertyTypeImpl::kString); const PropertyType PropertyType::kStringMap = @@ -108,12 +108,12 @@ PropertyType PropertyType::UInt64() { PropertyType PropertyType::Double() { return PropertyType(impl::PropertyTypeImpl::kDouble); } +PropertyType PropertyType::TimeStamp() { + return PropertyType(impl::PropertyTypeImpl::kTimeStamp); +} PropertyType PropertyType::Date() { return PropertyType(impl::PropertyTypeImpl::kDate); } -PropertyType PropertyType::Day() { - return PropertyType(impl::PropertyTypeImpl::kDay); -} PropertyType PropertyType::String() { return PropertyType(impl::PropertyTypeImpl::kString); } @@ -170,9 +170,9 @@ grape::InArchive& operator<<(grape::InArchive& in_archive, const Any& value) { in_archive << value.type << value.value.ul; } else if (value.type == PropertyType::Double()) { in_archive << value.type << value.value.db; - } else if (value.type == PropertyType::Date()) { + } else if (value.type == PropertyType::TimeStamp()) { in_archive << value.type << value.value.d.milli_second; - } else if (value.type == PropertyType::Day()) { + } else if (value.type == PropertyType::Date()) { in_archive << value.type << value.value.day.to_u32(); } else if (value.type == PropertyType::String()) { in_archive << value.type << value.value.s; @@ -208,11 +208,11 @@ grape::OutArchive& operator>>(grape::OutArchive& out_archive, Any& value) { out_archive >> value.value.ul; } else if (value.type == PropertyType::Double()) { out_archive >> value.value.db; + } else if (value.type == PropertyType::TimeStamp()) { + int64_t ts; + out_archive >> ts; + value.value.d.milli_second = ts; } else if (value.type == PropertyType::Date()) { - int64_t date_val; - out_archive >> date_val; - value.value.d.milli_second = date_val; - } else if (value.type == PropertyType::Day()) { uint32_t val; out_archive >> val; value.value.day.from_u32(val); @@ -291,28 +291,27 @@ GlobalId::vid_t GlobalId::vid() const { std::string GlobalId::to_string() const { return std::to_string(global_id); } -Date::Date(int64_t x) : milli_second(x) {} +TimeStamp::TimeStamp(int64_t x) : milli_second(x) {} -std::string Date::to_string() const { return std::to_string(milli_second); } +std::string TimeStamp::to_string() const { return std::to_string(milli_second); } -Day::Day(int64_t ts) { from_timestamp(ts); } +Date::Date(int64_t ts) { from_timestamp(ts); } -std::string Day::to_string() const { +std::string Date::to_string() const { return std::to_string(static_cast(year())) + "-" + std::to_string(static_cast(month())) + "-" + std::to_string(static_cast(day())); } -uint32_t Day::to_u32() const { return value.integer; } +uint32_t Date::to_u32() const { return value.integer; } -void Day::from_u32(uint32_t val) { value.integer = val; } +void Date::from_u32(uint32_t val) { value.integer = val; } -int Day::year() const { return value.internal.year; } +int Date::year() const { return value.internal.year; } -int Day::month() const { return value.internal.month; } +int Date::month() const { return value.internal.month; } -int Day::day() const { return value.internal.day; } +int Date::day() const { return value.internal.day; } -int Day::hour() const { return value.internal.hour; } } // namespace gs diff --git a/flex/utils/property/types.h b/flex/utils/property/types.h index 8ba27b71053e..426514fe1972 100644 --- a/flex/utils/property/types.h +++ b/flex/utils/property/types.h @@ -48,8 +48,8 @@ namespace impl { enum class PropertyTypeImpl { kInt32, - kDate, - kDay, + kDate, // YYYY-MM-DD + kTimeStamp, // milliseconds since epoch kString, kEmpty, kInt64, @@ -98,8 +98,8 @@ struct PropertyType { static PropertyType Int64(); static PropertyType UInt64(); static PropertyType Double(); + static PropertyType TimeStamp(); static PropertyType Date(); - static PropertyType Day(); static PropertyType String(); static PropertyType StringMap(); static PropertyType Varchar(uint16_t max_length); @@ -117,7 +117,7 @@ struct PropertyType { static const PropertyType kUInt64; static const PropertyType kDouble; static const PropertyType kDate; - static const PropertyType kDay; + static const PropertyType kTimeStamp; static const PropertyType kString; static const PropertyType kStringMap; static const PropertyType kVertexGlobalId; @@ -165,14 +165,14 @@ inline bool operator>(const GlobalId& lhs, const GlobalId& rhs) { return lhs.global_id > rhs.global_id; } -struct __attribute__((packed)) Date { - Date() = default; - ~Date() = default; - Date(int64_t x); +struct __attribute__((packed)) TimeStamp { + TimeStamp() = default; + ~TimeStamp() = default; + TimeStamp(int64_t x); std::string to_string() const; - bool operator<(const Date& rhs) const { + bool operator<(const TimeStamp& rhs) const { return milli_second < rhs.milli_second; } @@ -180,17 +180,16 @@ struct __attribute__((packed)) Date { }; struct DayValue { - uint32_t year : 18; - uint32_t month : 4; - uint32_t day : 5; - uint32_t hour : 5; + uint32_t year : 16; + uint32_t month : 8; + uint32_t day : 8; }; -struct Day { - Day() = default; - ~Day() = default; +struct Date { + Date() = default; + ~Date() = default; - Day(int64_t ts); + Date(int64_t ts); std::string to_string() const; @@ -202,7 +201,7 @@ struct Day { boost::gregorian::date new_date(year(), month(), day()); boost::posix_time::ptime new_time_point( - new_date, boost::posix_time::time_duration(hour(), 0, 0)); + new_date, boost::posix_time::time_duration(0, 0, 0)); boost::posix_time::time_duration diff = new_time_point - epoch; int64_t new_timestamp_sec = diff.total_seconds(); @@ -215,25 +214,24 @@ struct Day { boost::posix_time::ptime time_point = epoch + boost::posix_time::seconds(ts_sec); boost::posix_time::ptime::date_type date = time_point.date(); - boost::posix_time::time_duration td = time_point.time_of_day(); this->value.internal.year = date.year(); this->value.internal.month = date.month().as_number(); this->value.internal.day = date.day(); - this->value.internal.hour = td.hours(); int64_t ts_back = to_timestamp(); CHECK_EQ(ts, ts_back); } - bool operator<(const Day& rhs) const { return this->to_u32() < rhs.to_u32(); } - bool operator==(const Day& rhs) const { + bool operator<(const Date& rhs) const { + return this->to_u32() < rhs.to_u32(); + } + bool operator==(const Date& rhs) const { return this->to_u32() == rhs.to_u32(); } int year() const; int month() const; int day() const; - int hour() const; union { DayValue internal; @@ -261,8 +259,8 @@ union AnyValue { GlobalId vertex_gid; LabelKey label_key; - Date d; - Day day; + TimeStamp d; + Date day; std::string_view s; double db; uint8_t u8; @@ -325,18 +323,18 @@ struct Any { value.label_key = v; } - void set_date(int64_t v) { - type = PropertyType::kDate; + void set_timestamp(int64_t v) { + type = PropertyType::kTimeStamp; value.d.milli_second = v; } - void set_date(Date v) { - type = PropertyType::kDate; + void set_timestamp(TimeStamp v) { + type = PropertyType::kTimeStamp; value.d = v; } - void set_day(Day v) { - type = PropertyType::kDay; + void set_date(Date v) { + type = PropertyType::kDate; value.day = v; } @@ -375,7 +373,7 @@ struct Any { // return value.s.to_string(); } else if (type == PropertyType::kDate) { return value.d.to_string(); - } else if (type == PropertyType::kDay) { + } else if (type == PropertyType::kDate) { return value.day.to_string(); } else if (type == PropertyType::kEmpty) { return "NULL"; @@ -449,13 +447,13 @@ struct Any { return value.s; } - const Date& AsDate() const { + const TimeStamp& AsTimeStamp() const { assert(type == PropertyType::kDate); return value.d; } - const Day& AsDay() const { - assert(type == PropertyType::kDay); + const Date& AsDate() const { + assert(type == PropertyType::kDate); return value.day; } @@ -480,9 +478,9 @@ struct Any { return value.i == other.value.i; } else if (type == PropertyType::kInt64) { return value.l == other.value.l; - } else if (type == PropertyType::kDate) { + } else if (type == PropertyType::kTimeStamp) { return value.d.milli_second == other.value.d.milli_second; - } else if (type == PropertyType::kDay) { + } else if (type == PropertyType::kDate) { return value.day == other.value.day; } else if (type == PropertyType::kString) { return value.s == other.value.s; @@ -521,9 +519,9 @@ struct Any { return value.i < other.value.i; } else if (type == PropertyType::kInt64) { return value.l < other.value.l; - } else if (type == PropertyType::kDate) { + } else if (type == PropertyType::kTimeStamp) { return value.d.milli_second < other.value.d.milli_second; - } else if (type == PropertyType::kDay) { + } else if (type == PropertyType::kDate) { return value.day < other.value.day; } else if (type == PropertyType::kString) { return value.s < other.value.s; @@ -621,17 +619,17 @@ struct ConvertAny { }; template <> -struct ConvertAny { - static void to(const Any& value, Date& out) { +struct ConvertAny { + static void to(const Any& value, TimeStamp& out) { CHECK(value.type == PropertyType::kDate); out = value.value.d; } }; template <> -struct ConvertAny { - static void to(const Any& value, Day& out) { - CHECK(value.type == PropertyType::kDay); +struct ConvertAny { + static void to(const Any& value, Date& out) { + CHECK(value.type == PropertyType::kDate); out = value.value.day; } }; @@ -861,64 +859,66 @@ struct AnyConverter { }; template <> -struct AnyConverter { +struct AnyConverter { static PropertyType type() { return PropertyType::kDate; } - static Any to_any(const Date& value) { + static Any to_any(const TimeStamp& value) { Any ret; - ret.set_date(value); + ret.set_timestamp(value); return ret; } static Any to_any(int64_t value) { Any ret; - ret.set_date(value); + ret.set_timestamp(value); return ret; } - static AnyValue to_any_value(const Date& value) { + static AnyValue to_any_value(const TimeStamp& value) { AnyValue ret; ret.d = value; return ret; } - static const Date& from_any(const Any& value) { + static const TimeStamp& from_any(const Any& value) { CHECK(value.type == PropertyType::kDate); return value.value.d; } - static const Date& from_any_value(const AnyValue& value) { return value.d; } + static const TimeStamp& from_any_value(const AnyValue& value) { + return value.d; + } }; template <> -struct AnyConverter { - static PropertyType type() { return PropertyType::kDay; } +struct AnyConverter { + static PropertyType type() { return PropertyType::kDate; } - static Any to_any(const Day& value) { + static Any to_any(const Date& value) { Any ret; - ret.set_day(value); + ret.set_date(value); return ret; } static Any to_any(int64_t value) { - Day dval(value); + Date dval(value); Any ret; - ret.set_day(dval); + ret.set_date(dval); return ret; } - static AnyValue to_any_value(const Day& value) { + static AnyValue to_any_value(const Date& value) { AnyValue ret; ret.day = value; return ret; } - static const Day& from_any(const Any& value) { - CHECK(value.type == PropertyType::kDay); + static const Date& from_any(const Any& value) { + CHECK(value.type == PropertyType::kDate); return value.value.day; } - static const Day& from_any_value(const AnyValue& value) { return value.day; } + static const Date& from_any_value(const AnyValue& value) { return value.day; } }; template <> @@ -1115,12 +1115,12 @@ inline bool operator!=(const grape::EmptyType& a, const grape::EmptyType& b) { return false; } -inline ostream& operator<<(ostream& os, const gs::Date& dt) { +inline ostream& operator<<(ostream& os, const gs::TimeStamp& dt) { os << dt.to_string(); return os; } -inline ostream& operator<<(ostream& os, const gs::Day& dt) { +inline ostream& operator<<(ostream& os, const gs::Date& dt) { os << dt.to_string(); return os; } @@ -1146,9 +1146,9 @@ inline ostream& operator<<(ostream& os, gs::PropertyType pt) { os << "uint64"; } else if (pt == gs::PropertyType::Double()) { os << "double"; - } else if (pt == gs::PropertyType::Date()) { + } else if (pt == gs::PropertyType::TimeStamp()) { os << "date"; - } else if (pt == gs::PropertyType::Day()) { + } else if (pt == gs::PropertyType::Date()) { os << "day"; } else if (pt == gs::PropertyType::String()) { os << "string";