Skip to content

Commit

Permalink
Show security mode in SHOW CREATE VIEW
Browse files Browse the repository at this point in the history
Update test

Lint

Typo

Fix tests

Rerun CI

Rerun CI 2

Rerun CI 3

Fix spacing

Fix whitespace

Rerun CI 1
  • Loading branch information
kevintang2022 authored and rschlussel committed Jan 2, 2025
1 parent 08cf9bb commit 942cbbc
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,12 @@ public void testView()
assertUpdate(session, "CREATE VIEW view_orders AS SELECT * from orders");
assertQuery(session, "SELECT * FROM view_orders", "SELECT * from orders");
assertThat(computeActual("SHOW CREATE VIEW view_orders").getOnlyValue())
.isEqualTo(format("CREATE VIEW iceberg.\"%s\".view_orders AS\n" +
"SELECT *\n" +
"FROM\n" +
" orders", schemaName));
.isEqualTo(format("CREATE VIEW iceberg.\"%s\".view_orders SECURITY %s AS\n" +
"SELECT *\n" +
"FROM\n" +
" orders",
schemaName,
"DEFINER"));
assertUpdate(session, "DROP VIEW view_orders");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@ protected Node visitShowCreate(ShowCreate node, Void context)
}

Query query = parseView(viewDefinition.get().getOriginalSql(), objectName, node);
String sql = formatSql(new CreateView(createQualifiedName(objectName), query, false, Optional.empty()), Optional.of(parameters)).trim();
CreateView.Security security = (viewDefinition.get().isRunAsInvoker()) ? CreateView.Security.INVOKER : CreateView.Security.DEFINER;
String sql = formatSql(new CreateView(createQualifiedName(objectName), query, false, Optional.of(security)), Optional.of(parameters)).trim();
return singleValueQuery("Create View", sql);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,7 @@ protected Void visitCreateView(CreateView node, Integer indent)

node.getSecurity().ifPresent(security ->
builder.append(" SECURITY ")
.append(security.toString())
.append(" "));
.append(security.toString()));

builder.append(" AS\n");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ public void testCreateAlterTable()
public void testCreateDropView()
{
// create table with default format orc
String createViewSql = "CREATE VIEW hive.hive_test.hive_view AS\n" +
String createViewSql = "CREATE VIEW hive.hive_test.hive_view SECURITY DEFINER AS\n" +
"SELECT *\n" +
"FROM\n" +
" orders";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,10 +968,11 @@ public void testViewMetadata()

// test SHOW CREATE VIEW
String expectedSql = formatSqlText(format(
"CREATE VIEW %s.%s.%s AS %s",
"CREATE VIEW %s.%s.%s SECURITY %s AS %s",
getSession().getCatalog().get(),
getSession().getSchema().get(),
"meta_test_view",
"DEFINER",
query)).trim();

actual = computeActual("SHOW CREATE VIEW meta_test_view");
Expand Down

0 comments on commit 942cbbc

Please sign in to comment.