| 987 | } |
| 988 | |
| 989 | bool RowProject::Project(const int8_t* row_ptr, uint32_t size, |
| 990 | int8_t** output_ptr, uint32_t* out_size) { |
| 991 | if (row_ptr == NULL || output_ptr == NULL || out_size == NULL) return false; |
| 992 | uint8_t version = fedb::codec::RowView::GetSchemaVersion(row_ptr); |
| 993 | if (version != cur_ver_) { |
| 994 | auto it = vers_views_.find(version); |
| 995 | if (it == vers_views_.end()) { |
| 996 | LOG(WARNING) << "not found valid row view for ver " << unsigned(version); |
| 997 | return false; |
| 998 | } |
| 999 | cur_rv_ = it->second; |
| 1000 | cur_ver_ = version; |
| 1001 | cur_schema_ = vers_schema_.find(version)->second; |
| 1002 | } |
| 1003 | bool ok = cur_rv_->Reset(row_ptr, size); |
| 1004 | if (!ok) return false; |
| 1005 | uint32_t str_size = 0; |
| 1006 | for (int32_t i = 0; i < plist_.size(); i++) { |
| 1007 | uint32_t idx = plist_.Get(i); |
| 1008 | const ::fedb::common::ColumnDesc& column = cur_schema_->Get(idx); |
| 1009 | if (column.data_type() == ::fedb::type::kVarchar || |
| 1010 | column.data_type() == ::fedb::type::kString) { |
| 1011 | if (cur_rv_->IsNULL(idx)) continue; |
| 1012 | uint32_t length = 0; |
| 1013 | char* content = nullptr; |
| 1014 | int32_t ret = cur_rv_->GetString(idx, &content, &length); |
| 1015 | if (ret != 0) { |
| 1016 | return false; |
| 1017 | } |
| 1018 | str_size += length; |
| 1019 | } |
| 1020 | } |
| 1021 | uint32_t total_size = row_builder_->CalTotalLength(str_size); |
| 1022 | char* ptr = new char[total_size]; |
| 1023 | row_builder_->SetBuffer(reinterpret_cast<int8_t*>(ptr), total_size); |
| 1024 | for (int32_t i = 0; i < plist_.size(); i++) { |
| 1025 | uint32_t idx = plist_.Get(i); |
| 1026 | const ::fedb::common::ColumnDesc& column = cur_schema_->Get(idx); |
| 1027 | int32_t ret = 0; |
| 1028 | if (cur_rv_->IsNULL(idx)) { |
| 1029 | row_builder_->AppendNULL(); |
| 1030 | continue; |
| 1031 | } |
| 1032 | switch (column.data_type()) { |
| 1033 | case ::fedb::type::kBool: { |
| 1034 | bool val = false; |
| 1035 | ret = cur_rv_->GetBool(idx, &val); |
| 1036 | if (ret == 0) row_builder_->AppendBool(val); |
| 1037 | break; |
| 1038 | } |
| 1039 | case ::fedb::type::kSmallInt: { |
| 1040 | int16_t val = 0; |
| 1041 | ret = cur_rv_->GetInt16(idx, &val); |
| 1042 | if (ret == 0) row_builder_->AppendInt16(val); |
| 1043 | break; |
| 1044 | } |
| 1045 | case ::fedb::type::kInt: { |
| 1046 | int32_t val = 0; |