| 89 | namespace acero { |
| 90 | |
| 91 | TEST(AggregateSchema, NoKeys) { |
| 92 | auto input_schema = schema({field("x", int32())}); |
| 93 | EXPECT_RAISES_WITH_MESSAGE_THAT( |
| 94 | Invalid, HasSubstr("is a hash aggregate function"), |
| 95 | aggregate::MakeOutputSchema(input_schema, {}, {}, |
| 96 | {{"hash_count", nullptr, "x", "hash_count"}})); |
| 97 | ASSERT_OK_AND_ASSIGN(auto output_schema, |
| 98 | aggregate::MakeOutputSchema(input_schema, {}, {}, |
| 99 | {{"count", nullptr, "x", "count"}})); |
| 100 | AssertSchemaEqual(schema({field("count", int64())}), output_schema); |
| 101 | } |
| 102 | |
| 103 | TEST(AggregateSchema, SingleKey) { |
| 104 | auto input_schema = schema({field("x", int32()), field("y", int32())}); |
| 105 | EXPECT_RAISES_WITH_MESSAGE_THAT( |
| 106 | Invalid, HasSubstr("is a scalar aggregate function"), |
| 107 | aggregate::MakeOutputSchema(input_schema, {FieldRef("y")}, {}, |
| 108 | {{"count", nullptr, "x", "count"}})); |
| 109 | ASSERT_OK_AND_ASSIGN( |
| 110 | auto output_schema, |
| 111 | aggregate::MakeOutputSchema(input_schema, {FieldRef("y")}, {}, |
| 112 | {{"hash_count", nullptr, "x", "hash_count"}})); |
| 113 | AssertSchemaEqual(schema({field("y", int32()), field("hash_count", int64())}), |
| 114 | output_schema); |
| 115 | } |
| 116 | |
| 117 | TEST(AggregateSchema, DoubleKey) { |
| 118 | auto input_schema = |
| 119 | schema({field("x", int32()), field("y", int32()), field("z", int32())}); |
| 120 | ASSERT_OK_AND_ASSIGN( |
| 121 | auto output_schema, |
| 122 | aggregate::MakeOutputSchema(input_schema, {FieldRef("z"), FieldRef("y")}, {}, |
| 123 | {{"hash_count", nullptr, "x", "hash_count"}})); |
| 124 | AssertSchemaEqual( |
| 125 | schema({field("z", int32()), field("y", int32()), field("hash_count", int64())}), |
| 126 | output_schema); |
| 127 | } |
| 128 | |
| 129 | TEST(AggregateSchema, SingleSegmentKey) { |
| 130 | auto input_schema = schema({field("x", int32()), field("y", int32())}); |
| 131 | ASSERT_OK_AND_ASSIGN(auto output_schema, |
| 132 | aggregate::MakeOutputSchema(input_schema, {}, {FieldRef("y")}, |
| 133 | {{"count", nullptr, "x", "count"}})); |
| 134 | AssertSchemaEqual(schema({field("y", int32()), field("count", int64())}), |
| 135 | output_schema); |
| 136 | } |
| 137 | |
| 138 | TEST(AggregateSchema, DoubleSegmentKey) { |
| 139 | auto input_schema = |
| 140 | schema({field("x", int32()), field("y", int32()), field("z", int32())}); |
| 141 | ASSERT_OK_AND_ASSIGN( |
| 142 | auto output_schema, |
| 143 | aggregate::MakeOutputSchema(input_schema, {}, {FieldRef("z"), FieldRef("y")}, |
| 144 | {{"count", nullptr, "x", "count"}})); |
| 145 | AssertSchemaEqual( |
| 146 | schema({field("z", int32()), field("y", int32()), field("count", int64())}), |
| 147 | output_schema); |
| 148 | } |
no test coverage detected