|
21 | 21 | #include "velox/common/base/tests/GTestUtils.h" |
22 | 22 | #include "velox/connectors/hive/HiveConnector.h" |
23 | 23 | #include "velox/connectors/hive/TableHandle.h" |
| 24 | +#include "velox/connectors/hive/iceberg/IcebergColumnHandle.h" |
24 | 25 |
|
25 | 26 | using namespace facebook::presto; |
26 | 27 | using namespace facebook::velox; |
@@ -185,3 +186,110 @@ TEST_F(PrestoToVeloxConnectorTest, hiveLowercasesColumnNames) { |
185 | 186 | EXPECT_EQ(dataColumnsType->nameOf(0), "mixedcasecol1"); |
186 | 187 | EXPECT_EQ(dataColumnsType->nameOf(1), "uppercasecol2"); |
187 | 188 | } |
| 189 | + |
| 190 | +namespace { |
| 191 | + |
| 192 | +protocol::iceberg::IcebergColumnHandle createIcebergColumnHandle( |
| 193 | + const std::string& name, |
| 194 | + int32_t fieldId, |
| 195 | + const std::string& type, |
| 196 | + protocol::iceberg::TypeCategory typeCategory = |
| 197 | + protocol::iceberg::TypeCategory::PRIMITIVE, |
| 198 | + const std::vector<protocol::iceberg::ColumnIdentity>& children = {}) { |
| 199 | + protocol::iceberg::IcebergColumnHandle column; |
| 200 | + column.columnIdentity.name = name; |
| 201 | + column.columnIdentity.id = fieldId; |
| 202 | + column.columnIdentity.typeCategory = typeCategory; |
| 203 | + column.columnIdentity.children = children; |
| 204 | + column.type = type; |
| 205 | + column.columnType = protocol::hive::ColumnType::REGULAR; |
| 206 | + return column; |
| 207 | +} |
| 208 | + |
| 209 | +} // namespace |
| 210 | + |
| 211 | +TEST_F(PrestoToVeloxConnectorTest, icebergColumnHandleSimple) { |
| 212 | + auto icebergColumn = createIcebergColumnHandle("col1", 1, "integer"); |
| 213 | + |
| 214 | + IcebergPrestoToVeloxConnector icebergConnector("iceberg"); |
| 215 | + auto handle = |
| 216 | + icebergConnector.toVeloxColumnHandle(&icebergColumn, *typeParser_); |
| 217 | + auto* icebergHandle = |
| 218 | + dynamic_cast<connector::hive::iceberg::IcebergColumnHandle*>( |
| 219 | + handle.get()); |
| 220 | + ASSERT_NE(icebergHandle, nullptr); |
| 221 | + |
| 222 | + EXPECT_EQ(icebergHandle->name(), "col1"); |
| 223 | + EXPECT_EQ(icebergHandle->dataType()->kind(), TypeKind::INTEGER); |
| 224 | + EXPECT_EQ(icebergHandle->field().fieldId, 1); |
| 225 | + EXPECT_TRUE(icebergHandle->field().children.empty()); |
| 226 | +} |
| 227 | + |
| 228 | +TEST_F(PrestoToVeloxConnectorTest, icebergColumnHandleNested) { |
| 229 | + protocol::iceberg::ColumnIdentity child1; |
| 230 | + child1.name = "child1"; |
| 231 | + child1.id = 2; |
| 232 | + child1.typeCategory = protocol::iceberg::TypeCategory::PRIMITIVE; |
| 233 | + |
| 234 | + protocol::iceberg::ColumnIdentity child2; |
| 235 | + child2.name = "child2"; |
| 236 | + child2.id = 3; |
| 237 | + child2.typeCategory = protocol::iceberg::TypeCategory::PRIMITIVE; |
| 238 | + |
| 239 | + auto icebergColumn = createIcebergColumnHandle( |
| 240 | + "struct_col", |
| 241 | + 1, |
| 242 | + "row(child1 integer, child2 varchar)", |
| 243 | + protocol::iceberg::TypeCategory::STRUCT, |
| 244 | + {child1, child2}); |
| 245 | + |
| 246 | + IcebergPrestoToVeloxConnector icebergConnector("iceberg"); |
| 247 | + auto handle = |
| 248 | + icebergConnector.toVeloxColumnHandle(&icebergColumn, *typeParser_); |
| 249 | + auto* icebergHandle = |
| 250 | + dynamic_cast<connector::hive::iceberg::IcebergColumnHandle*>( |
| 251 | + handle.get()); |
| 252 | + ASSERT_NE(icebergHandle, nullptr); |
| 253 | + |
| 254 | + EXPECT_EQ(icebergHandle->name(), "struct_col"); |
| 255 | + EXPECT_EQ(icebergHandle->dataType()->kind(), TypeKind::ROW); |
| 256 | + EXPECT_EQ(icebergHandle->field().fieldId, 1); |
| 257 | + ASSERT_EQ(icebergHandle->field().children.size(), 2); |
| 258 | + EXPECT_EQ(icebergHandle->field().children[0].fieldId, 2); |
| 259 | + EXPECT_EQ(icebergHandle->field().children[1].fieldId, 3); |
| 260 | +} |
| 261 | + |
| 262 | +TEST_F(PrestoToVeloxConnectorTest, icebergColumnHandleDeeplyNested) { |
| 263 | + protocol::iceberg::ColumnIdentity inner; |
| 264 | + inner.name = "inner"; |
| 265 | + inner.id = 3; |
| 266 | + inner.typeCategory = protocol::iceberg::TypeCategory::PRIMITIVE; |
| 267 | + |
| 268 | + protocol::iceberg::ColumnIdentity middle; |
| 269 | + middle.name = "middle"; |
| 270 | + middle.id = 2; |
| 271 | + middle.typeCategory = protocol::iceberg::TypeCategory::STRUCT; |
| 272 | + middle.children = {inner}; |
| 273 | + |
| 274 | + auto icebergColumn = createIcebergColumnHandle( |
| 275 | + "outer", |
| 276 | + 1, |
| 277 | + "row(middle row(inner bigint))", |
| 278 | + protocol::iceberg::TypeCategory::STRUCT, |
| 279 | + {middle}); |
| 280 | + |
| 281 | + IcebergPrestoToVeloxConnector icebergConnector("iceberg"); |
| 282 | + auto handle = |
| 283 | + icebergConnector.toVeloxColumnHandle(&icebergColumn, *typeParser_); |
| 284 | + auto* icebergHandle = |
| 285 | + dynamic_cast<connector::hive::iceberg::IcebergColumnHandle*>( |
| 286 | + handle.get()); |
| 287 | + ASSERT_NE(icebergHandle, nullptr); |
| 288 | + |
| 289 | + EXPECT_EQ(icebergHandle->name(), "outer"); |
| 290 | + EXPECT_EQ(icebergHandle->field().fieldId, 1); |
| 291 | + ASSERT_EQ(icebergHandle->field().children.size(), 1); |
| 292 | + EXPECT_EQ(icebergHandle->field().children[0].fieldId, 2); |
| 293 | + ASSERT_EQ(icebergHandle->field().children[0].children.size(), 1); |
| 294 | + EXPECT_EQ(icebergHandle->field().children[0].children[0].fieldId, 3); |
| 295 | +} |
0 commit comments