Skip to content
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 @@ -145,6 +145,7 @@ public class HiveConfig

private boolean translateHiveViews;
private boolean legacyHiveViewTranslation;
private boolean hiveViewsRunAsInvoker;

private Optional<Duration> hiveTransactionHeartbeatInterval = Optional.empty();
private int hiveTransactionHeartbeatThreads = 5;
Expand Down Expand Up @@ -792,6 +793,19 @@ public HiveConfig setLegacyHiveViewTranslation(boolean legacyHiveViewTranslation
return this;
}

public boolean isHiveViewsRunAsInvoker()
{
return hiveViewsRunAsInvoker;
}

@Config("hive.hive-views.run-as-invoker")
@ConfigDescription("Execute Hive views with permissions of invoker")
public HiveConfig setHiveViewsRunAsInvoker(boolean hiveViewsRunAsInvoker)
{
this.hiveViewsRunAsInvoker = hiveViewsRunAsInvoker;
return this;
}

public long getFileStatusCacheMaxSize()
{
return fileStatusCacheMaxSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ public class HiveMetadata
private final boolean writesToNonManagedTablesEnabled;
private final boolean createsOfNonManagedTablesEnabled;
private final boolean translateHiveViews;
private final boolean hiveViewsRunAsInvoker;
private final boolean hideDeltaLakeTables;
private final String prestoVersion;
private final HiveStatisticsProvider hiveStatisticsProvider;
Expand All @@ -376,6 +377,7 @@ public HiveMetadata(
boolean writesToNonManagedTablesEnabled,
boolean createsOfNonManagedTablesEnabled,
boolean translateHiveViews,
boolean hiveViewsRunAsInvoker,
boolean hideDeltaLakeTables,
TypeManager typeManager,
MetadataProvider metadataProvider,
Expand All @@ -402,6 +404,7 @@ public HiveMetadata(
this.writesToNonManagedTablesEnabled = writesToNonManagedTablesEnabled;
this.createsOfNonManagedTablesEnabled = createsOfNonManagedTablesEnabled;
this.translateHiveViews = translateHiveViews;
this.hiveViewsRunAsInvoker = hiveViewsRunAsInvoker;
this.hideDeltaLakeTables = hideDeltaLakeTables;
this.prestoVersion = requireNonNull(trinoVersion, "trinoVersion is null");
this.hiveStatisticsProvider = requireNonNull(hiveStatisticsProvider, "hiveStatisticsProvider is null");
Expand Down Expand Up @@ -2437,7 +2440,7 @@ public Optional<ConnectorViewDefinition> getView(ConnectorSession session, Schem
throw new HiveViewNotSupportedException(viewName);
}

ConnectorViewDefinition definition = createViewReader(metastore, session, view, typeManager, this::redirectTable, metadataProvider)
ConnectorViewDefinition definition = createViewReader(metastore, session, view, typeManager, this::redirectTable, metadataProvider, hiveViewsRunAsInvoker)
.decodeViewData(view.getViewOriginalText().get(), view, catalogName);
// use owner from table metadata if it exists
if (view.getOwner().isPresent() && !definition.isRunAsInvoker()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class HiveMetadataFactory
private final boolean createsOfNonManagedTablesEnabled;
private final boolean deleteSchemaLocationsFallback;
private final boolean translateHiveViews;
private final boolean hiveViewsRunAsInvoker;
private final boolean hideDeltaLakeTables;
private final long perTransactionCacheMaximumSize;
private final HiveMetastoreFactory metastoreFactory;
Expand Down Expand Up @@ -109,6 +110,7 @@ public HiveMetadataFactory(
hiveConfig.getCreatesOfNonManagedTablesEnabled(),
hiveConfig.isDeleteSchemaLocationsFallback(),
hiveConfig.isTranslateHiveViews(),
hiveConfig.isHiveViewsRunAsInvoker(),
hiveConfig.getPerTransactionMetastoreCacheMaximumSize(),
hiveConfig.getHiveTransactionHeartbeatInterval(),
metastoreConfig.isHideDeltaLakeTables(),
Expand Down Expand Up @@ -142,6 +144,7 @@ public HiveMetadataFactory(
boolean createsOfNonManagedTablesEnabled,
boolean deleteSchemaLocationsFallback,
boolean translateHiveViews,
boolean hiveViewsRunAsInvoker,
long perTransactionCacheMaximumSize,
Optional<Duration> hiveTransactionHeartbeatInterval,
boolean hideDeltaLakeTables,
Expand All @@ -167,6 +170,7 @@ public HiveMetadataFactory(
this.createsOfNonManagedTablesEnabled = createsOfNonManagedTablesEnabled;
this.deleteSchemaLocationsFallback = deleteSchemaLocationsFallback;
this.translateHiveViews = translateHiveViews;
this.hiveViewsRunAsInvoker = hiveViewsRunAsInvoker;
this.hideDeltaLakeTables = hideDeltaLakeTables;
this.perTransactionCacheMaximumSize = perTransactionCacheMaximumSize;

Expand Down Expand Up @@ -229,6 +233,7 @@ public TransactionalMetadata create(ConnectorIdentity identity, boolean autoComm
writesToNonManagedTablesEnabled,
createsOfNonManagedTablesEnabled,
translateHiveViews,
hiveViewsRunAsInvoker,
hideDeltaLakeTables,
typeManager,
metadataProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
public class LegacyHiveViewReader
implements ViewReaderUtil.ViewReader
{
private final boolean hiveViewsRunAsInvoker;

public LegacyHiveViewReader(boolean hiveViewsRunAsInvoker)
{
this.hiveViewsRunAsInvoker = hiveViewsRunAsInvoker;
}

@Override
public ConnectorViewDefinition decodeViewData(String viewData, Table table, CatalogName catalogName)
{
Expand All @@ -43,6 +50,6 @@ public ConnectorViewDefinition decodeViewData(String viewData, Table table, Cata
.collect(toImmutableList()),
Optional.ofNullable(table.getParameters().get(TABLE_COMMENT)),
table.getOwner(),
false); // don't run as invoker
hiveViewsRunAsInvoker);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,20 @@ public static ViewReader createViewReader(
Table table,
TypeManager typeManager,
BiFunction<ConnectorSession, SchemaTableName, Optional<CatalogSchemaTableName>> tableRedirectionResolver,
MetadataProvider metadataProvider)
MetadataProvider metadataProvider,
boolean runHiveViewRunAsInvoker)
{
if (isPrestoView(table)) {
return new PrestoViewReader();
}
if (isHiveViewsLegacyTranslation(session)) {
return new LegacyHiveViewReader();
return new LegacyHiveViewReader(runHiveViewRunAsInvoker);
}

return new HiveViewReader(
new CoralSemiTransactionalHiveMSCAdapter(metastore, coralTableRedirectionResolver(session, tableRedirectionResolver, metadataProvider)),
typeManager);
typeManager,
runHiveViewRunAsInvoker);
}

private static CoralTableRedirectionResolver coralTableRedirectionResolver(
Expand Down Expand Up @@ -195,11 +197,13 @@ public static class HiveViewReader
{
private final HiveMetastoreClient metastoreClient;
private final TypeManager typeManager;
private final boolean hiveViewsRunAsInvoker;

public HiveViewReader(HiveMetastoreClient hiveMetastoreClient, TypeManager typeManager)
public HiveViewReader(HiveMetastoreClient hiveMetastoreClient, TypeManager typeManager, boolean hiveViewsRunAsInvoker)
{
this.metastoreClient = requireNonNull(hiveMetastoreClient, "hiveMetastoreClient is null");
this.typeManager = requireNonNull(typeManager, "typeManager is null");
this.hiveViewsRunAsInvoker = hiveViewsRunAsInvoker;
}

@Override
Expand All @@ -223,7 +227,7 @@ public ConnectorViewDefinition decodeViewData(String viewSql, Table table, Catal
columns,
Optional.ofNullable(table.getParameters().get(TABLE_COMMENT)),
Optional.empty(),
false);
hiveViewsRunAsInvoker);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work, if owner is always Optional.empty() (line above)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does work; although the ConnectorViewDefinition returns without an owner, that information is then added again in HiveMetadata#getView.

}
catch (RuntimeException e) {
throw new TrinoException(HIVE_VIEW_TRANSLATION_ERROR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@ protected final void setup(String databaseName, HiveConfig hiveConfig, HiveMetas
true,
true,
false,
false,
1000,
Optional.empty(),
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public void testDefaults()
.setPerTransactionFileStatusCacheMaximumSize(1000 * 1000)
.setTranslateHiveViews(false)
.setLegacyHiveViewTranslation(false)
.setHiveViewsRunAsInvoker(false)
.setHiveTransactionHeartbeatInterval(null)
.setHiveTransactionHeartbeatThreads(5)
.setAllowRegisterPartition(false)
Expand Down Expand Up @@ -182,6 +183,7 @@ public void testExplicitPropertyMappings()
.put("hive.per-transaction-file-status-cache-maximum-size", "42")
.put("hive.hive-views.enabled", "true")
.put("hive.hive-views.legacy-translation", "true")
.put("hive.hive-views.run-as-invoker", "true")
.put("hive.transaction-heartbeat-interval", "10s")
.put("hive.transaction-heartbeat-threads", "10")
.put("hive.allow-register-partition-procedure", "true")
Expand Down Expand Up @@ -262,6 +264,7 @@ public void testExplicitPropertyMappings()
.setPerTransactionFileStatusCacheMaximumSize(42)
.setTranslateHiveViews(true)
.setLegacyHiveViewTranslation(true)
.setHiveViewsRunAsInvoker(true)
.setHiveTransactionHeartbeatInterval(new Duration(10, TimeUnit.SECONDS))
.setHiveTransactionHeartbeatThreads(10)
.setAllowRegisterPartition(true)
Expand Down