decster commented on a change in pull request #3637: URL: https://github.com/apache/incubator-doris/pull/3637#discussion_r428532791
########## File path: be/src/olap/memory/partial_row_batch.cpp ########## @@ -0,0 +1,267 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. + +#include "olap/memory/partial_row_batch.h" + +#include "util/bitmap.h" + +namespace doris { +namespace memory { + +// Methods for PartialRowBatch + +PartialRowBatch::PartialRowBatch(scoped_refptr<Schema>* schema, size_t byte_capacity, + size_t row_capacity) + : _schema(*schema) { + _data = reinterpret_cast<uint8_t*>(aligned_malloc(byte_capacity, 64)); + _bsize = 0; + if (!_data) { + _byte_capacity = 0; + _row_capacity = 0; + } + _byte_capacity = byte_capacity; + _row_capacity = row_capacity; +} + +PartialRowBatch::~PartialRowBatch() { + if (_data) { + free(_data); + _data = nullptr; + } + _bsize = 0; + _byte_capacity = 0; + _row_capacity = 0; +} + +const uint8_t* PartialRowBatch::get_row(size_t idx) const { + if (!_data || idx >= _row_offsets.size()) { + return nullptr; + } + return _data + _row_offsets[idx] + 4; +} + +// Methods for PartialRowWriter + +PartialRowWriter::PartialRowWriter(const Schema& schema) + : _schema(schema), _bit_set_size(_schema.cid_size()), _bit_null_size(0) { + _temp_cells.resize(_schema.cid_size()); +} + +PartialRowWriter::~PartialRowWriter() {} + +void PartialRowWriter::start_row() { + _bit_null_size = 0; + memset(&(_temp_cells[0]), 0, sizeof(CellInfo) * _temp_cells.size()); +} + +Status PartialRowWriter::write_row_to_batch(PartialRowBatch* batch) { + if (batch->_row_offsets.size() >= batch->row_capacity()) { + return Status::InvalidArgument("over capacity"); + } + size_t row_byte_size = byte_size(); + if (batch->byte_size() + row_byte_size + 4 > batch->byte_capacity()) { + return Status::InvalidArgument("over capacity"); + } + *reinterpret_cast<uint32_t*>(batch->_data + batch->_bsize) = row_byte_size; + uint8_t* pos = batch->_data + batch->_bsize + 4; + RETURN_IF_ERROR(write(&pos)); + batch->_row_offsets.push_back(batch->_bsize); + batch->_bsize = pos - batch->_data; + return Status::OK(); +} + +Status PartialRowWriter::set(const string& col, const void* data) { + auto cs = _schema.get_by_name(col); + if (!cs) { + return Status::NotFound("col name not found"); + } + if (cs->type() == ColumnType::OLAP_FIELD_TYPE_VARCHAR) { + return Status::NotSupported("var length type not supported"); + } + uint32_t cid = cs->cid(); + if (cs->is_nullable() || data) { + if (cs->is_nullable() && !_temp_cells[cid].isnullable) { + _bit_null_size++; + } + _temp_cells[cid].isnullable = cs->is_nullable(); + _temp_cells[cid].isset = 1; + _temp_cells[cid].data = reinterpret_cast<const uint8_t*>(data); + } else { + return Status::InvalidArgument("not nullable"); + } + return Status::OK(); +} + +Status PartialRowWriter::set(uint32_t cid, const void* data) { + auto cs = _schema.get_by_cid(cid); + if (!cs) { + return Status::NotFound("cid not found"); + } + if (cs->is_nullable() || data) { + if (cs->is_nullable() && !_temp_cells[cid].isnullable) { + _bit_null_size++; + } + _temp_cells[cid].isnullable = cs->is_nullable(); + _temp_cells[cid].isset = 1; + _temp_cells[cid].data = reinterpret_cast<const uint8_t*>(data); + } else { + return Status::InvalidArgument("not nullable column set to null"); + } Review comment: fixed ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org