|
67 | 67 | import java.util.Optional; |
68 | 68 | import java.util.function.Consumer; |
69 | 69 |
|
| 70 | +import static com.facebook.presto.SystemSessionProperties.CHECK_ACCESS_CONTROL_ON_UTILIZED_COLUMNS_ONLY; |
| 71 | +import static com.facebook.presto.SystemSessionProperties.CHECK_ACCESS_CONTROL_WITH_SUBFIELDS; |
70 | 72 | import static com.facebook.presto.common.type.BigintType.BIGINT; |
71 | 73 | import static com.facebook.presto.common.type.DoubleType.DOUBLE; |
72 | 74 | import static com.facebook.presto.common.type.TypeSignature.parseTypeSignature; |
@@ -106,6 +108,8 @@ public class AbstractAnalyzerTest |
106 | 108 | protected static final Session CLIENT_SESSION = testSessionBuilder() |
107 | 109 | .setCatalog(TPCH_CATALOG) |
108 | 110 | .setSchema("s1") |
| 111 | + .setSystemProperty(CHECK_ACCESS_CONTROL_ON_UTILIZED_COLUMNS_ONLY, "true") |
| 112 | + .setSystemProperty(CHECK_ACCESS_CONTROL_WITH_SUBFIELDS, "true") |
109 | 113 | .build(); |
110 | 114 |
|
111 | 115 | protected static final SqlInvokedFunction SQL_FUNCTION_SQUARE = new SqlInvokedFunction( |
@@ -353,6 +357,103 @@ public void setup() |
353 | 357 | new SchemaTableName("s1", "v5"), |
354 | 358 | ImmutableList.of(ColumnMetadata.builder().setName("a").setType(BIGINT).build())); |
355 | 359 | inSetupTransaction(session -> metadata.createView(session, TPCH_CATALOG, viewMetadata5, viewData5, false)); |
| 360 | + |
| 361 | + String viewDataInvoker1 = JsonCodec.jsonCodec(ViewDefinition.class).toJson( |
| 362 | + new ViewDefinition( |
| 363 | + "select a,b,c from t1", |
| 364 | + Optional.of(TPCH_CATALOG), |
| 365 | + Optional.of("s1"), |
| 366 | + ImmutableList.of( |
| 367 | + new ViewDefinition.ViewColumn("a", BIGINT), |
| 368 | + new ViewDefinition.ViewColumn("b", BIGINT), |
| 369 | + new ViewDefinition.ViewColumn("c", BIGINT)), |
| 370 | + Optional.empty(), |
| 371 | + true)); |
| 372 | + |
| 373 | + ConnectorTableMetadata viewMetadataInvoker1 = new ConnectorTableMetadata( |
| 374 | + new SchemaTableName("s1", "view_invoker1"), |
| 375 | + ImmutableList.of( |
| 376 | + ColumnMetadata.builder().setName("a").setType(BIGINT).build(), |
| 377 | + ColumnMetadata.builder().setName("b").setType(BIGINT).build(), |
| 378 | + ColumnMetadata.builder().setName("c").setType(BIGINT).build())); |
| 379 | + inSetupTransaction(session -> metadata.createView(session, TPCH_CATALOG, viewMetadataInvoker1, viewDataInvoker1, false)); |
| 380 | + |
| 381 | + String viewDataInvoker2 = JsonCodec.jsonCodec(ViewDefinition.class).toJson( |
| 382 | + new ViewDefinition( |
| 383 | + "select x, y, z from t13", |
| 384 | + Optional.of(TPCH_CATALOG), |
| 385 | + Optional.of("s1"), |
| 386 | + ImmutableList.of( |
| 387 | + new ViewDefinition.ViewColumn("x", BIGINT), |
| 388 | + new ViewDefinition.ViewColumn("y", BIGINT), |
| 389 | + new ViewDefinition.ViewColumn("z", BIGINT)), |
| 390 | + Optional.empty(), |
| 391 | + true)); |
| 392 | + ConnectorTableMetadata viewMetadataInvoker2 = new ConnectorTableMetadata( |
| 393 | + new SchemaTableName("s1", "view_invoker2"), |
| 394 | + ImmutableList.of( |
| 395 | + ColumnMetadata.builder().setName("x").setType(BIGINT).build(), |
| 396 | + ColumnMetadata.builder().setName("y").setType(BIGINT).build(), |
| 397 | + ColumnMetadata.builder().setName("z").setType(BIGINT).build())); |
| 398 | + inSetupTransaction(session -> metadata.createView(session, TPCH_CATALOG, viewMetadataInvoker2, viewDataInvoker2, false)); |
| 399 | + |
| 400 | + String viewDataDefiner1 = JsonCodec.jsonCodec(ViewDefinition.class).toJson( |
| 401 | + new ViewDefinition( |
| 402 | + "select a,b,c from t1", |
| 403 | + Optional.of(TPCH_CATALOG), |
| 404 | + Optional.of("s1"), |
| 405 | + ImmutableList.of( |
| 406 | + new ViewDefinition.ViewColumn("a", BIGINT), |
| 407 | + new ViewDefinition.ViewColumn("b", BIGINT), |
| 408 | + new ViewDefinition.ViewColumn("c", BIGINT)), |
| 409 | + Optional.of("different_user"), |
| 410 | + false)); |
| 411 | + |
| 412 | + ConnectorTableMetadata viewMetadataDefiner1 = new ConnectorTableMetadata( |
| 413 | + new SchemaTableName("s1", "view_definer1"), |
| 414 | + ImmutableList.of( |
| 415 | + ColumnMetadata.builder().setName("a").setType(BIGINT).build(), |
| 416 | + ColumnMetadata.builder().setName("b").setType(BIGINT).build(), |
| 417 | + ColumnMetadata.builder().setName("c").setType(BIGINT).build())); |
| 418 | + inSetupTransaction(session -> metadata.createView(session, TPCH_CATALOG, viewMetadataDefiner1, viewDataDefiner1, false)); |
| 419 | + |
| 420 | + String viewDataDefiner2 = JsonCodec.jsonCodec(ViewDefinition.class).toJson( |
| 421 | + new ViewDefinition( |
| 422 | + "select x, y, z from t13", |
| 423 | + Optional.of(TPCH_CATALOG), |
| 424 | + Optional.of("s1"), |
| 425 | + ImmutableList.of( |
| 426 | + new ViewDefinition.ViewColumn("x", BIGINT), |
| 427 | + new ViewDefinition.ViewColumn("y", BIGINT), |
| 428 | + new ViewDefinition.ViewColumn("z", BIGINT)), |
| 429 | + Optional.of("different_user"), |
| 430 | + false)); |
| 431 | + ConnectorTableMetadata viewMetadataDefiner2 = new ConnectorTableMetadata( |
| 432 | + new SchemaTableName("s1", "view_definer2"), |
| 433 | + ImmutableList.of( |
| 434 | + ColumnMetadata.builder().setName("x").setType(BIGINT).build(), |
| 435 | + ColumnMetadata.builder().setName("y").setType(BIGINT).build(), |
| 436 | + ColumnMetadata.builder().setName("z").setType(BIGINT).build())); |
| 437 | + inSetupTransaction(session -> metadata.createView(session, TPCH_CATALOG, viewMetadataDefiner2, viewDataDefiner2, false)); |
| 438 | + |
| 439 | + String viewDataInvokerWithCte1 = JsonCodec.jsonCodec(ViewDefinition.class).toJson( |
| 440 | + new ViewDefinition( |
| 441 | + "WITH cte as (SELECT a + 1 as c1, b +1 as c2, c +1 as c3 FROM t1) SELECT c1, c2, c3 from cte where c1 > 5", |
| 442 | + Optional.of(TPCH_CATALOG), |
| 443 | + Optional.of("s1"), |
| 444 | + ImmutableList.of( |
| 445 | + new ViewDefinition.ViewColumn("c1", BIGINT), |
| 446 | + new ViewDefinition.ViewColumn("c2", BIGINT), |
| 447 | + new ViewDefinition.ViewColumn("c3", BIGINT)), |
| 448 | + Optional.empty(), |
| 449 | + true)); |
| 450 | + ConnectorTableMetadata viewMetadataInvokerWithCte1 = new ConnectorTableMetadata( |
| 451 | + new SchemaTableName("s1", "view_invoker_with_cte1"), |
| 452 | + ImmutableList.of( |
| 453 | + ColumnMetadata.builder().setName("c1").setType(BIGINT).build(), |
| 454 | + ColumnMetadata.builder().setName("c2").setType(BIGINT).build(), |
| 455 | + ColumnMetadata.builder().setName("c3").setType(BIGINT).build())); |
| 456 | + inSetupTransaction(session -> metadata.createView(session, TPCH_CATALOG, viewMetadataInvokerWithCte1, viewDataInvokerWithCte1, false)); |
356 | 457 | } |
357 | 458 |
|
358 | 459 | private void inSetupTransaction(Consumer<Session> consumer) |
|
0 commit comments