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

Remove supportsReportingWrittenBytes from SPI #18617

Merged
merged 1 commit into from
Aug 10, 2023
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
10 changes: 0 additions & 10 deletions core/trino-main/src/main/java/io/trino/metadata/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -741,16 +741,6 @@ default boolean isMaterializedView(Session session, QualifiedObjectName viewName
*/
RedirectionAwareTableHandle getRedirectionAwareTableHandle(Session session, QualifiedObjectName tableName, Optional<TableVersion> startVersion, Optional<TableVersion> endVersion);

/**
* Returns true if the connector reports number of written bytes for an existing table. Otherwise, it returns false.
*/
boolean supportsReportingWrittenBytes(Session session, TableHandle tableHandle);

/**
* Returns true if the connector reports number of written bytes for a new table. Otherwise, it returns false.
*/
boolean supportsReportingWrittenBytes(Session session, QualifiedObjectName tableName, Map<String, Object> tableProperties);

/**
* Returns a table handle for the specified table name with a specified version
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2603,27 +2603,6 @@ private synchronized void finish()
}
}

@Override
public boolean supportsReportingWrittenBytes(Session session, QualifiedObjectName tableName, Map<String, Object> tableProperties)
{
Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, tableName.getCatalogName());
if (catalog.isEmpty()) {
return false;
}

CatalogMetadata catalogMetadata = catalog.get();
CatalogHandle catalogHandle = catalogMetadata.getCatalogHandle(session, tableName);
ConnectorMetadata metadata = catalogMetadata.getMetadataFor(session, catalogHandle);
return metadata.supportsReportingWrittenBytes(session.toConnectorSession(catalogHandle), tableName.asSchemaTableName(), tableProperties);
}

@Override
public boolean supportsReportingWrittenBytes(Session session, TableHandle tableHandle)
{
ConnectorMetadata metadata = getMetadata(session, tableHandle.getCatalogHandle());
return metadata.supportsReportingWrittenBytes(session.toConnectorSession(tableHandle.getCatalogHandle()), tableHandle.getConnectorHandle());
}

@Override
public OptionalInt getMaxWriterTasks(Session session, String catalogName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1226,24 +1226,6 @@ public Optional<CatalogSchemaTableName> redirectTable(ConnectorSession session,
}
}

@Override
public boolean supportsReportingWrittenBytes(ConnectorSession session, SchemaTableName schemaTableName, Map<String, Object> tableProperties)
{
Span span = startSpan("supportsReportingWrittenBytes", schemaTableName);
try (var ignored = scopedSpan(span)) {
return delegate.supportsReportingWrittenBytes(session, schemaTableName, tableProperties);
}
}

@Override
public boolean supportsReportingWrittenBytes(ConnectorSession session, ConnectorTableHandle connectorTableHandle)
{
Span span = startSpan("supportsReportingWrittenBytes", connectorTableHandle);
try (var ignored = scopedSpan(span)) {
return delegate.supportsReportingWrittenBytes(session, connectorTableHandle);
}
}

@Override
public OptionalInt getMaxWriterTasks(ConnectorSession session)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1340,24 +1340,6 @@ public RedirectionAwareTableHandle getRedirectionAwareTableHandle(Session sessio
}
}

@Override
public boolean supportsReportingWrittenBytes(Session session, TableHandle tableHandle)
{
Span span = startSpan("supportsReportingWrittenBytes", tableHandle);
try (var ignored = scopedSpan(span)) {
return delegate.supportsReportingWrittenBytes(session, tableHandle);
}
}

@Override
public boolean supportsReportingWrittenBytes(Session session, QualifiedObjectName tableName, Map<String, Object> tableProperties)
{
Span span = startSpan("supportsReportingWrittenBytes", tableName);
try (var ignored = scopedSpan(span)) {
return delegate.supportsReportingWrittenBytes(session, tableName, tableProperties);
}
}

@Override
public Optional<TableHandle> getTableHandle(Session session, QualifiedObjectName tableName, Optional<TableVersion> startVersion, Optional<TableVersion> endVersion)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -923,18 +923,6 @@ public RedirectionAwareTableHandle getRedirectionAwareTableHandle(Session sessio
throw new UnsupportedOperationException();
}

@Override
public boolean supportsReportingWrittenBytes(Session session, TableHandle tableHandle)
{
throw new UnsupportedOperationException();
}

@Override
public boolean supportsReportingWrittenBytes(Session session, QualifiedObjectName tableName, Map<String, Object> tableProperties)
{
throw new UnsupportedOperationException();
}

@Override
public Optional<TableHandle> getTableHandle(Session session, QualifiedObjectName table, Optional<TableVersion> startVersion, Optional<TableVersion> endVersion)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1555,20 +1555,6 @@ default Optional<CatalogSchemaTableName> redirectTable(ConnectorSession session,
return Optional.empty();
}

// TODO - Remove this method since now it is only used in test BaseConnectorTest#testWrittenDataSize()
@Deprecated
default boolean supportsReportingWrittenBytes(ConnectorSession session, SchemaTableName schemaTableName, Map<String, Object> tableProperties)
{
return false;
}

// TODO - Remove this method since now it is only used in test BaseConnectorTest#testWrittenDataSize()
@Deprecated
default boolean supportsReportingWrittenBytes(ConnectorSession session, ConnectorTableHandle connectorTableHandle)
{
return false;
}

default OptionalInt getMaxWriterTasks(ConnectorSession session)
{
return OptionalInt.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1117,22 +1117,6 @@ public RowChangeParadigm getRowChangeParadigm(ConnectorSession session, Connecto
}
}

@Override
public boolean supportsReportingWrittenBytes(ConnectorSession session, SchemaTableName schemaTableName, Map<String, Object> tableProperties)
{
try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
return delegate.supportsReportingWrittenBytes(session, schemaTableName, tableProperties);
}
}

@Override
public boolean supportsReportingWrittenBytes(ConnectorSession session, ConnectorTableHandle connectorTableHandle)
{
try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
return delegate.supportsReportingWrittenBytes(session, connectorTableHandle);
}
}

@Override
public OptionalInt getMaxWriterTasks(ConnectorSession session)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3054,18 +3054,6 @@ private static String toPhysicalColumnName(String columnName, Map</* lowercase*/
return originalColumnName;
}

