Skip to content

Commit

Permalink
feat(interactive): Import VARCHAR to GraphScope interactive (#3404)
Browse files Browse the repository at this point in the history
Import a new data type `VARCHAR` to GraphScope Interactive.
#3400 
#3405 

0. Use `VARCHAR` in schema. `VARCHAR` is not a primitive type.

The following Representation can be revised.
```yaml
property_type:
  var_char:
    max_length: 128
```



1. Refactor `PropertyType`

Previous `PropertyType` is just a enum.
```c++
enum class PropertyType {
  kEmpty,
  kBool,
  kUInt8,
  kUInt16,
  ...
};
```

To represent `VARCHAR`, an enum alone is not enough, because we also
need to express the maximum length of `VARCHAR`, i.e. max_length.

```c++
namespace impl {

enum class PropertyTypeImpl {
  kEmpty,
  kBool,
  kUInt8,
  kUInt16,
 ...
};

// Stores additional type information for PropertyTypeImpl
union AdditionalTypeInfo {
  uint16_t max_length;  // for varchar
};
}  // namespace impl

struct PropertyType {
  impl::PropertyTypeImpl type_enum;
  impl::AdditionalTypeInfo additional_type_info;

  PropertyType()
      : type_enum(impl::PropertyTypeImpl::kEmpty), additional_type_info() {}
  PropertyType(impl::PropertyTypeImpl type)
      : type_enum(type), additional_type_info() {}
  PropertyType(impl::PropertyTypeImpl type, uint16_t max_length)
      : type_enum(type), additional_type_info({.max_length = max_length}) {
    assert(type == impl::PropertyTypeImpl::kVarChar);
  }

  //get DataType object, like `arrow::bool()`(but arrow returns a shared_ptr)
  static PropertyType empty();
  static PropertyType bool_();
  static PropertyType uint8();
  static PropertyType uint16();

  // different from other functions
  static PropertyType var_char(uint16_t max_length); 
  //...

  static const PropertyType kEmpty;
  static const PropertyType kBool;
  static const PropertyType kUInt8;
  static const PropertyType kUInt16;
  //...

  bool operator==(const PropertyType& other) const;
  bool operator!=(const PropertyType& other) const;
};

```

VarChar is implemented but not fully provided by interactive. User shall be able to use VarChar type after VarChar is supported by compiler.

---------

Co-authored-by: liulx20 <[email protected]>
  • Loading branch information
zhanglei1949 and liulx20 authored Dec 14, 2023
1 parent 052b9e6 commit 975667e
Show file tree
Hide file tree
Showing 28 changed files with 663 additions and 445 deletions.
2 changes: 0 additions & 2 deletions docs/flex/interactive/data_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ property_type:
primitive_type: DT_STRING
```

Please note that we currently do not support the use of string data type for properties on edges.

### Array Types

Array types are currently not supported, but are planned to be supported in the near future.
Expand Down
1 change: 1 addition & 0 deletions flex/bin/interactive_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ int main(int argc, char** argv) {
data_path = vm["data-path"].as<std::string>();

auto schema = gs::Schema::LoadFromYaml(graph_schema_path);

// Ths schema is loaded just to get the plugin dir and plugin list
gs::init_codegen_proxy(vm, graph_schema_path, engine_config_file);
db.Close();
Expand Down
1 change: 1 addition & 0 deletions flex/engines/graph_db/database/graph_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Result<bool> GraphDB::Open(const Schema& schema, const std::string& data_dir,
}

if ((!create_empty_graph) && (!graph_.schema().Equals(schema))) {
LOG(ERROR) << "Schema inconsistent..\n";
return Result<bool>(StatusCode::InternalError,
"Schema of work directory is not compatible with the "
"graph schema",
Expand Down
71 changes: 25 additions & 46 deletions flex/engines/graph_db/database/transaction_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,74 +26,53 @@
namespace gs {

inline void serialize_field(grape::InArchive& arc, const Any& prop) {
switch (prop.type) {
case PropertyType::kBool:
if (prop.type == PropertyType::Bool()) {
arc << prop.value.b;
break;
case PropertyType::kInt32:
} else if (prop.type == PropertyType::Int32()) {
arc << prop.value.i;
break;
case PropertyType::kUInt32:
} else if (prop.type == PropertyType::UInt32()) {
arc << prop.value.ui;
break;
case PropertyType::kDate:
} else if (prop.type == PropertyType::Date()) {
arc << prop.value.d.milli_second;
break;
case PropertyType::kString:
} else if (prop.type == PropertyType::String()) {
arc << prop.value.s;
break;
case PropertyType::kEmpty:
break;
case PropertyType::kInt64:
} else if (prop.type == PropertyType::Int64()) {
arc << prop.value.l;
break;
case PropertyType::kUInt64:
} else if (prop.type == PropertyType::UInt64()) {
arc << prop.value.ul;
break;
case PropertyType::kDouble:
} else if (prop.type == PropertyType::Double()) {
arc << prop.value.db;
break;
case PropertyType::kFloat:
} else if (prop.type == PropertyType::Float()) {
arc << prop.value.f;
break;
default:
LOG(FATAL) << "Unexpected property type";
} else if (prop.type == PropertyType::Empty()) {
} else {
LOG(FATAL) << "Unexpected property type" << int(prop.type.type_enum);
}
}

inline void deserialize_field(grape::OutArchive& arc, Any& prop) {
switch (prop.type) {
case PropertyType::kBool:
if (prop.type == PropertyType::Bool()) {
arc >> prop.value.b;
break;
case PropertyType::kInt32:
} else if (prop.type == PropertyType::Int32()) {
arc >> prop.value.i;
break;
case PropertyType::kUInt32:
} else if (prop.type == PropertyType::UInt32()) {
arc >> prop.value.ui;
break;
case PropertyType::kDate:
} else if (prop.type == PropertyType::Date()) {
arc >> prop.value.d.milli_second;
break;
case PropertyType::kString:
} else if (prop.type == PropertyType::String()) {
arc >> prop.value.s;
break;
case PropertyType::kEmpty:
break;
case PropertyType::kInt64:
} else if (prop.type == PropertyType::Int64()) {
arc >> prop.value.l;
break;
case PropertyType::kUInt64:
} else if (prop.type == PropertyType::UInt64()) {
arc >> prop.value.ul;
break;
case PropertyType::kDouble:
} else if (prop.type == PropertyType::Double()) {
arc >> prop.value.db;
break;
case PropertyType::kFloat:
} else if (prop.type == PropertyType::Float()) {
arc >> prop.value.f;
break;
default:
LOG(FATAL) << "Unexpected property type";
} else if (prop.type == PropertyType::Empty()) {
} else {
LOG(FATAL) << "Unexpected property type: "
<< static_cast<int>(prop.type.type_enum);
}
}

Expand Down
42 changes: 16 additions & 26 deletions flex/engines/hqps_db/core/operator/sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,41 +179,31 @@ void template_set_tuple_value(results::Collection* collection,
/////Sink Any

void set_any_to_common_value(const Any& any, common::Value* value) {
switch (any.type) {
case gs::PropertyType::kBool:
if (any.type == PropertyType::Bool()) {
value->set_boolean(any.value.b);
break;
case gs::PropertyType::kInt32:
} else if (any.type == PropertyType::Int32()) {
value->set_i32(any.value.i);
break;
case gs::PropertyType::kInt64:
value->set_i64(any.value.l);
break;
case gs::PropertyType::kUInt32:
// FIXME(zhanglei): temporarily use i64, fix this after common.proto is
} else if (any.type == PropertyType::UInt32()) {
// FIXME(zhanglei): temporarily use i32, fix this after common.proto is
// changed
value->set_i32(any.value.ui);
break;
case gs::PropertyType::kUInt64:
} else if (any.type == PropertyType::Int64()) {
value->set_i64(any.value.l);
} else if (any.type == PropertyType::UInt64()) {
// FIXME(zhanglei): temporarily use i64, fix this after common.proto is
// changed
value->set_i64(any.value.ul);
break;
case gs::PropertyType::kDate:
value->set_i64(any.value.d.milli_second);
break;
case gs::PropertyType::kString:
value->mutable_str()->assign(any.value.s.data(), any.value.s.size());
break;
case gs::PropertyType::kDouble:
} else if (any.type == PropertyType::Double()) {
value->set_f64(any.value.db);
break;
case gs::PropertyType::kFloat:
} else if (any.type == PropertyType::Float()) {
value->set_f64(any.value.f);
break;
default:
LOG(WARNING) << "Unsupported type: " << any.type;
break;
} else if (any.type == PropertyType::Date()) {
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());
} else {
LOG(WARNING) << "Unexpected property type: "
<< static_cast<int>(any.type.type_enum);
}
}

Expand Down
2 changes: 1 addition & 1 deletion flex/engines/hqps_db/database/mutable_csr_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ class MutableCSRInterface {
*std::dynamic_pointer_cast<TypedColumn<float>>(column));
} else {
LOG(FATAL) << "unexpected type to create column, "
<< static_cast<int>(type);
<< static_cast<int>(type.type_enum);
return nullptr;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class UnTypedEdgeSet {
while (iter != end_iter) {
auto edata = iter.GetData();
PropT prop;
if (edata.type == TypeConverter<PropT>::property_type) {
if (edata.type == TypeConverter<PropT>::property_type()) {
ConvertAny<PropT>::to(edata, prop);
}
CHECK(cur_ind < sum) << "cur: " << cur_ind << ", sum: " << sum;
Expand Down
6 changes: 4 additions & 2 deletions flex/storages/rt_mutable_graph/dual_csr.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,10 @@ class DualCsr : public DualCsrBase {
template <>
class DualCsr<std::string_view> : public DualCsrBase {
public:
DualCsr(EdgeStrategy oe_strategy, EdgeStrategy ie_strategy)
: in_csr_(nullptr), out_csr_(nullptr), column_(StorageStrategy::kMem) {
DualCsr(EdgeStrategy oe_strategy, EdgeStrategy ie_strategy, uint16_t width)
: in_csr_(nullptr),
out_csr_(nullptr),
column_(StorageStrategy::kMem, width) {
if (ie_strategy == EdgeStrategy::kNone) {
in_csr_ = new EmptyCsr<std::string_view>(column_, column_idx_);
} else if (ie_strategy == EdgeStrategy::kMultiple) {
Expand Down
Loading

0 comments on commit 975667e

Please sign in to comment.