| 53 | }; |
| 54 | |
| 55 | TEST_F(ExprStatsTest, printWithStats) { |
| 56 | vector_size_t size = 1'024; |
| 57 | |
| 58 | auto data = makeRowVector({ |
| 59 | makeFlatVector<int32_t>(size, [](auto row) { return row; }), |
| 60 | makeFlatVector<int32_t>(size, [](auto row) { return row % 7; }), |
| 61 | }); |
| 62 | |
| 63 | auto rowType = asRowType(data->type()); |
| 64 | { |
| 65 | auto exprSet = |
| 66 | compileExpressions({"(c0 + 3) * c1", "(c0 + c1) % 2 = 0"}, rowType); |
| 67 | |
| 68 | // Check stats before evaluation. |
| 69 | ASSERT_EQ( |
| 70 | exec::printExprWithStats(*exprSet), |
| 71 | "multiply [cpu time: 0ns, rows: 0, batches: 0] -> BIGINT [#1]\n" |
| 72 | " plus [cpu time: 0ns, rows: 0, batches: 0] -> BIGINT [#2]\n" |
| 73 | " cast(c0 as BIGINT) [cpu time: 0ns, rows: 0, batches: 0] -> BIGINT [#3]\n" |
| 74 | " c0 [cpu time: 0ns, rows: 0, batches: 0] -> INTEGER [#4]\n" |
| 75 | " 3:BIGINT [cpu time: 0ns, rows: 0, batches: 0] -> BIGINT [#5]\n" |
| 76 | " cast(c1 as BIGINT) [cpu time: 0ns, rows: 0, batches: 0] -> BIGINT [#6]\n" |
| 77 | " c1 [cpu time: 0ns, rows: 0, batches: 0] -> INTEGER [#7]\n" |
| 78 | "\n" |
| 79 | "eq [cpu time: 0ns, rows: 0, batches: 0] -> BOOLEAN [#8]\n" |
| 80 | " mod [cpu time: 0ns, rows: 0, batches: 0] -> BIGINT [#9]\n" |
| 81 | " cast(plus as BIGINT) [cpu time: 0ns, rows: 0, batches: 0] -> BIGINT [#10]\n" |
| 82 | " plus [cpu time: 0ns, rows: 0, batches: 0] -> INTEGER [#11]\n" |
| 83 | " c0 -> INTEGER [CSE #4]\n" |
| 84 | " c1 -> INTEGER [CSE #7]\n" |
| 85 | " 2:BIGINT [cpu time: 0ns, rows: 0, batches: 0] -> BIGINT [#12]\n" |
| 86 | " 0:BIGINT [cpu time: 0ns, rows: 0, batches: 0] -> BIGINT [#13]\n"); |
| 87 | |
| 88 | evaluate(*exprSet, data); |
| 89 | |
| 90 | // Check stats after evaluation. |
| 91 | ASSERT_THAT( |
| 92 | exec::printExprWithStats(*exprSet), |
| 93 | ::testing::MatchesRegex( |
| 94 | "multiply .cpu time: .+, rows: 1024, batches: 1. -> BIGINT .#1.\n" |
| 95 | " plus .cpu time: .+, rows: 1024, batches: 1. -> BIGINT .#2.\n" |
| 96 | " cast.c0 as BIGINT. .cpu time: .+, rows: 1024, batches: 1. -> BIGINT .#3.\n" |
| 97 | " c0 .cpu time: 0ns, rows: 2048, batches: 2. -> INTEGER .#4.\n" |
| 98 | " 3:BIGINT .cpu time: 0ns, rows: 1024, batches: 1. -> BIGINT .#5.\n" |
| 99 | " cast.c1 as BIGINT. .cpu time: .+, rows: 1024, batches: 1. -> BIGINT .#6.\n" |
| 100 | " c1 .cpu time: 0ns, rows: 2048, batches: 2. -> INTEGER .#7.\n" |
| 101 | "\n" |
| 102 | "eq .cpu time: .+, rows: 1024, batches: 1. -> BOOLEAN .#8.\n" |
| 103 | " mod .cpu time: .+, rows: 1024, batches: 1. -> BIGINT .#9.\n" |
| 104 | " cast.plus as BIGINT. .cpu time: .+, rows: 1024, batches: 1. -> BIGINT .#10.\n" |
| 105 | " plus .cpu time: .+, rows: 1024, batches: 1. -> INTEGER .#11.\n" |
| 106 | " c0 -> INTEGER .CSE #4.\n" |
| 107 | " c1 -> INTEGER .CSE #7.\n" |
| 108 | " 2:BIGINT .cpu time: 0ns, rows: 1024, batches: 1. -> BIGINT .#12.\n" |
| 109 | " 0:BIGINT .cpu time: 0ns, rows: 1024, batches: 1. -> BIGINT .#13.\n")); |
| 110 | } |
| 111 | |
| 112 | // Verify that common sub-expressions are identified properly. |
nothing calls this directly
no test coverage detected