@Override
public boolean supportsReportingWrittenBytes(ConnectorSession session, ConnectorTableHandle connectorTableHandle)
{
return true;
}

@Override
public boolean supportsReportingWrittenBytes(ConnectorSession session, SchemaTableName fullTableName, Map<String, Object> tableProperties)
{
return true;
}

private void cleanExtraOutputFiles(ConnectorSession session, Location baseLocation, List<DataFileInfo> validDataFiles)
{
Set<Location> writtenFilePaths = validDataFiles.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_CREATE_MATERIALIZED_VIEW:
return false;

case SUPPORTS_REPORTING_WRITTEN_BYTES:
return true;

default:
return super.hasBehavior(connectorBehavior);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3902,16 +3902,4 @@ private static boolean isQueryPartitionFilterRequiredForTable(ConnectorSession s
return isQueryPartitionFilterRequired(session) &&
requiredSchemas.isEmpty() || requiredSchemas.contains(schemaTableName.getSchemaName());
}

@Override
public boolean supportsReportingWrittenBytes(ConnectorSession session, ConnectorTableHandle connectorTableHandle)
{
return true;
}

@Override
public boolean supportsReportingWrittenBytes(ConnectorSession session, SchemaTableName schemaTableName, Map<String, Object> tableProperties)
{
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)

case SUPPORTS_MULTI_STATEMENT_WRITES:
return true;
case SUPPORTS_REPORTING_WRITTEN_BYTES:
return true;

default:
return super.hasBehavior(connectorBehavior);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2878,18 +2878,6 @@ private TableChangeInfo getTableChangeInfo(ConnectorSession session, IcebergTabl
.orElse(new UnknownTableChange());
}

@Override
public boolean supportsReportingWrittenBytes(ConnectorSession session, ConnectorTableHandle connectorTableHandle)
{
return true;
}

@Override
public boolean supportsReportingWrittenBytes(ConnectorSession session, SchemaTableName fullTableName, Map<String, Object> tableProperties)
{
return true;
}

@Override
public void setColumnComment(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle column, Optional<String> comment)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
case SUPPORTS_ADD_COLUMN_NOT_NULL_CONSTRAINT:
return false;

case SUPPORTS_REPORTING_WRITTEN_BYTES:
return true;

default:
return super.hasBehavior(connectorBehavior);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
import io.trino.metadata.FunctionManager;
import io.trino.metadata.Metadata;
import io.trino.metadata.QualifiedObjectName;
import io.trino.security.AllowAllAccessControl;
import io.trino.server.BasicQueryInfo;
import io.trino.server.testing.TestingTrinoServer;
import io.trino.spi.connector.ConnectorSession;
import io.trino.spi.connector.MaterializedViewFreshness;
import io.trino.spi.security.Identity;
Expand Down Expand Up @@ -145,6 +143,7 @@
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_RENAME_SCHEMA;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_RENAME_TABLE;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_RENAME_TABLE_ACROSS_SCHEMAS;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_REPORTING_WRITTEN_BYTES;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_ROW_LEVEL_DELETE;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_ROW_TYPE;
import static io.trino.testing.TestingConnectorBehavior.SUPPORTS_SET_COLUMN_TYPE;
Expand All @@ -155,7 +154,6 @@
import static io.trino.testing.TestingNames.randomNameSuffix;
import static io.trino.testing.assertions.Assert.assertEventually;
import static io.trino.testing.assertions.TestUtil.verifyResultOrFailure;
import static io.trino.transaction.TransactionBuilder.transaction;
import static java.lang.String.format;
import static java.lang.String.join;
import static java.lang.Thread.currentThread;
Expand Down Expand Up @@ -5086,41 +5084,14 @@ public void testWrittenStats()
@Test
public void testWrittenDataSize()
{
skipTestUnless(hasBehavior(SUPPORTS_CREATE_TABLE_WITH_DATA));

AtomicBoolean isReportingWrittenBytesSupported = new AtomicBoolean();
transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl())
.singleStatement()
.execute(getSession(), session -> {
String catalogName = session.getCatalog().orElseThrow();
TestingTrinoServer coordinator = getDistributedQueryRunner().getCoordinator();
Map<String, Object> properties = coordinator.getTablePropertyManager().getProperties(
catalogName,
coordinator.getMetadata().getCatalogHandle(session, catalogName).orElseThrow(),
List.of(),
session,
null,
new AllowAllAccessControl(),
Map.of(),
true);
QualifiedObjectName fullTableName = new QualifiedObjectName(catalogName, "any", "any");
isReportingWrittenBytesSupported.set(coordinator.getMetadata().supportsReportingWrittenBytes(session, fullTableName, properties));
});

skipTestUnless(hasBehavior(SUPPORTS_REPORTING_WRITTEN_BYTES));
String tableName = "write_stats_" + randomNameSuffix();
try {
String query = "CREATE TABLE " + tableName + " AS SELECT * FROM tpch.tiny.nation";
assertQueryStats(
getSession(),
query,
queryStats -> {
if (isReportingWrittenBytesSupported.get()) {
assertThat(queryStats.getPhysicalWrittenDataSize().toBytes()).isPositive();
}
else {
assertThat(queryStats.getPhysicalWrittenDataSize().toBytes()).isZero();
}
},
queryStats -> assertThat(queryStats.getPhysicalWrittenDataSize().toBytes()).isPositive(),
results -> {});
}
finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public enum TestingConnectorBehavior

SUPPORTS_NATIVE_QUERY(true), // system.query or equivalent PTF for query passthrough

SUPPORTS_REPORTING_WRITTEN_BYTES(false),

/**/;

private final Predicate<Predicate<TestingConnectorBehavior>> hasBehaviorByDefault;
Expand All @@ -134,6 +136,7 @@ public enum TestingConnectorBehavior
(name().equals("SUPPORTS_CANCELLATION") ||
name().equals("SUPPORTS_DYNAMIC_FILTER_PUSHDOWN") ||
name().equals("SUPPORTS_JOIN_PUSHDOWN") ||
name().equals("SUPPORTS_REPORTING_WRITTEN_BYTES") ||
name().equals("SUPPORTS_MULTI_STATEMENT_WRITES")),
"Every behavior should be expected to be true by default. Having mixed defaults makes reasoning about tests harder. False default provided for %s",
name());
Expand Down