OmniSciDB  2e3a973ef4
AbstractBuffer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /*
18 This file implements some of the longer functions used by the AbstractBuffer interface
19 outside of the header file in order to prevent unnecessary re-compilation.
20 */
21 
22 #include "AbstractBuffer.h"
23 
24 namespace Data_Namespace {
25 
26 void AbstractBuffer::initEncoder(const SQLTypeInfo& tmp_sql_type) {
27  sql_type_ = tmp_sql_type;
28  encoder_.reset(Encoder::Create(this, sql_type_));
29  LOG_IF(FATAL, encoder_ == nullptr)
30  << "Failed to create encoder for SQL Type " << sql_type_.get_type_name();
31 }
32 
34  if (src_buffer->hasEncoder()) {
35  if (!hasEncoder()) {
36  initEncoder(src_buffer->sql_type_);
37  }
38  encoder_->copyMetadata(src_buffer->encoder_.get());
39  } else {
40  encoder_ = nullptr;
41  }
42 }
43 
44 void AbstractBuffer::copyTo(AbstractBuffer* destination_buffer, const size_t num_bytes) {
45  size_t chunk_size = (num_bytes == 0) ? size() : num_bytes;
46  destination_buffer->reserve(chunk_size);
47  if (isUpdated()) {
48  read(destination_buffer->getMemoryPtr(),
49  chunk_size,
50  0,
51  destination_buffer->getType(),
52  destination_buffer->getDeviceId());
53  } else {
54  read(destination_buffer->getMemoryPtr() + destination_buffer->size(),
55  chunk_size - destination_buffer->size(),
56  destination_buffer->size(),
57  destination_buffer->getType(),
58  destination_buffer->getDeviceId());
59  }
60  destination_buffer->setSize(chunk_size);
61  destination_buffer->syncEncoder(this);
62 }
63 
65  encoder_ = nullptr;
66  size_ = 0;
67 }
68 } // namespace Data_Namespace
void syncEncoder(const AbstractBuffer *src_buffer)
virtual int8_t * getMemoryPtr()=0
static Encoder * Create(Data_Namespace::AbstractBuffer *buffer, const SQLTypeInfo sqlType)
Definition: Encoder.cpp:26
virtual MemoryLevel getType() const =0
void initEncoder(const SQLTypeInfo &tmp_sql_type)
#define LOG_IF(severity, condition)
Definition: Logger.h:287
virtual void read(int8_t *const dst, const size_t num_bytes, const size_t offset=0, const MemoryLevel dst_buffer_type=CPU_LEVEL, const int dst_device_id=-1)=0
An AbstractBuffer is a unit of data management for a data manager.
std::string get_type_name() const
Definition: sqltypes.h:362
std::unique_ptr< Encoder > encoder_
void setSize(const size_t size)
void copyTo(AbstractBuffer *destination_buffer, const size_t num_bytes=0)
virtual void reserve(size_t num_bytes)=0