Skip to content
Draft
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
10 changes: 10 additions & 0 deletions include/neug/common/extra_type_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ enum class ExtraTypeInfoType : uint8_t {
STRING_TYPE_INFO = 3,
LIST_TYPE_INFO = 4,
STRUCT_TYPE_INFO = 5,
ARRAY_TYPE_INFO = 6,
};

struct ExtraTypeInfo {
Expand Down Expand Up @@ -84,6 +85,15 @@ struct ListTypeInfo : public ExtraTypeInfo {
bool EqualsInternal(ExtraTypeInfo* other_p) const override;
};

struct ArrayTypeInfo : public ExtraTypeInfo {
DataType child_type;
uint32_t array_size;
ArrayTypeInfo(DataType child_type_p, uint32_t array_size_p);

protected:
bool EqualsInternal(ExtraTypeInfo* other_p) const override;
};

struct StringTypeInfo : public ExtraTypeInfo {
size_t max_length;
explicit StringTypeInfo(size_t length)
Expand Down
8 changes: 7 additions & 1 deletion include/neug/common/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ enum class DataTypeId : uint8_t {
kList = 101,
// kMap = 102,

// kArray = 108,
kArray = 108,

kVertex = 200,
kEdge = 201,
Expand Down Expand Up @@ -113,6 +113,7 @@ struct DataType {

static DataType Struct(std::vector<DataType> children);
static DataType List(const DataType& child_type);
static DataType Array(const DataType& child_type, uint32_t array_size);
static DataType Varchar(size_t max_length);

inline DataTypeId id() const { return id_; }
Expand Down Expand Up @@ -175,11 +176,16 @@ struct DataType {
static constexpr const DataTypeId VERTEX = DataTypeId::kVertex;
static constexpr const DataTypeId EDGE = DataTypeId::kEdge;
static constexpr const DataTypeId PATH = DataTypeId::kPath;
static constexpr const DataTypeId ARRAY = DataTypeId::kArray;
};

struct ListType {
static const DataType& GetChildType(const DataType& type);
};
struct ArrayType {
static const DataType& GetChildType(const DataType& type);
static uint32_t GetSize(const DataType& type);
};
struct StructType {
static const std::vector<DataType>& GetChildTypes(const DataType& type);
static const DataType& GetChildType(const DataType& type, size_t index);
Expand Down
19 changes: 19 additions & 0 deletions include/neug/execution/common/types/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Value {
friend struct StringValue;
friend struct StructValue;
friend struct ListValue;
friend struct ArrayValue;
friend struct PathValue;

public:
Expand Down Expand Up @@ -81,6 +82,8 @@ class Value {
static Value LIST(const DataType& child_type, std::vector<Value>&& values);
static Value LIST(std::vector<Value>&& values);

static Value ARRAY(const DataType& array_type, std::vector<Value>&& values);

static Value STRING(const std::string& str);

static Value VARCHAR(const std::string& str, uint16_t max_length);
Expand Down Expand Up @@ -168,6 +171,11 @@ struct ListValue {
static const std::vector<Value>& GetChildren(const Value& value);
};

struct ArrayValue {
static const std::vector<Value>& GetChildren(const Value& value);
static uint32_t GetSize(const Value& value);
};

struct StructValue {
static const std::vector<Value>& GetChildren(const Value& value);
};
Expand Down Expand Up @@ -616,6 +624,17 @@ bool Value::ApplyComparisonOp(const Value& lhs, const Value& rhs) {
}
return true;
}
case DataTypeId::kArray: {
const auto& lhs_children = ArrayValue::GetChildren(lhs);
const auto& rhs_children = ArrayValue::GetChildren(rhs);
assert(lhs_children.size() == rhs_children.size());
for (size_t i = 0; i < lhs_children.size(); ++i) {
if (!ApplyComparisonOp<OP>(lhs_children[i], rhs_children[i])) {
return false;
}
}
return true;
}
case DataTypeId::kVertex: {
return OP::operation(lhs.GetValue<vertex_t>(), rhs.GetValue<vertex_t>());
}
Expand Down
75 changes: 75 additions & 0 deletions include/neug/utils/property/array_column.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/** 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 "neug/common/extra_type_info.h"
#include "neug/common/types.h"
#include "neug/execution/common/types/value.h"
#include "neug/utils/property/column.h"

namespace neug {

/**
* @brief Fixed-length array column backed by a child column.
*
* For row i, element j is stored at child_column[i * array_size + j].
* The ArrayColumn itself has no data buffer; it stores only metadata
* (array_type, array_size, row count) in its module descriptor.
* The child column handles actual storage.
*/
class ArrayColumn : public ColumnBase {
public:
ArrayColumn() : array_size_(0), size_(0) {}
explicit ArrayColumn(const DataType& array_type);
~ArrayColumn() override = default;

void Open(Checkpoint& ckp, const ModuleDescriptor& desc,
MemoryLevel level) override;

ModuleDescriptor Dump(Checkpoint& ckp) override;

size_t size() const override { return size_; }

void resize(size_t size) override;
void resize(size_t size, const Property& default_value) override;

DataTypeId type() const override { return DataTypeId::kArray; }

void set_any(size_t index, const Property& value,
bool insert_safe) override;

Property get_prop(size_t index) const override;

void set_value(size_t index, const execution::Value& value);

execution::Value get_value(size_t index) const;

void ingest(uint32_t index, OutArchive& arc) override;

std::string ModuleTypeName() const override { return type_name(); }

static std::string type_name() { return "column<array>"; }

private:
DataType array_type_;
uint32_t array_size_;
size_t size_;
std::unique_ptr<ColumnBase> child_column_;
};

} // namespace neug
15 changes: 15 additions & 0 deletions include/neug/utils/property/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,16 @@ struct convert<neug::DataType> {
THROW_NOT_SUPPORTED_EXCEPTION("Unrecognized temporal type: " +
temporal.as<std::string>());
}
} else if (config["array"]) {
auto array_node = config["array"];
neug::DataType child_type;
if (!array_node["component_type"] ||
!decode(array_node["component_type"], child_type)) {
LOG(ERROR) << "Failed to parse array component_type";
return false;
}
uint32_t max_length = array_node["max_length"].as<uint32_t>();
property_type = neug::DataType::Array(child_type, max_length);
} else if (config["date"]) {
property_type = neug::DataTypeId::kDate;
} else {
Expand Down Expand Up @@ -612,6 +622,11 @@ struct convert<neug::DataType> {
: neug::STRING_DEFAULT_MAX_LENGTH;
} else if (type == neug::DataTypeId::kDate) {
node["temporal"]["datetime"] = "";
} else if (type == neug::DataTypeId::kArray) {
auto child_type = neug::ArrayType::GetChildType(type);
uint32_t array_size = neug::ArrayType::GetSize(type);
node["array"]["component_type"] = encode(child_type);
node["array"]["max_length"] = array_size;
} else {
LOG(ERROR) << "Unrecognized property type: " << type.ToString();
}
Expand Down
10 changes: 10 additions & 0 deletions src/common/extra_type_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ bool ListTypeInfo::EqualsInternal(ExtraTypeInfo* other_p) const {
return child_type == other.child_type;
}

ArrayTypeInfo::ArrayTypeInfo(DataType child_type_p, uint32_t array_size_p)
: ExtraTypeInfo(ExtraTypeInfoType::ARRAY_TYPE_INFO),
child_type(std::move(child_type_p)),
array_size(array_size_p) {}

bool ArrayTypeInfo::EqualsInternal(ExtraTypeInfo* other_p) const {
auto& other = other_p->Cast<ArrayTypeInfo>();
return child_type == other.child_type && array_size == other.array_size;
}

bool StringTypeInfo::EqualsInternal(ExtraTypeInfo* other_p) const {
auto& other = other_p->Cast<StringTypeInfo>();
return max_length == other.max_length;
Expand Down
38 changes: 34 additions & 4 deletions src/common/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ DataType DataType::List(const DataType& child_type) {
return DataType(DataTypeId::kList, type_info);
}

DataType DataType::Array(const DataType& child_type, uint32_t array_size) {
std::shared_ptr<ExtraTypeInfo> type_info =
std::make_shared<ArrayTypeInfo>(child_type, array_size);
return DataType(DataTypeId::kArray, type_info);
}

const DataType& ArrayType::GetChildType(const DataType& type) {
assert(type.id() == DataTypeId::kArray);
auto info = type.RawExtraTypeInfo();
assert(info);
return info->Cast<ArrayTypeInfo>().child_type;
}

uint32_t ArrayType::GetSize(const DataType& type) {
assert(type.id() == DataTypeId::kArray);
auto info = type.RawExtraTypeInfo();
assert(info);
return info->Cast<ArrayTypeInfo>().array_size;
}

DataType DataType::Varchar(size_t max_length) {
std::shared_ptr<ExtraTypeInfo> type_info =
std::make_shared<StringTypeInfo>(max_length);
Expand Down Expand Up @@ -147,10 +167,14 @@ DataType parse_from_data_type(const ::common::DataType& ddt) {
}
}
case ::common::DataType::kArray: {
const auto& element_type = ddt.array().component_type();
auto data_type = parse_from_data_type(element_type);
return DataType(DataTypeId::kList,
std::make_shared<ListTypeInfo>(data_type));
const auto& array_pb = ddt.array();
const auto& element_type = array_pb.component_type();
auto child_data_type = parse_from_data_type(element_type);
uint32_t max_length = array_pb.max_length();
if (max_length > 0) {
return DataType::Array(child_data_type, max_length);
}
return DataType::List(child_data_type);
}
case ::common::DataType::kTuple: {
const auto& component_types = ddt.tuple().component_types();
Expand Down Expand Up @@ -255,6 +279,12 @@ std::string DataType::ToString() const {
const DataType& child_type = ListType::GetChildType(*this);
return "LIST<" + child_type.ToString() + ">";
}
case DataTypeId::kArray: {
const DataType& child_type = ArrayType::GetChildType(*this);
uint32_t array_size = ArrayType::GetSize(*this);
return "ARRAY<" + child_type.ToString() + ", " +
std::to_string(array_size) + ">";
}
case DataTypeId::kStruct: {
const auto& child_types = StructType::GetChildTypes(*this);
std::string result = "STRUCT<";
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/binder/bind/read/bind_unwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ std::unique_ptr<BoundReadingClause> Binder::bindUnwindClause(
if (boundExpression->getDataType().getLogicalTypeID() ==
LogicalTypeID::ARRAY) {
auto targetType = LogicalType::LIST(
ArrayType::getChildType(boundExpression->dataType).copy());
common::ArrayType::getChildType(boundExpression->dataType).copy());
boundExpression =
expressionBinder.implicitCast(boundExpression, targetType);
}
Expand Down
12 changes: 6 additions & 6 deletions src/compiler/function/vector_cast_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,24 +182,24 @@ static bool hasImplicitCastList(const LogicalType& srcType,

static bool hasImplicitCastArray(const LogicalType& srcType,
const LogicalType& dstType) {
if (ArrayType::getNumElements(srcType) !=
ArrayType::getNumElements(dstType)) {
if (common::ArrayType::getNumElements(srcType) !=
common::ArrayType::getNumElements(dstType)) {
return false;
}
return CastFunction::hasImplicitCast(ArrayType::getChildType(srcType),
ArrayType::getChildType(dstType));
return CastFunction::hasImplicitCast(common::ArrayType::getChildType(srcType),
common::ArrayType::getChildType(dstType));
}

static bool hasImplicitCastArrayToList(const LogicalType& srcType,
const LogicalType& dstType) {
return CastFunction::hasImplicitCast(ArrayType::getChildType(srcType),
return CastFunction::hasImplicitCast(common::ArrayType::getChildType(srcType),
::ListType::getChildType(dstType));
}

static bool hasImplicitCastListToArray(const LogicalType& srcType,
const LogicalType& dstType) {
return CastFunction::hasImplicitCast(::ListType::getChildType(srcType),
ArrayType::getChildType(dstType));
common::ArrayType::getChildType(dstType));
}

static bool hasImplicitCastStruct(const LogicalType& srcType,
Expand Down
11 changes: 11 additions & 0 deletions src/compiler/gopt/g_type_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,17 @@ GPhysicalTypeConverter::convertSimpleLogicalType(
result->set_allocated_temporal(temporalType.release());
break;
}
case common::LogicalTypeID::ARRAY: {
auto& childType = common::ArrayType::getChildType(type);
auto numElements = common::ArrayType::getNumElements(type);
auto childIrType = convertSimpleLogicalType(childType);
auto arrayPb = std::make_unique<::common::Array>();
arrayPb->set_allocated_component_type(
childIrType->release_data_type());
arrayPb->set_max_length(numElements);
result->set_allocated_array(arrayPb.release());
break;
}
default:
THROW_EXCEPTION_WITH_FILE_LINE("Unsupported basic type for conversion: " +
type.toString());
Expand Down
4 changes: 4 additions & 0 deletions src/execution/common/columns/columns_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ std::shared_ptr<IContextColumnBuilder> ColumnsUtils::create_builder(
DataType elem_type = ListType::GetChildType(type);
return std::make_shared<ListColumnBuilder>(elem_type);
}
case DataTypeId::kArray: {
DataType elem_type = ArrayType::GetChildType(type);
return std::make_shared<ListColumnBuilder>(elem_type);
}
case DataTypeId::kPath: {
return std::make_shared<PathColumnBuilder>();
}
Expand Down
Loading
Loading