Skip to content

Commit

Permalink
feat: support compress
Browse files Browse the repository at this point in the history
  • Loading branch information
dl239 committed Oct 27, 2023
1 parent 190992d commit 69c5a8b
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 12 deletions.
6 changes: 6 additions & 0 deletions hybridse/include/node/node_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ enum SqlNodeType {
kWithClauseEntry,
kAlterTableStmt,
kShowStmt,
kCompressType,
kSqlNodeTypeLast, // debug type
};

Expand Down Expand Up @@ -342,6 +343,11 @@ enum StorageMode {
kHDD = 3,
};

enum CompressType {
kNoCompress = 0,
kSnappy = 1,
};

// batch plan node type
enum BatchPlanNodeType { kBatchDataset, kBatchPartition, kBatchMap };

Expand Down
2 changes: 0 additions & 2 deletions hybridse/include/node/node_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,6 @@ class NodeManager {

SqlNode *MakeReplicaNumNode(int num);

SqlNode *MakeStorageModeNode(StorageMode storage_mode);

SqlNode *MakePartitionNumNode(int num);

SqlNode *MakeDistributionsNode(const NodePointVector& distribution_list);
Expand Down
33 changes: 30 additions & 3 deletions hybridse/include/node/sql_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <vector>

#include "absl/status/statusor.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "boost/algorithm/string.hpp"
Expand Down Expand Up @@ -309,17 +310,26 @@ inline const std::string StorageModeName(StorageMode mode) {
}

inline const StorageMode NameToStorageMode(const std::string& name) {
if (boost::iequals(name, "memory")) {
if (absl::EqualsIgnoreCase(name, "memory")) {
return kMemory;
} else if (boost::iequals(name, "hdd")) {
} else if (absl::EqualsIgnoreCase(name, "hdd")) {
return kHDD;
} else if (boost::iequals(name, "ssd")) {
} else if (absl::EqualsIgnoreCase(name, "ssd")) {
return kSSD;
} else {
return kUnknown;
}
}

inline absl::StatusOr<CompressType> NameToCompressType(const std::string& name) {
if (absl::EqualsIgnoreCase(name, "snappy")) {
return CompressType::kSnappy;
} else if (absl::EqualsIgnoreCase(name, "nocompress")) {
return CompressType::kNoCompress;
}
return absl::Status(absl::StatusCode::kInvalidArgument, absl::StrCat("invalid compress type: ", name));
}

inline const std::string RoleTypeName(RoleType type) {
switch (type) {
case kLeader:
Expand Down Expand Up @@ -1881,6 +1891,23 @@ class StorageModeNode : public SqlNode {
StorageMode storage_mode_;
};

class CompressTypeNode : public SqlNode {
public:
CompressTypeNode() : SqlNode(kCompressType, 0, 0), compress_type_(kNoCompress) {}

explicit CompressTypeNode(CompressType compress_type)
: SqlNode(kStorageMode, 0, 0), compress_type_(compress_type) {}

~CompressTypeNode() {}

CompressType GetCompressType() const { return compress_type_; }

void Print(std::ostream &output, const std::string &org_tab) const;

private:
CompressType compress_type_;
};

class CreateTableLikeClause {
public:
CreateTableLikeClause() = default;
Expand Down
5 changes: 0 additions & 5 deletions hybridse/src/node/node_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1031,11 +1031,6 @@ SqlNode *NodeManager::MakeReplicaNumNode(int num) {
return RegisterNode(node_ptr);
}

SqlNode *NodeManager::MakeStorageModeNode(StorageMode storage_mode) {
SqlNode *node_ptr = new StorageModeNode(storage_mode);
return RegisterNode(node_ptr);
}

SqlNode *NodeManager::MakePartitionNumNode(int num) {
SqlNode *node_ptr = new PartitionNumNode(num);
return RegisterNode(node_ptr);
Expand Down
12 changes: 12 additions & 0 deletions hybridse/src/node/sql_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,7 @@ static absl::flat_hash_map<SqlNodeType, absl::string_view> CreateSqlNodeTypeToNa
{kReplicaNum, "kReplicaNum"},
{kPartitionNum, "kPartitionNum"},
{kStorageMode, "kStorageMode"},
{kCompressType, "kCompressType"},
{kFn, "kFn"},
{kFnParaList, "kFnParaList"},
{kCreateSpStmt, "kCreateSpStmt"},
Expand Down Expand Up @@ -2598,6 +2599,17 @@ void StorageModeNode::Print(std::ostream &output, const std::string &org_tab) co
PrintValue(output, tab, StorageModeName(storage_mode_), "storage_mode", true);
}

void CompressTypeNode::Print(std::ostream &output, const std::string &org_tab) const {
SqlNode::Print(output, org_tab);
const std::string tab = org_tab + INDENT + SPACE_ED;
output << "\n";
if (compress_type_ == CompressType::kSnappy) {
PrintValue(output, tab, "snappy", "compress_type", true);
} else {
PrintValue(output, tab, "nocompress", "compress_type", true);
}
}

void PartitionNumNode::Print(std::ostream &output, const std::string &org_tab) const {
SqlNode::Print(output, org_tab);
const std::string tab = org_tab + INDENT + SPACE_ED;
Expand Down
14 changes: 12 additions & 2 deletions hybridse/src/planv2/ast_node_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1761,8 +1761,18 @@ base::Status ConvertTableOption(const zetasql::ASTOptionsEntry* entry, node::Nod
} else if (absl::EqualsIgnoreCase("storage_mode", identifier_v)) {
std::string storage_mode;
CHECK_STATUS(AstStringLiteralToString(entry->value(), &storage_mode));
boost::to_lower(storage_mode);
*output = node_manager->MakeStorageModeNode(node::NameToStorageMode(storage_mode));
absl::AsciiStrToLower(&storage_mode);
*output = node_manager->MakeNode<node::StorageModeNode>(node::NameToStorageMode(storage_mode));
} else if (absl::EqualsIgnoreCase("compress_type", identifier_v)) {
std::string compress_type;
CHECK_STATUS(AstStringLiteralToString(entry->value(), &compress_type));
absl::AsciiStrToLower(&compress_type);
auto ret = node::NameToCompressType(compress_type);
if (ret.ok()) {
*output = node_manager->MakeNode<node::CompressTypeNode>(*ret);
} else {
return base::Status(common::kSqlAstError, ret.status().ToString());
}
} else {
return base::Status(common::kSqlAstError, absl::StrCat("invalid option ", identifier));
}
Expand Down
6 changes: 6 additions & 0 deletions src/sdk/node_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ bool NodeAdapter::TransformToTableDef(::hybridse::node::CreatePlanNode* create_n
hybridse::node::NodePointVector distribution_list;

hybridse::node::StorageMode storage_mode = hybridse::node::kMemory;
hybridse::node::CompressType compress_type = hybridse::node::kNoCompress;
// different default value for cluster and standalone mode
int replica_num = 1;
int partition_num = 1;
Expand Down Expand Up @@ -253,6 +254,10 @@ bool NodeAdapter::TransformToTableDef(::hybridse::node::CreatePlanNode* create_n
storage_mode = dynamic_cast<hybridse::node::StorageModeNode *>(table_option)->GetStorageMode();
break;
}
case hybridse::node::kCompressType: {
compress_type = dynamic_cast<hybridse::node::CompressTypeNode *>(table_option)->GetCompressType();
break;
}
case hybridse::node::kDistributions: {
distribution_list =
dynamic_cast<hybridse::node::DistributionsNode*>(table_option)->GetDistributionList();
Expand Down Expand Up @@ -293,6 +298,7 @@ bool NodeAdapter::TransformToTableDef(::hybridse::node::CreatePlanNode* create_n
table->set_replica_num(replica_num);
table->set_partition_num(partition_num);
table->set_storage_mode(static_cast<common::StorageMode>(storage_mode));
table->set_compress_type(static_cast<type::CompressType>(compress_type));
bool has_generate_index = false;
std::set<std::string> index_names;
std::map<std::string, ::openmldb::common::ColumnDesc*> column_names;
Expand Down

0 comments on commit 69c5a8b

Please sign in to comment.