|
15 | 15 | */ |
16 | 16 | #include "velox/exec/tests/utils/PlanBuilder.h" |
17 | 17 | #include "velox/common/base/tests/GTestUtils.h" |
| 18 | +#include "velox/core/Expressions.h" |
18 | 19 | #include "velox/exec/WindowFunction.h" |
19 | 20 | #include "velox/functions/prestosql/aggregates/RegisterAggregateFunctions.h" |
20 | 21 | #include "velox/functions/prestosql/registration/RegistrationFunctions.h" |
| 22 | +#include "velox/parse/Expressions.h" |
| 23 | +#include "velox/parse/IExpr.h" |
21 | 24 | #include "velox/parse/TypeResolver.h" |
22 | 25 | #include "velox/vector/tests/utils/VectorTestBase.h" |
23 | 26 |
|
@@ -250,4 +253,52 @@ TEST_F(PlanBuilderTest, missingOutputType) { |
250 | 253 | "outputType must be specified"); |
251 | 254 | } |
252 | 255 |
|
| 256 | +TEST_F(PlanBuilderTest, projectExpressions) { |
| 257 | + // Non-typed Expressions. |
| 258 | + // Simple field access. |
| 259 | + auto data = ROW({"c0"}, {BIGINT()}); |
| 260 | + VELOX_CHECK_EQ( |
| 261 | + PlanBuilder() |
| 262 | + .tableScan("tmp", data) |
| 263 | + .projectExpressions( |
| 264 | + {std::make_shared<core::FieldAccessExpr>("c0", std::nullopt)}) |
| 265 | + .planNode() |
| 266 | + ->toString(true, false), |
| 267 | + "-- Project[1][expressions: (c0:BIGINT, ROW[\"c0\"])] -> c0:BIGINT\n"); |
| 268 | + // Dereference test using field access query. |
| 269 | + data = ROW({"c0"}, {ROW({"field0"}, {BIGINT()})}); |
| 270 | + VELOX_CHECK_EQ( |
| 271 | + PlanBuilder() |
| 272 | + .tableScan("tmp", data) |
| 273 | + .projectExpressions({std::make_shared<core::FieldAccessExpr>( |
| 274 | + "field0", |
| 275 | + std::nullopt, |
| 276 | + std::vector<core::ExprPtr>{ |
| 277 | + std::make_shared<core::FieldAccessExpr>( |
| 278 | + "c0", std::nullopt)})}) |
| 279 | + .planNode() |
| 280 | + ->toString(true, false), |
| 281 | + "-- Project[1][expressions: (field0:BIGINT, ROW[\"c0\"][field0])] -> field0:BIGINT\n"); |
| 282 | + |
| 283 | + // Test Typed Expressions |
| 284 | + VELOX_CHECK_EQ( |
| 285 | + PlanBuilder() |
| 286 | + .tableScan("tmp", ROW({"c0"}, {ROW({VARCHAR()})})) |
| 287 | + .projectExpressions( |
| 288 | + {std::make_shared<core::FieldAccessTypedExpr>(VARCHAR(), "c0")}) |
| 289 | + .planNode() |
| 290 | + ->toString(true, false), |
| 291 | + "-- Project[1][expressions: (p0:VARCHAR, \"c0\")] -> p0:VARCHAR\n"); |
| 292 | + VELOX_CHECK_EQ( |
| 293 | + PlanBuilder() |
| 294 | + .tableScan("tmp", ROW({"c0"}, {ROW({VARCHAR()})})) |
| 295 | + .projectExpressions({std::make_shared<core::FieldAccessTypedExpr>( |
| 296 | + VARCHAR(), |
| 297 | + std::make_shared<core::FieldAccessTypedExpr>(VARCHAR(), "c0"), |
| 298 | + "field0")}) |
| 299 | + .planNode() |
| 300 | + ->toString(true, false), |
| 301 | + "-- Project[1][expressions: (p0:VARCHAR, \"c0\"[\"field0\"])] -> p0:VARCHAR\n"); |
| 302 | +} |
| 303 | + |
253 | 304 | } // namespace facebook::velox::exec::test |
0 commit comments