Skip to content

Commit 4eb4ce2

Browse files
Utilized columns fix for views (#24638)
Update test file to check all utilized references Add test for definer mode Lint Untab Untab 2 Remove line break Lint Lint Add cte to view definition Lint Fix naming of test tables Check access control info in tests Remove wrapper set Check ViewAccessControlEquality Refactor test Lint Fix build Update equals method Add check to catalog Add catalog to hashcode Merge unnest
1 parent d5c285e commit 4eb4ce2

File tree

4 files changed

+297
-128
lines changed

4 files changed

+297
-128
lines changed

presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/UtilizedColumnsAnalyzer.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,15 @@ protected Void visitTable(Table table, Context context)
314314
{
315315
handleRelation(table, context);
316316

317+
Analysis.NamedQuery namedQuery = analysis.getNamedQuery(table);
318+
if (namedQuery != null && namedQuery.isFromView()) {
319+
handleRelation(table, context, namedQuery.getQuery().getQueryBody());
320+
process(namedQuery.getQuery(), context);
321+
}
322+
else {
323+
handleRelation(table, context);
324+
}
325+
317326
return null;
318327
}
319328

presto-main-base/src/test/java/com/facebook/presto/sql/analyzer/AbstractAnalyzerTest.java

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
import java.util.Optional;
6868
import java.util.function.Consumer;
6969

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;
7072
import static com.facebook.presto.common.type.BigintType.BIGINT;
7173
import static com.facebook.presto.common.type.DoubleType.DOUBLE;
7274
import static com.facebook.presto.common.type.TypeSignature.parseTypeSignature;
@@ -106,6 +108,8 @@ public class AbstractAnalyzerTest
106108
protected static final Session CLIENT_SESSION = testSessionBuilder()
107109
.setCatalog(TPCH_CATALOG)
108110
.setSchema("s1")
111+
.setSystemProperty(CHECK_ACCESS_CONTROL_ON_UTILIZED_COLUMNS_ONLY, "true")
112+
.setSystemProperty(CHECK_ACCESS_CONTROL_WITH_SUBFIELDS, "true")
109113
.build();
110114

111115
protected static final SqlInvokedFunction SQL_FUNCTION_SQUARE = new SqlInvokedFunction(
@@ -353,6 +357,103 @@ public void setup()
353357
new SchemaTableName("s1", "v5"),
354358
ImmutableList.of(ColumnMetadata.builder().setName("a").setType(BIGINT).build()));
355359
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));
356457
}
357458

358459
private void inSetupTransaction(Consumer<Session> consumer)

0 commit comments

Comments
 (0)