Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions include/neug/compiler/catalog/catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
#pragma once

#include <memory>
#include <optional>

#include "neug/compiler/catalog/catalog_entry/function_catalog_entry.h"
#include "neug/compiler/catalog/catalog_set.h"
#include "neug/compiler/common/cast.h"
#include "neug/compiler/function/function.h"
#include "neug/storages/graph/schema.h"
#include "neug/storages/graph/schema_view.h"

namespace neug::main {
struct DBConfig;
Expand Down Expand Up @@ -167,14 +168,15 @@ class NEUG_API Catalog {
}

virtual std::unique_ptr<Catalog> clone(const Schema* schema) const;
virtual std::unique_ptr<Catalog> clone(const SchemaView* schema) const;

private:
void initCatalogSets();

protected:
void setSchema(const Schema* schema);
void setSchema(const SchemaView* schema);

const Schema* schema;
std::optional<SchemaView> schema;

private:
std::shared_ptr<CatalogSet> sequences;
Expand Down
1 change: 1 addition & 0 deletions include/neug/compiler/gopt/g_catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class GCatalog : public Catalog {
const std::string& signatureName);

std::unique_ptr<Catalog> clone(const Schema* schema) const override;
std::unique_ptr<Catalog> clone(const SchemaView* schema) const override;

private:
void registerBuiltInFunctions();
Expand Down
4 changes: 4 additions & 0 deletions include/neug/compiler/main/metadata_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class CatalogEntry;

class GraphStats;
class Schema;
class SchemaView;

namespace function {
struct Function;
Expand Down Expand Up @@ -92,6 +93,9 @@ class MetadataManager {
std::unique_ptr<MetadataManager> clone(const Schema* schema,
const GraphStats& stats) const;

std::unique_ptr<MetadataManager> clone(const SchemaView* schema,
const GraphStats& stats) const;

std::shared_ptr<GraphStats> getGraphStats() const;

graph::GraphEntrySet& getGraphEntrySetUnsafe();
Expand Down
16 changes: 15 additions & 1 deletion include/neug/storages/graph/operation_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CreateVertexTypeParam {
std::vector<std::pair<std::string, Value>> properties;
std::vector<std::string> primary_key_names;
bool temporary = false;
std::string namespace_name = "default";
CreateVertexTypeParam() = default;
friend class CreateVertexTypeParamBuilder;

Expand All @@ -43,6 +44,7 @@ class CreateVertexTypeParam {
return primary_key_names;
}
bool IsTemporary() const { return temporary; }
const std::string& GetNamespace() const { return namespace_name; }

void Serialize(InArchive& arc) const;
static CreateVertexTypeParam Deserialize(OutArchive& arc);
Expand Down Expand Up @@ -87,6 +89,11 @@ class CreateVertexTypeParamBuilder {
return *this;
}

CreateVertexTypeParamBuilder& Namespace(const std::string& namespace_name) {
config.namespace_name = namespace_name;
return *this;
}

CreateVertexTypeParam Build() {
if (config.vertex_label_name.empty()) {
LOG(ERROR) << "Vertex label cannot be empty.";
Expand All @@ -110,6 +117,7 @@ class CreateEdgeTypeParam {
EdgeStrategy ie_edge_strategy;
std::optional<std::string> sort_key_for_nbr;
bool temporary = false;
std::string namespace_name = "default";
CreateEdgeTypeParam() = default;
friend class CreateEdgeTypeParamBuilder;

Expand All @@ -126,6 +134,7 @@ class CreateEdgeTypeParam {
return sort_key_for_nbr;
}
bool IsTemporary() const { return temporary; }
const std::string& GetNamespace() const { return namespace_name; }

void Serialize(InArchive& arc) const;
static CreateEdgeTypeParam Deserialize(OutArchive& arc);
Expand Down Expand Up @@ -187,6 +196,11 @@ class CreateEdgeTypeParamBuilder {
return *this;
}

CreateEdgeTypeParamBuilder& Namespace(const std::string& namespace_name) {
config.namespace_name = namespace_name;
return *this;
}

CreateEdgeTypeParam Build() {
if (config.src_label_name.empty()) {
LOG(ERROR) << "Source label must be specified.";
Expand Down Expand Up @@ -547,4 +561,4 @@ class DeleteEdgePropertiesParamBuilder {
}
};

} // namespace neug
} // namespace neug
11 changes: 9 additions & 2 deletions include/neug/storages/graph/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ struct VertexSchema : public SchemaEntry {
std::string description;
size_t max_num;

// Logical namespace this vertex type belongs to.
std::string namespace_name = "default";

// Mark whether the vertex property is soft deleted
std::vector<bool> vprop_soft_deleted;

Expand Down Expand Up @@ -409,6 +412,9 @@ struct EdgeSchema : public SchemaEntry {
std::vector<std::string> property_names;
std::vector<Value> default_property_values;

// Logical namespace this edge type belongs to.
std::string namespace_name = "default";

// Mark whether the edge property is soft deleted
std::vector<bool> eprop_soft_deleted;

Expand Down Expand Up @@ -556,7 +562,7 @@ class Schema {
size_t max_vnum = static_cast<size_t>(1) << 32,
const std::string& description = "",
const std::vector<Value>& default_property_values = {},
bool temporary = false);
bool temporary = false, const std::string& namespace_name = "default");

void AddEdgeLabel(const std::string& src_label, const std::string& dst_label,
const std::string& edge_label,
Expand All @@ -568,7 +574,8 @@ class Schema {
std::optional<std::string> sort_key_for_nbr = std::nullopt,
const std::string& description = "",
const std::vector<Value>& default_property_values = {},
bool temporary = false);
bool temporary = false,
const std::string& namespace_name = "default");

bool is_vertex_label_temporary(label_t label) const;
bool is_edge_label_temporary(uint32_t edge_triplet_key) const;
Expand Down
73 changes: 73 additions & 0 deletions include/neug/storages/graph/schema_view.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/** Copyright 2020 Alibaba Group Holding Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

#include <memory>
#include <string>
#include <vector>

#include "neug/storages/graph/schema.h"

namespace neug {

class SchemaView {
public:
SchemaView(const Schema* schema, std::string namespace_name);
SchemaView(const Schema& schema, std::string namespace_name);

const Schema& GetSchema() const;
const std::string& GetNamespace() const { return namespace_; }

std::vector<std::shared_ptr<const VertexSchema>> GetVertexSchemas() const;
std::vector<std::shared_ptr<const EdgeSchema>> GetEdgeSchemas() const;

result<std::shared_ptr<const VertexSchema>> GetVertexSchema(
label_t label) const;
result<std::shared_ptr<const VertexSchema>> GetVertexSchema(
const std::string& label) const;

result<std::shared_ptr<const EdgeSchema>> GetEdgeSchema(
label_t src_label, label_t dst_label, label_t edge_label) const;
result<std::shared_ptr<const EdgeSchema>> GetEdgeSchema(
const std::string& src_label, const std::string& dst_label,
const std::string& edge_label) const;

bool ContainsVertexLabel(label_t label) const;
bool ContainsVertexLabel(const std::string& label) const;

bool ContainsEdgeLabel(label_t label) const;
bool ContainsEdgeLabel(const std::string& label) const;

bool ContainsEdgeTriplet(label_t src_label, label_t dst_label,
label_t edge_label) const;
bool ContainsEdgeTriplet(const std::string& src_label,
const std::string& dst_label,
const std::string& edge_label) const;

std::vector<label_t> GetVertexLabelIds() const;
std::vector<label_t> GetEdgeLabelIds() const;

private:
void EnsureSchema() const;

bool IsVertexInNamespace(label_t label) const;
bool IsVertexInNamespace(const VertexSchema& schema) const;
bool IsEdgeInNamespace(const EdgeSchema& schema) const;

const Schema* schema_;
std::string namespace_;
};

} // namespace neug
Loading
Loading