| 135 | } |
| 136 | |
| 137 | void RawValue::WriteNonNullPrimitive(const void* value, void* dst, const ColumnType& type, |
| 138 | MemPool* pool) { |
| 139 | DCHECK(value != NULL); |
| 140 | switch (type.type) { |
| 141 | case TYPE_NULL: |
| 142 | break; |
| 143 | case TYPE_BOOLEAN: |
| 144 | // Unlike the other scalar types, bool has a limited set of valid values, so if |
| 145 | // 'dst' is uninitialized memory and happens to point to a value that is not a valid |
| 146 | // bool, then dereferencing it via *reinterpret_cast<bool*>(dst) is undefined |
| 147 | // behavior. |
| 148 | memcpy(dst, value, sizeof(bool)); |
| 149 | break; |
| 150 | case TYPE_TINYINT: |
| 151 | *reinterpret_cast<int8_t*>(dst) = *reinterpret_cast<const int8_t*>(value); |
| 152 | break; |
| 153 | case TYPE_SMALLINT: |
| 154 | *reinterpret_cast<int16_t*>(dst) = *reinterpret_cast<const int16_t*>(value); |
| 155 | break; |
| 156 | case TYPE_INT: |
| 157 | *reinterpret_cast<int32_t*>(dst) = *reinterpret_cast<const int32_t*>(value); |
| 158 | break; |
| 159 | case TYPE_DATE: |
| 160 | *reinterpret_cast<DateValue*>(dst) = *reinterpret_cast<const DateValue*>(value); |
| 161 | break; |
| 162 | case TYPE_BIGINT: |
| 163 | *reinterpret_cast<int64_t*>(dst) = *reinterpret_cast<const int64_t*>(value); |
| 164 | break; |
| 165 | case TYPE_FLOAT: |
| 166 | *reinterpret_cast<float*>(dst) = *reinterpret_cast<const float*>(value); |
| 167 | break; |
| 168 | case TYPE_DOUBLE: |
| 169 | *reinterpret_cast<double*>(dst) = *reinterpret_cast<const double*>(value); |
| 170 | break; |
| 171 | case TYPE_TIMESTAMP: |
| 172 | *reinterpret_cast<TimestampValue*>(dst) = |
| 173 | *reinterpret_cast<const TimestampValue*>(value); |
| 174 | break; |
| 175 | case TYPE_STRING: |
| 176 | case TYPE_VARCHAR: { |
| 177 | const StringValue* src = reinterpret_cast<const StringValue*>(value); |
| 178 | StringValue* dest = reinterpret_cast<StringValue*>(dst); |
| 179 | dest->Assign(*src); |
| 180 | if (type.type == TYPE_VARCHAR) DCHECK_LE(dest->Len(), type.len); |
| 181 | if (pool != NULL) { |
| 182 | // Note: if this changes to TryAllocate(), SlotDescriptor::CodegenWriteToSlot() |
| 183 | // will need to reflect this change as well (the codegen'd Allocate() call is |
| 184 | // actually generated in SlotDescriptor::CodegenWriteStringOrCollectionToSlot()). |
| 185 | dest->Assign(reinterpret_cast<char*>(pool->Allocate(dest->Len())), dest->Len()); |
| 186 | Ubsan::MemCpy(dest->Ptr(), src->Ptr(), dest->Len()); |
| 187 | } |
| 188 | break; |
| 189 | } |
| 190 | case TYPE_CHAR: |
| 191 | DCHECK_EQ(type.type, TYPE_CHAR); |
| 192 | memcpy(dst, value, type.len); |
| 193 | break; |
| 194 | case TYPE_DECIMAL: |
nothing calls this directly
no test coverage detected