Add support for printing out in the ast temporal data values (#227)
This commit is contained in:
parent
738b5fb8d8
commit
da68f86fc9
@ -142,8 +142,8 @@ void PrintObject(std::ostream *out, const storage::PropertyValue &value) {
|
||||
PrintObject(out, value.ValueMap());
|
||||
break;
|
||||
case storage::PropertyValue::Type::TemporalData:
|
||||
// TODO(antonio2368): Print out the temporal data based on the type
|
||||
LOG_FATAL("Not implemented!");
|
||||
PrintObject(out, value.ValueTemporalData());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,10 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <string_view>
|
||||
|
||||
#include "utils/temporal.hpp"
|
||||
|
||||
namespace storage {
|
||||
|
||||
enum class TemporalType : uint8_t { Date = 0, LocalTime, LocalDateTime, Duration };
|
||||
@ -23,7 +26,18 @@ struct TemporalData {
|
||||
explicit TemporalData(TemporalType type, int64_t microseconds);
|
||||
|
||||
auto operator<=>(const TemporalData &) const = default;
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &os, const TemporalData &t) {
|
||||
switch (t.type) {
|
||||
case TemporalType::Date:
|
||||
return os << "DATE(\"" << utils::Date(t.microseconds) << "\")";
|
||||
case TemporalType::LocalTime:
|
||||
return os << "LOCALTIME(\"" << utils::LocalTime(t.microseconds) << "\")";
|
||||
case TemporalType::LocalDateTime:
|
||||
return os << "LOCALDATETIME(\"" << utils::LocalDateTime(t.microseconds) << "\")";
|
||||
case TemporalType::Duration:
|
||||
return os << "DURATION(\"" << utils::Duration(t.microseconds) << "\")";
|
||||
}
|
||||
}
|
||||
TemporalType type;
|
||||
int64_t microseconds;
|
||||
};
|
||||
|
@ -47,6 +47,15 @@ TEST_F(ExpressionPrettyPrinterTest, Literals) {
|
||||
std::map<std::string, storage::PropertyValue> map{{"hello", storage::PropertyValue(1)},
|
||||
{"there", storage::PropertyValue(2)}};
|
||||
EXPECT_EQ(ToString(LITERAL(storage::PropertyValue(map))), "{\"hello\": 1, \"there\": 2}");
|
||||
|
||||
std::vector<storage::PropertyValue> tt_vec{
|
||||
storage::PropertyValue(storage::TemporalData(storage::TemporalType::Duration, 1)),
|
||||
storage::PropertyValue(storage::TemporalData(storage::TemporalType::LocalTime, 2)),
|
||||
storage::PropertyValue(storage::TemporalData(storage::TemporalType::LocalDateTime, 3)),
|
||||
storage::PropertyValue(storage::TemporalData(storage::TemporalType::Date, 4))};
|
||||
EXPECT_EQ(ToString(LITERAL(storage::PropertyValue(tt_vec))),
|
||||
"[DURATION(\"P0000-00-00T00:00:00.000001\"), LOCALTIME(\"00:00:00.000002\"), "
|
||||
"LOCALDATETIME(\"1970-01-01T00:00:00.000003\"), DATE(\"1970-01-01\")]");
|
||||
}
|
||||
|
||||
TEST_F(ExpressionPrettyPrinterTest, Identifiers) {
|
||||
|
Loading…
Reference in New Issue
Block a user