| 260 | |
| 261 | template<PrimitiveType SLOT_TYPE, bool ENCODED> |
| 262 | Status OrcStringColumnReader::ReadValueInternal(int row_idx, Tuple* tuple) { |
| 263 | if (IsNull(DCHECK_NOTNULL(batch_), row_idx)) { |
| 264 | SetNullSlot(tuple); |
| 265 | return Status::OK(); |
| 266 | } |
| 267 | char* src_ptr; |
| 268 | int src_len; |
| 269 | |
| 270 | if (ENCODED) { |
| 271 | DCHECK(batch_->isEncoded); |
| 272 | orc::EncodedStringVectorBatch* currentBatch = |
| 273 | static_cast<orc::EncodedStringVectorBatch*>(batch_); |
| 274 | |
| 275 | orc::DataBuffer<int64_t>& offsets = currentBatch->dictionary->dictionaryOffset; |
| 276 | int64_t index = currentBatch->index[row_idx]; |
| 277 | if (UNLIKELY(index < 0 || static_cast<uint64_t>(index) + 1 >= offsets.size())) { |
| 278 | return Status(Substitute("Corrupt ORC file: $0. Index ($1) out of range [0, $2) in " |
| 279 | "StringDictionary.", scanner_->filename(), index, offsets.size()));; |
| 280 | } |
| 281 | src_ptr = blob_ + offsets[index]; |
| 282 | src_len = offsets[index + 1] - offsets[index]; |
| 283 | } else { |
| 284 | // The pointed data is now in blob_, a buffer handled by Impala. |
| 285 | src_ptr = blob_ + (batch_->data[row_idx] - batch_->blob.data()); |
| 286 | src_len = batch_->length[row_idx]; |
| 287 | } |
| 288 | int dst_len = slot_desc_->type().len; |
| 289 | if (SLOT_TYPE == TYPE_CHAR) { |
| 290 | DCHECK_EQ(slot_desc_->type().type, TYPE_CHAR); |
| 291 | int unpadded_len = min(dst_len, static_cast<int>(src_len)); |
| 292 | char* dst_char = reinterpret_cast<char*>(GetSlot(tuple)); |
| 293 | memcpy(dst_char, src_ptr, unpadded_len); |
| 294 | StringValue::PadWithSpaces(dst_char, dst_len, unpadded_len); |
| 295 | return Status::OK(); |
| 296 | } |
| 297 | StringValue* dst = reinterpret_cast<StringValue*>(GetSlot(tuple)); |
| 298 | dst->Assign(src_ptr, src_len); |
| 299 | if (SLOT_TYPE == TYPE_VARCHAR && dst_len < src_len) { |
| 300 | dst->SetLen(dst_len); |
| 301 | } |
| 302 | return Status::OK(); |
| 303 | } |
| 304 | |
| 305 | Status OrcTimestampReader::ReadValue(int row_idx, Tuple* tuple, MemPool* pool) { |
| 306 | if (IsNull(DCHECK_NOTNULL(batch_), row_idx)) { |