Skip to content

Commit

Permalink
Add column add/drop/rename events
Browse files Browse the repository at this point in the history
Add methods in SystemSecurityMetadata to provide
notification of adding, dropping and renaming columns.
  • Loading branch information
djsstarburst authored and electrum committed Jan 23, 2023
1 parent 2e1c125 commit 33fdaa0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ public void tableRenamed(Session session, CatalogSchemaTableName sourceTable, Ca
@Override
public void tableDropped(Session session, CatalogSchemaTableName table) {}

@Override
public void columnCreated(Session session, CatalogSchemaTableName table, String column) {}

@Override
public void columnRenamed(Session session, CatalogSchemaTableName table, String oldColumn, String newColumn) {}

@Override
public void columnDropped(Session session, CatalogSchemaTableName table, String column) {}

private static TrinoException notSupportedException(String catalogName)
{
return new TrinoException(NOT_SUPPORTED, "Catalog does not support permission management: " + catalogName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,14 @@ public void renameColumn(Session session, TableHandle tableHandle, ColumnHandle
CatalogHandle catalogHandle = tableHandle.getCatalogHandle();
ConnectorMetadata metadata = getMetadataForWrite(session, catalogHandle);
metadata.renameColumn(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), source, target.toLowerCase(ENGLISH));

CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogHandle);
ColumnMetadata sourceColumnMetadata = getColumnMetadata(session, tableHandle, source);
if (catalogMetadata.getSecurityManagement() != CONNECTOR) {
TableMetadata tableMetadata = getTableMetadata(session, tableHandle);
CatalogSchemaTableName sourceTableName = new CatalogSchemaTableName(catalogHandle.getCatalogName(), tableMetadata.getTable());
systemSecurityMetadata.columnRenamed(session, sourceTableName, sourceColumnMetadata.getName(), target);
}
}

@Override
Expand All @@ -734,14 +742,28 @@ public void addColumn(Session session, TableHandle tableHandle, ColumnMetadata c
CatalogHandle catalogHandle = tableHandle.getCatalogHandle();
ConnectorMetadata metadata = getMetadataForWrite(session, catalogHandle);
metadata.addColumn(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), column);

CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogHandle);
if (catalogMetadata.getSecurityManagement() != CONNECTOR) {
TableMetadata tableMetadata = getTableMetadata(session, tableHandle);
CatalogSchemaTableName sourceTableName = new CatalogSchemaTableName(catalogHandle.getCatalogName(), tableMetadata.getTable());
systemSecurityMetadata.columnCreated(session, sourceTableName, column.getName());
}
}

@Override
public void dropColumn(Session session, TableHandle tableHandle, ColumnHandle column)
{
CatalogHandle catalogHandle = tableHandle.getCatalogHandle();
ConnectorMetadata metadata = getMetadataForWrite(session, catalogHandle);
CatalogMetadata catalogMetadata = getCatalogMetadataForWrite(session, catalogHandle);
metadata.dropColumn(session.toConnectorSession(catalogHandle), tableHandle.getConnectorHandle(), column);
if (catalogMetadata.getSecurityManagement() != CONNECTOR) {
String columnName = getColumnMetadata(session, tableHandle, column).getName();
TableMetadata tableMetadata = getTableMetadata(session, tableHandle);
CatalogSchemaTableName sourceTableName = new CatalogSchemaTableName(catalogHandle.getCatalogName(), tableMetadata.getTable());
systemSecurityMetadata.columnDropped(session, sourceTableName, columnName);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,19 @@ public interface SystemSecurityMetadata
* A table or view was dropped
*/
void tableDropped(Session session, CatalogSchemaTableName table);

/**
* A column was created
*/
void columnCreated(Session session, CatalogSchemaTableName table, String column);

/**
* A column was renamed
*/
void columnRenamed(Session session, CatalogSchemaTableName table, String oldColumn, String newColumn);

/**
* A column was dropped
*/
void columnDropped(Session session, CatalogSchemaTableName table, String column);
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,13 @@ public void tableRenamed(Session session, CatalogSchemaTableName sourceTable, Ca

@Override
public void tableDropped(Session session, CatalogSchemaTableName table) {}

@Override
public void columnCreated(Session session, CatalogSchemaTableName table, String column) {}

@Override
public void columnRenamed(Session session, CatalogSchemaTableName table, String oldColumn, String newColumn) {}

@Override
public void columnDropped(Session session, CatalogSchemaTableName table, String column) {}
}

0 comments on commit 33fdaa0

Please sign in to comment.