Skip to content

Commit f5bd0c9

Browse files
committed
init commit for list impl
support to_list expression in compiler Committed-by: Xiaoli Zhou from Dev container resolve some comments use owned property to hold the string memory temporarily when passing it to storage fix default value of list type in ddl Committed-by: Xiaoli Zhou from Dev container fix
1 parent f506b24 commit f5bd0c9

42 files changed

Lines changed: 1674 additions & 224 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/neug/common/types.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,28 @@ enum class DataTypeId : uint8_t {
101101
DATA_TYPES_DATETIME(M) \
102102
M(kVarchar, std::string)
103103

104+
inline bool is_pod_type(DataTypeId id) {
105+
switch (id) {
106+
case DataTypeId::kBoolean:
107+
case DataTypeId::kInt8:
108+
case DataTypeId::kInt16:
109+
case DataTypeId::kInt32:
110+
case DataTypeId::kInt64:
111+
case DataTypeId::kUInt8:
112+
case DataTypeId::kUInt16:
113+
case DataTypeId::kUInt32:
114+
case DataTypeId::kUInt64:
115+
case DataTypeId::kFloat:
116+
case DataTypeId::kDouble:
117+
case DataTypeId::kDate:
118+
case DataTypeId::kTimestampMs:
119+
case DataTypeId::kInterval:
120+
return true;
121+
default:
122+
return false;
123+
}
124+
}
125+
104126
struct ExtraTypeInfo;
105127

106128
struct DataType {

include/neug/compiler/gopt/g_ddl_converter.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "neug/compiler/gopt/g_catalog.h"
2222
#include "neug/compiler/gopt/g_expr_converter.h"
2323
#include "neug/compiler/gopt/g_type_converter.h"
24+
#include "neug/compiler/main/client_context.h"
2425
#include "neug/compiler/planner/operator/ddl/logical_alter.h"
2526
#include "neug/compiler/planner/operator/ddl/logical_create_table.h"
2627
#include "neug/compiler/planner/operator/ddl/logical_drop.h"
@@ -45,8 +46,9 @@ struct EdgeLabel {
4546
class GDDLConverter {
4647
public:
4748
explicit GDDLConverter(std::shared_ptr<GAliasManager> aliasManager,
48-
neug::catalog::Catalog* catalog)
49-
: catalog{catalog}, exprConverter(aliasManager) {}
49+
neug::catalog::Catalog* catalog,
50+
main::ClientContext* clientContext)
51+
: catalog{catalog}, exprConverter(aliasManager, clientContext) {}
5052

5153
virtual ~GDDLConverter() = default;
5254

include/neug/compiler/gopt/g_expr_converter.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "neug/compiler/gopt/g_precedence.h"
3434
#include "neug/compiler/gopt/g_scalar_type.h"
3535
#include "neug/compiler/gopt/g_type_converter.h"
36+
#include "neug/compiler/main/client_context.h"
3637
#include "neug/config.h"
3738
#include "neug/generated/proto/plan/algebra.pb.h"
3839
#include "neug/generated/proto/plan/common.pb.h"
@@ -44,8 +45,9 @@ namespace gopt {
4445

4546
class GExprConverter {
4647
public:
47-
GExprConverter(const std::shared_ptr<gopt::GAliasManager> aliasManager)
48-
: aliasManager{std::move(aliasManager)} {}
48+
GExprConverter(const std::shared_ptr<gopt::GAliasManager> aliasManager,
49+
main::ClientContext* clientContext)
50+
: aliasManager{std::move(aliasManager)}, ctx{clientContext} {}
4951

5052
// Main conversion function
5153
std::unique_ptr<::common::Expression> convert(
@@ -158,11 +160,13 @@ class GExprConverter {
158160

159161
std::unique_ptr<::common::Value> castLiteral(
160162
const binder::Expression& castExpr);
163+
std::shared_ptr<binder::Expression> foldExpression(
164+
std::shared_ptr<binder::Expression> expr);
161165

162-
private:
163166
const std::shared_ptr<gopt::GAliasManager> aliasManager;
164167
gopt::GPhysicalTypeConverter typeConverter;
165168
gopt::GPrecedence preced;
169+
main::ClientContext* ctx;
166170
};
167171

168172
} // namespace gopt

include/neug/compiler/gopt/g_physical_convertor.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "neug/compiler/gopt/g_ddl_converter.h"
2020
#include "neug/compiler/gopt/g_physical_analyzer.h"
2121
#include "neug/compiler/gopt/g_query_converter.h"
22+
#include "neug/compiler/main/client_context.h"
2223
#include "neug/compiler/planner/operator/logical_plan.h"
2324
#include "neug/compiler/planner/operator/simple/logical_extension.h"
2425
#include "neug/generated/proto/plan/physical.pb.h"
@@ -29,8 +30,11 @@ namespace gopt {
2930
class GPhysicalConvertor {
3031
public:
3132
GPhysicalConvertor(std::shared_ptr<GAliasManager> aliasManager,
32-
neug::catalog::Catalog* catalog)
33-
: aliasManager{aliasManager}, catalog{catalog} {}
33+
neug::catalog::Catalog* catalog,
34+
main::ClientContext* clientContext)
35+
: aliasManager{aliasManager},
36+
catalog{catalog},
37+
clientContext{clientContext} {}
3438

3539
std::unique_ptr<::physical::PhysicalPlan> createEmptyPlan() {
3640
auto physicalPlan = std::make_unique<::physical::PhysicalPlan>();
@@ -83,13 +87,15 @@ class GPhysicalConvertor {
8387
private:
8488
std::unique_ptr<::physical::PhysicalPlan> convertQuery(
8589
const planner::LogicalPlan& plan, bool skipSink) {
86-
auto converter = std::make_unique<GQueryConvertor>(aliasManager, catalog);
90+
auto converter =
91+
std::make_unique<GQueryConvertor>(aliasManager, catalog, clientContext);
8792
return converter->convert(plan, skipSink);
8893
}
8994

9095
private:
9196
std::shared_ptr<GAliasManager> aliasManager;
9297
neug::catalog::Catalog* catalog;
98+
main::ClientContext* clientContext;
9399
};
94100

95101
} // namespace gopt

include/neug/compiler/gopt/g_query_converter.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "neug/compiler/gopt/g_ddl_converter.h"
3232
#include "neug/compiler/gopt/g_expr_converter.h"
3333
#include "neug/compiler/gopt/g_type_converter.h"
34+
#include "neug/compiler/main/client_context.h"
3435
#include "neug/compiler/planner/operator/extend/logical_extend.h"
3536
#include "neug/compiler/planner/operator/extend/logical_recursive_extend.h"
3637
#include "neug/compiler/planner/operator/logical_aggregate.h"
@@ -78,7 +79,8 @@ struct EdgeLabelId {
7879
class GQueryConvertor {
7980
public:
8081
GQueryConvertor(std::shared_ptr<GAliasManager> aliasManager,
81-
neug::catalog::Catalog* catalog);
82+
neug::catalog::Catalog* catalog,
83+
main::ClientContext* clientContext);
8284

8385
std::unique_ptr<::physical::PhysicalPlan> convert(
8486
const planner::LogicalPlan& plan, bool skipSink);
@@ -239,6 +241,7 @@ class GQueryConvertor {
239241
std::unique_ptr<GExprConverter> exprConvertor;
240242
std::unique_ptr<GPhysicalTypeConverter> typeConverter;
241243
neug::catalog::Catalog* catalog;
244+
main::ClientContext* clientContext;
242245
neug::gopt::GDDLConverter ddlConverter;
243246
};
244247

include/neug/compiler/gopt/g_scalar_type.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,8 @@ class GScalarType {
117117
} else if (func.name == function::ListCreationFunction::name) {
118118
const auto& type = expr.getDataType();
119119
if (type.getLogicalTypeID() == common::LogicalTypeID::LIST) {
120-
LOG(INFO) << "type is list";
121120
return ScalarType::TO_LIST;
122121
} else if (type.getLogicalTypeID() == common::LogicalTypeID::STRUCT) {
123-
LOG(INFO) << "type is struct";
124122
return ScalarType::TO_TUPLE;
125123
}
126124
THROW_EXCEPTION_WITH_FILE_LINE("Invalid data type: " + type.toString() +

include/neug/compiler/gopt/g_type_utils.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ class GTypeUtils {
147147
return YAML_NODE_TEMPORAL_DATETIME();
148148
case neug::common::LogicalTypeID::INTERVAL:
149149
return YAML_NODE_TEMPORAL_INTERVAL();
150+
case neug::common::LogicalTypeID::LIST: {
151+
auto extraInfo = type.getExtraTypeInfo();
152+
if (!extraInfo) {
153+
THROW_RUNTIME_ERROR("List type should have extra info");
154+
}
155+
auto listType = extraInfo->constPtrCast<neug::common::ListTypeInfo>();
156+
YAML::Node n;
157+
n["array"]["component_type"] = toYAML(listType->getChildType());
158+
return n;
159+
}
150160
default:
151161
LOG(WARNING) << "Unsupported type in YAML: "
152162
<< static_cast<uint8_t>(type.getLogicalTypeID());
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/** Copyright 2020 Alibaba Group Holding Limited.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
#pragma once
16+
17+
#include <string>
18+
19+
#include "neug/utils/property/property.h"
20+
21+
namespace neug {
22+
namespace execution {
23+
24+
// OwnedProperty wraps a Property together with optional owned memory that
25+
// backs the Property's string_view (used for List, VARCHAR or other non-pod
26+
// types). This is needed because Property is a pure-view type that never owns
27+
// memory, but Value->Property conversion for List types produces a temporary
28+
// blob that must outlive the Property until the storage layer copies the data.
29+
struct OwnedProperty {
30+
OwnedProperty() = default;
31+
32+
explicit OwnedProperty(Property p) : prop_(std::move(p)) {}
33+
OwnedProperty(Property p, std::string owned)
34+
: owned_buffer_(std::move(owned)), prop_(std::move(p)) {
35+
reseat();
36+
}
37+
OwnedProperty(OwnedProperty&& other) noexcept
38+
: owned_buffer_(std::move(other.owned_buffer_)), prop_(other.prop_) {
39+
reseat();
40+
}
41+
42+
OwnedProperty& operator=(OwnedProperty&& other) noexcept {
43+
if (this != &other) {
44+
owned_buffer_ = std::move(other.owned_buffer_);
45+
prop_ = other.prop_;
46+
reseat();
47+
}
48+
return *this;
49+
}
50+
51+
// Copy constructor: deep-copy the buffer and re-seat
52+
OwnedProperty(const OwnedProperty& other)
53+
: owned_buffer_(other.owned_buffer_), prop_(other.prop_) {
54+
reseat();
55+
}
56+
57+
OwnedProperty& operator=(const OwnedProperty& other) {
58+
if (this != &other) {
59+
owned_buffer_ = other.owned_buffer_;
60+
prop_ = other.prop_;
61+
reseat();
62+
}
63+
return *this;
64+
}
65+
66+
// Access the underlying Property (for passing to storage layer APIs).
67+
const Property& prop() const { return prop_; }
68+
Property& prop() { return prop_; }
69+
70+
private:
71+
void reseat() {
72+
if (!owned_buffer_.empty()) {
73+
if (prop_.type() == DataTypeId::kList) {
74+
prop_.set_list_data(owned_buffer_);
75+
} else if (prop_.type() == DataTypeId::kVarchar) {
76+
prop_.set_string_view(owned_buffer_);
77+
}
78+
}
79+
}
80+
81+
std::string owned_buffer_;
82+
Property prop_;
83+
};
84+
85+
} // namespace execution
86+
} // namespace neug

include/neug/execution/common/types/value.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
#include <charconv>
2626
#include "neug/common/types.h"
2727
#include "neug/execution/common/types/graph_types.h"
28+
#include "neug/execution/common/types/owned_property.h"
2829
#include "neug/execution/utils/numeric_cast.h"
30+
#include "neug/utils/property/list_view.h"
2931

3032
namespace neug {
3133
class Property;
@@ -631,8 +633,8 @@ bool Value::ApplyComparisonOp(const Value& lhs, const Value& rhs) {
631633
}
632634
}
633635

634-
Property value_to_property(const Value& value);
635-
Value property_to_value(const Property& property);
636+
OwnedProperty value_to_property(const Value& value);
637+
Value property_to_value(const Property& property, const DataType& type);
636638

637639
template <typename T>
638640
Value performCast(const Value& input) {

include/neug/storages/graph/schema.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,16 @@ class Schema;
4242
inline void process_default_values(
4343
std::vector<Property>& default_property_values,
4444
std::vector<std::string>& default_property_strings) {
45-
// Keep the ownership of string default property in default_property_strings
45+
// Keep the ownership of string/list default property in
46+
// default_property_strings so the Property's string_view remains valid.
4647
for (auto& prop : default_property_values) {
4748
if (prop.type() == DataTypeId::kVarchar && prop.as_string_view() != "") {
4849
default_property_strings.emplace_back(prop.as_string_view());
4950
prop.set_string_view(std::string_view(default_property_strings.back()));
51+
} else if (prop.type() == DataTypeId::kList &&
52+
!prop.as_list_data().empty()) {
53+
default_property_strings.emplace_back(prop.as_list_data());
54+
prop.set_list_data(std::string_view(default_property_strings.back()));
5055
}
5156
}
5257
}

0 commit comments

Comments
 (0)