| 41 | } |
| 42 | |
| 43 | TEST(ConvertColumnReader, betweenNumericWithoutOverflows) { |
| 44 | constexpr int DEFAULT_MEM_STREAM_SIZE = 10 * 1024 * 1024; |
| 45 | constexpr int TEST_CASES = 1024; |
| 46 | MemoryOutputStream memStream(DEFAULT_MEM_STREAM_SIZE); |
| 47 | std::unique_ptr<Type> fileType( |
| 48 | Type::buildTypeFromString("struct<t1:boolean,t2:int,t3:double,t4:float>")); |
| 49 | std::shared_ptr<Type> readType( |
| 50 | Type::buildTypeFromString("struct<t1:int,t2:boolean,t3:bigint,t4:boolean>")); |
| 51 | WriterOptions options; |
| 52 | options.setUseTightNumericVector(true); |
| 53 | auto writer = createWriter(*fileType, &memStream, options); |
| 54 | auto batch = writer->createRowBatch(TEST_CASES); |
| 55 | auto& structBatch = dynamic_cast<StructVectorBatch&>(*batch); |
| 56 | auto& c0 = dynamic_cast<ByteVectorBatch&>(*structBatch.fields[0]); |
| 57 | auto& c1 = dynamic_cast<IntVectorBatch&>(*structBatch.fields[1]); |
| 58 | auto& c2 = dynamic_cast<DoubleVectorBatch&>(*structBatch.fields[2]); |
| 59 | auto& c3 = dynamic_cast<FloatVectorBatch&>(*structBatch.fields[3]); |
| 60 | |
| 61 | structBatch.numElements = c0.numElements = c1.numElements = c2.numElements = c3.numElements = |
| 62 | TEST_CASES; |
| 63 | |
| 64 | for (size_t i = 0; i < TEST_CASES; i++) { |
| 65 | c0.data[i] = i % 2 || i % 3 ? true : false; |
| 66 | c1.data[i] = static_cast<int>((TEST_CASES / 2 - i) * TEST_CASES); |
| 67 | c2.data[i] = static_cast<double>(TEST_CASES - i) / (TEST_CASES / 2); |
| 68 | c3.data[i] = static_cast<float>(TEST_CASES - i) / (TEST_CASES / 2); |
| 69 | } |
| 70 | |
| 71 | writer->add(*batch); |
| 72 | writer->close(); |
| 73 | |
| 74 | auto inStream = std::make_unique<MemoryInputStream>(memStream.getData(), memStream.getLength()); |
| 75 | auto pool = getDefaultPool(); |
| 76 | auto reader = createReader(*pool, std::move(inStream)); |
| 77 | RowReaderOptions rowReaderOpts; |
| 78 | rowReaderOpts.setReadType(readType); |
| 79 | rowReaderOpts.setUseTightNumericVector(true); |
| 80 | auto rowReader = reader->createRowReader(rowReaderOpts); |
| 81 | auto readBatch = rowReader->createRowBatch(TEST_CASES); |
| 82 | EXPECT_EQ(true, rowReader->next(*readBatch)); |
| 83 | auto& readStructBatch = dynamic_cast<StructVectorBatch&>(*readBatch); |
| 84 | auto& readC0 = dynamic_cast<IntVectorBatch&>(*readStructBatch.fields[0]); |
| 85 | auto& readC1 = dynamic_cast<ByteVectorBatch&>(*readStructBatch.fields[1]); |
| 86 | auto& readC2 = dynamic_cast<LongVectorBatch&>(*readStructBatch.fields[2]); |
| 87 | auto& readC3 = dynamic_cast<ByteVectorBatch&>(*readStructBatch.fields[3]); |
| 88 | |
| 89 | for (size_t i = 0; i < TEST_CASES; i++) { |
| 90 | EXPECT_EQ(readC0.data[i], i % 2 || i % 3 ? 1 : 0); |
| 91 | EXPECT_TRUE(readC1.data[i] == true || i == TEST_CASES / 2); |
| 92 | EXPECT_EQ(readC2.data[i], |
| 93 | i > TEST_CASES / 2 ? 0 : static_cast<int64_t>((TEST_CASES - i) / (TEST_CASES / 2))); |
| 94 | EXPECT_TRUE(readC3.data[i] == true || i > TEST_CASES / 2); |
| 95 | } |
| 96 | |
| 97 | rowReaderOpts.setUseTightNumericVector(false); |
| 98 | rowReader = reader->createRowReader(rowReaderOpts); |
| 99 | readBatch = rowReader->createRowBatch(TEST_CASES); |
| 100 | EXPECT_THROW(rowReader->next(*readBatch), SchemaEvolutionError); |
nothing calls this directly
no test coverage detected