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 @@ -26,16 +26,22 @@
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.SecurityContext;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.service.catalog.CatalogPrefixParser;
import org.apache.polaris.service.catalog.api.PolarisCatalogGenericTableApiService;
import org.apache.polaris.service.catalog.common.CatalogAdapter;
import org.apache.polaris.service.events.CatalogGenericTableServiceEvents;
import org.apache.polaris.service.events.listeners.PolarisEventListener;
import org.apache.polaris.service.types.CreateGenericTableRequest;
import org.apache.polaris.service.types.LoadGenericTableResponse;

@Decorator
@Priority(1000)
public class CatalogGenericTableEventServiceDelegator
implements PolarisCatalogGenericTableApiService, CatalogAdapter {

@Inject @Delegate GenericTableCatalogAdapter delegate;
@Inject PolarisEventListener polarisEventListener;
@Inject CatalogPrefixParser prefixParser;

@Override
public Response createGenericTable(
Expand All @@ -44,8 +50,17 @@ public Response createGenericTable(
CreateGenericTableRequest createGenericTableRequest,
RealmContext realmContext,
SecurityContext securityContext) {
return delegate.createGenericTable(
prefix, namespace, createGenericTableRequest, realmContext, securityContext);
String catalogName = prefixParser.prefixToCatalogName(realmContext, prefix);
polarisEventListener.onBeforeCreateGenericTable(
new CatalogGenericTableServiceEvents.BeforeCreateGenericTableEvent(
catalogName, namespace, createGenericTableRequest));
Response resp =
delegate.createGenericTable(
prefix, namespace, createGenericTableRequest, realmContext, securityContext);
polarisEventListener.onAfterCreateGenericTable(
new CatalogGenericTableServiceEvents.AfterCreateGenericTableEvent(
catalogName, namespace, ((LoadGenericTableResponse) resp.getEntity()).getTable()));
return resp;
}

@Override
Expand All @@ -55,8 +70,16 @@ public Response dropGenericTable(
String genericTable,
RealmContext realmContext,
SecurityContext securityContext) {
return delegate.dropGenericTable(
prefix, namespace, genericTable, realmContext, securityContext);
String catalogName = prefixParser.prefixToCatalogName(realmContext, prefix);
polarisEventListener.onBeforeDropGenericTable(
new CatalogGenericTableServiceEvents.BeforeDropGenericTableEvent(
catalogName, namespace, genericTable));
Response resp =
delegate.dropGenericTable(prefix, namespace, genericTable, realmContext, securityContext);
polarisEventListener.onAfterDropGenericTable(
new CatalogGenericTableServiceEvents.AfterDropGenericTableEvent(
catalogName, namespace, genericTable));
return resp;
}

@Override
Expand All @@ -67,8 +90,15 @@ public Response listGenericTables(
Integer pageSize,
RealmContext realmContext,
SecurityContext securityContext) {
return delegate.listGenericTables(
prefix, namespace, pageToken, pageSize, realmContext, securityContext);
String catalogName = prefixParser.prefixToCatalogName(realmContext, prefix);
polarisEventListener.onBeforeListGenericTables(
new CatalogGenericTableServiceEvents.BeforeListGenericTablesEvent(catalogName, namespace));
Response resp =
delegate.listGenericTables(
prefix, namespace, pageToken, pageSize, realmContext, securityContext);
polarisEventListener.onAfterListGenericTables(
new CatalogGenericTableServiceEvents.AfterListGenericTablesEvent(catalogName, namespace));
return resp;
}

@Override
Expand All @@ -78,7 +108,15 @@ public Response loadGenericTable(
String genericTable,
RealmContext realmContext,
SecurityContext securityContext) {
return delegate.loadGenericTable(
prefix, namespace, genericTable, realmContext, securityContext);
String catalogName = prefixParser.prefixToCatalogName(realmContext, prefix);
polarisEventListener.onBeforeLoadGenericTable(
new CatalogGenericTableServiceEvents.BeforeLoadGenericTableEvent(
catalogName, namespace, genericTable));
Response resp =
delegate.loadGenericTable(prefix, namespace, genericTable, realmContext, securityContext);
polarisEventListener.onAfterLoadGenericTable(
new CatalogGenericTableServiceEvents.AfterLoadGenericTableEvent(
catalogName, namespace, ((LoadGenericTableResponse) resp.getEntity()).getTable()));
return resp;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.polaris.service.events;

import org.apache.polaris.service.types.CreateGenericTableRequest;
import org.apache.polaris.service.types.GenericTable;

public class CatalogGenericTableServiceEvents {
public record BeforeCreateGenericTableEvent(
String catalogName, String namespace, CreateGenericTableRequest request) {}

public record AfterCreateGenericTableEvent(
String catalogName, String namespace, GenericTable table) {}

public record BeforeDropGenericTableEvent(
String catalogName, String namespace, String tableName) {}

public record AfterDropGenericTableEvent(
String catalogName, String namespace, String tableName) {}

public record BeforeListGenericTablesEvent(String catalogName, String namespace) {}

public record AfterListGenericTablesEvent(String catalogName, String namespace) {}

public record BeforeLoadGenericTableEvent(
String catalogName, String namespace, String tableName) {}

public record AfterLoadGenericTableEvent(
String catalogName, String namespace, GenericTable table) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.polaris.service.events.BeforeTaskAttemptedEvent;
import org.apache.polaris.service.events.BeforeViewCommitedEvent;
import org.apache.polaris.service.events.BeforeViewRefreshedEvent;
import org.apache.polaris.service.events.CatalogGenericTableServiceEvents;

/**
* Represents an event listener that can respond to notable moments during Polaris's execution.
Expand Down Expand Up @@ -76,4 +77,36 @@ public void onAfterTableCreated(AfterTableCreatedEvent event) {}

/** {@link AfterCatalogCreatedEvent} */
public void onAfterCatalogCreated(AfterCatalogCreatedEvent event) {}

/** {@link CatalogGenericTableServiceEvents.BeforeCreateGenericTableEvent} */
public void onBeforeCreateGenericTable(
CatalogGenericTableServiceEvents.BeforeCreateGenericTableEvent event) {}

/** {@link CatalogGenericTableServiceEvents.AfterCreateGenericTableEvent} */
public void onAfterCreateGenericTable(
CatalogGenericTableServiceEvents.AfterCreateGenericTableEvent event) {}

/** {@link CatalogGenericTableServiceEvents.BeforeDropGenericTableEvent} */
public void onBeforeDropGenericTable(
CatalogGenericTableServiceEvents.BeforeDropGenericTableEvent event) {}

/** {@link CatalogGenericTableServiceEvents.AfterDropGenericTableEvent} */
public void onAfterDropGenericTable(
CatalogGenericTableServiceEvents.AfterDropGenericTableEvent event) {}

/** {@link CatalogGenericTableServiceEvents.BeforeListGenericTablesEvent} */
public void onBeforeListGenericTables(
CatalogGenericTableServiceEvents.BeforeListGenericTablesEvent event) {}

/** {@link CatalogGenericTableServiceEvents.AfterListGenericTablesEvent} */
public void onAfterListGenericTables(
CatalogGenericTableServiceEvents.AfterListGenericTablesEvent event) {}

/** {@link CatalogGenericTableServiceEvents.BeforeLoadGenericTableEvent} */
public void onBeforeLoadGenericTable(
CatalogGenericTableServiceEvents.BeforeLoadGenericTableEvent event) {}

/** {@link CatalogGenericTableServiceEvents.AfterLoadGenericTableEvent} */
public void onAfterLoadGenericTable(
CatalogGenericTableServiceEvents.AfterLoadGenericTableEvent event) {}
}