Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show security mode in SHOW CREATE VIEW #24297

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading