Skip to content

Commit

Permalink
Fast Schema alter. (#666)
Browse files Browse the repository at this point in the history
* enable_fast_alter_schema.

* fix check all.

* fix compile.

* fix ut.

* fix uts.

* fix some error.

* fix uts.

* fix some code style.

* fix uts.

* fix schema serialize.

* fix cpplint.
  • Loading branch information
ColinLeeo authored Feb 28, 2025
1 parent 0730e33 commit 1ad6a3e
Show file tree
Hide file tree
Showing 33 changed files with 3,115 additions and 1,045 deletions.
4 changes: 3 additions & 1 deletion .msvc/lgraph_core/lgraph_core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
<ClCompile Include="..\..\src\core\audit_logger.cpp" />
<ClCompile Include="..\..\src\core\data_type.cpp" />
<ClCompile Include="..\..\src\core\edge_index.cpp" />
<ClCompile Include="..\..\src\core\field_extractor.cpp" />
<ClCompile Include="..\..\src\core\field_extractor_v1.cpp" />
<CICompile Include="..\..\src\core\field_extractor_v2.cpp"/>
<CICompile Include="..\..\src\core\field_extractor_base.cpp"/>
<ClCompile Include="..\..\src\core\full_text_index.cpp" />
<ClCompile Include="..\..\src\core\global_config.cpp" />
<ClCompile Include="..\..\src\core\graph.cpp" />
Expand Down
8 changes: 7 additions & 1 deletion .msvc/lgraph_core/lgraph_core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@
<ClCompile Include="..\..\src\core\graph.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\core\field_extractor.cpp">
<ClCompile Include="..\..\src\core\field_extractor_v1.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\core\field_extractor_v2.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\core\field_extractor_base.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\core\data_type.cpp">
Expand Down
97 changes: 91 additions & 6 deletions include/lgraph/lgraph_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ struct LabelOptions {
// store property data in detached model
// Default: false
bool detach_property = false;
// use fast alter schema format
// Default: false
bool fast_alter_schema = false;
virtual std::string to_string() const = 0;
virtual void clear() = 0;
virtual ~LabelOptions() {}
Expand Down Expand Up @@ -196,6 +199,28 @@ enum FieldType {
FLOAT_VECTOR = 16 // float vector
};

inline bool const is_integer_type(FieldType type) {
switch (type) {
case INT8:
case INT16:
case INT32:
case INT64:
return true;
default:
return false;
}
}

inline bool const is_float_type(FieldType type) {
switch (type) {
case FLOAT:
case DOUBLE:
return true;
default:
return false;
}
}

/**
* @brief Get the name of the given FieldType.
*
Expand Down Expand Up @@ -1304,27 +1329,87 @@ struct FieldSpec {
FieldType type;
/** @brief is this field optional? */
bool optional;

FieldSpec(): name(), type(FieldType::NUL), optional(false) {}
/** @brief is this field deleted? */
bool deleted;
/** @brief id of this field, starts from 0 */
uint16_t id;
/** @brief the value of the field is set when it is created. */
bool set_default_value;
/** @brief the default value when inserting data. */
FieldData default_value;
/** @brief is set init value? */

FieldSpec()
: name(),
type(FieldType::NUL),
optional(false),
deleted(false),
id(0),
set_default_value(false),
default_value(FieldData()) {}

/**
* @brief Constructor
*
* @param n Field name
* @param t Field type
* @param nu True if field is optional
* @param id Field id
* @param dv Default value
*/
FieldSpec(const std::string& n, FieldType t, bool nu) : name(n), type(t), optional(nu) {}
FieldSpec(std::string&& n, FieldType t, bool nu) : name(std::move(n)), type(t), optional(nu) {}
FieldSpec(const std::string& n, FieldType t, bool nu)
: name(n),
type(t),
optional(nu),
deleted(false),
id(0),
set_default_value(false),
default_value(FieldData()) {}
FieldSpec(const std::string& n, FieldType t, bool nu, uint16_t id)
: name(n),
type(t),
optional(nu),
deleted(false),
id(id),
set_default_value(false),
default_value(FieldData()) {}
FieldSpec(std::string&& n, FieldType t, bool nu, uint16_t id)
: name(std::move(n)),
type(t),
optional(nu),
deleted(false),
id(id),
set_default_value(false),
default_value(FieldData()) {}
FieldSpec(const std::string& n, FieldType t, bool nu, uint16_t id, const FieldData& dv)
: name(n),
type(t),
optional(nu),
deleted(false),
id(id),
set_default_value(true),
default_value(dv) {}
FieldSpec(const FieldSpec& spec)
: name(spec.name),
type(spec.type),
optional(spec.optional),
deleted(spec.deleted),
id(spec.id),
set_default_value(spec.set_default_value),
default_value(spec.default_value) {}

inline bool operator==(const FieldSpec& rhs) const {
return name == rhs.name && type == rhs.type && optional == rhs.optional;
return name == rhs.name && type == rhs.type && optional == rhs.optional &&
deleted == rhs.deleted && id == rhs.id &&
set_default_value == rhs.set_default_value && default_value == rhs.default_value;
}

/** @brief Get the string representation of the FieldSpec. */
std::string ToString() const {
return "lgraph_api::FieldSpec(name=[" + name + "],type=" + lgraph_api::to_string(type) +
"),optional=" + std::to_string(optional);
"),optional=" + std::to_string(optional) + ",fieldid=" + std::to_string(id) +
",isDeleted=" + std::to_string(deleted) +
(set_default_value ? ",default_value=" + default_value.ToString() : "");
}
};

Expand Down
4 changes: 3 additions & 1 deletion src/BuildLGraphApi.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ set(LGRAPH_CORE_SRC
core/audit_logger.cpp
core/data_type.cpp
core/edge_index.cpp
core/field_extractor.cpp
core/field_extractor_base.cpp
core/field_extractor_v1.cpp
core/field_extractor_v2.cpp
core/full_text_index.cpp
core/global_config.cpp
core/graph.cpp
Expand Down
4 changes: 3 additions & 1 deletion src/BuildLGraphApiForJNI.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ set(LGRAPH_CORE_SRC
core/audit_logger.cpp
core/data_type.cpp
core/edge_index.cpp
core/field_extractor.cpp
core/field_extractor_base.cpp
core/field_extractor_v1.cpp
core/field_extractor_v2.cpp
core/full_text_index.cpp
core/global_config.cpp
core/graph.cpp
Expand Down
4 changes: 4 additions & 0 deletions src/core/data_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ typedef int32_t PackDataOffset; // offset used in a packed data (maximum 1024)
typedef uint16_t LabelId;
typedef int64_t TemporalId;

typedef uint16_t FieldId; // Field id in schema Fields
typedef uint8_t VersionId; // Schema version

enum CompareOp { LBR_EQ = 0, LBR_NEQ = 1, LBR_LT = 2, LBR_LE = 3, LBR_GT = 4, LBR_GE = 5 };

enum LogicalOp { LBR_EMPTY = 0, LBR_AND = 1, LBR_OR = 2, LBR_NOT = 3, LBR_XOR = 4 };
Expand Down Expand Up @@ -308,6 +311,7 @@ static const size_t MAX_IN_PLACE_BLOB_SIZE = 512;
static const size_t MAX_BLOB_SIZE = ((size_t)1 << 32) - 1;
static const size_t MAX_KEY_SIZE = 480;
static const size_t MAX_HOST_ADDR_LEN = 256;
static const uint8_t SCHEMA_VERSION = 0;

template <size_t NBYTE>
inline int64_t GetNByteIdFromBuf(const char* p) {
Expand Down
Loading

0 comments on commit 1ad6a3e

Please sign in to comment.