27 #include "graphar/fwd.h"
28 #include "graphar/macros.h"
81 explicit DataType(Type
id,
const std::string& user_defined_type_name =
"")
84 user_defined_type_name_(user_defined_type_name) {}
86 explicit DataType(Type
id,
const std::shared_ptr<DataType>& child)
87 : id_(
id), child_(std::move(child)), user_defined_type_name_(
"") {}
92 user_defined_type_name_(other.user_defined_type_name_) {}
96 child_(std::move(other.child_)),
97 user_defined_type_name_(std::move(other.user_defined_type_name_)) {}
101 bool Equals(
const DataType& other)
const {
102 return id_ == other.id_ &&
103 user_defined_type_name_ == other.user_defined_type_name_;
106 bool Equals(
const std::shared_ptr<DataType>& other)
const {
110 return Equals(*other.get());
113 const std::shared_ptr<DataType>& value_type()
const {
return child_; }
115 bool operator==(
const DataType& other)
const {
return Equals(other); }
117 bool operator!=(
const DataType& other)
const {
return !Equals(other); }
119 static std::shared_ptr<arrow::DataType> DataTypeToArrowDataType(
120 const std::shared_ptr<DataType>& type);
122 static std::shared_ptr<DataType> ArrowDataTypeToDataType(
123 const std::shared_ptr<arrow::DataType>& type);
125 static std::shared_ptr<DataType> TypeNameToDataType(
const std::string& str);
128 Type
id()
const {
return id_; }
130 std::string ToTypeName()
const;
134 std::shared_ptr<DataType> child_;
135 std::string user_defined_type_name_;
141 using c_type = int64_t;
142 explicit Timestamp(c_type value) : value_(value) {}
144 c_type value()
const {
return value_; }
153 using c_type = int32_t;
154 explicit Date(c_type value) : value_(value) {}
156 c_type value()
const {
return value_; }
163 enum class AdjListType : std::uint8_t {
165 unordered_by_source = 0b00000001,
168 unordered_by_dest = 0b00000010,
170 ordered_by_source = 0b00000100,
173 ordered_by_dest = 0b00001000,
176 constexpr AdjListType operator|(AdjListType lhs, AdjListType rhs) {
177 return static_cast<AdjListType
>(
178 static_cast<std::underlying_type_t<AdjListType>
>(lhs) |
179 static_cast<std::underlying_type_t<AdjListType>
>(rhs));
182 constexpr AdjListType operator&(AdjListType lhs, AdjListType rhs) {
183 return static_cast<AdjListType
>(
184 static_cast<std::underlying_type_t<AdjListType>
>(lhs) &
185 static_cast<std::underlying_type_t<AdjListType>
>(rhs));
188 static inline const char* AdjListTypeToString(AdjListType adj_list_type) {
189 static const std::map<AdjListType, const char*> adj_list2string{
190 {AdjListType::unordered_by_source,
"unordered_by_source"},
191 {AdjListType::unordered_by_dest,
"unordered_by_dest"},
192 {AdjListType::ordered_by_source,
"ordered_by_source"},
193 {AdjListType::ordered_by_dest,
"ordered_by_dest"}};
194 return adj_list2string.at(adj_list_type);
197 static inline AdjListType OrderedAlignedToAdjListType(
198 bool ordered,
const std::string& aligned) {
200 return aligned ==
"src" ? AdjListType::ordered_by_source
201 : AdjListType::ordered_by_dest;
203 return aligned ==
"src" ? AdjListType::unordered_by_source
204 : AdjListType::unordered_by_dest;
207 static inline std::pair<bool, std::string> AdjListTypeToOrderedAligned(
208 AdjListType adj_list_type) {
209 switch (adj_list_type) {
210 case AdjListType::unordered_by_source:
211 return std::make_pair(
false,
"src");
212 case AdjListType::unordered_by_dest:
213 return std::make_pair(
false,
"dst");
214 case AdjListType::ordered_by_source:
215 return std::make_pair(
true,
"src");
216 case AdjListType::ordered_by_dest:
217 return std::make_pair(
true,
"dst");
219 return std::make_pair(
false,
"dst");
223 static inline FileType StringToFileType(
const std::string& str) {
224 static const std::map<std::string, FileType> str2file_type{
225 {
"csv", FileType::CSV},
226 {
"json", FileType::JSON},
227 {
"parquet", FileType::PARQUET},
228 {
"orc", FileType::ORC}};
230 return str2file_type.at(str.c_str());
231 }
catch (
const std::exception& e) {
232 throw std::runtime_error(
"KeyError: " + str);
236 static inline const char* FileTypeToString(FileType file_type) {
237 static const std::map<FileType, const char*> file_type2string{
238 {FileType::CSV,
"csv"},
239 {FileType::JSON,
"json"},
240 {FileType::PARQUET,
"parquet"},
241 {FileType::ORC,
"orc"}};
242 return file_type2string.at(file_type);
The DataType struct to provide enum type for data type and functions to parse data type.