Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed 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 io.trino.spi.connector;
import io.airlift.slice.Slice;
import io.trino.spi.TrinoException;
import io.trino.spi.expression.ConnectorExpression;
import io.trino.spi.expression.Constant;
import io.trino.spi.expression.Variable;
import io.trino.spi.predicate.TupleDomain;
import io.trino.spi.security.GrantInfo;
import io.trino.spi.security.Privilege;
import io.trino.spi.security.RoleGrant;
import io.trino.spi.security.TrinoPrincipal;
import io.trino.spi.statistics.ComputedStatistics;
import io.trino.spi.statistics.TableStatistics;
import io.trino.spi.statistics.TableStatisticsMetadata;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalLong;
import java.util.Set;
import java.util.stream.Collectors;
import static io.trino.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR;
import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED;
import static java.lang.String.format;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static java.util.stream.Collectors.toList;
public interface ConnectorMetadata
{
/**
* Checks if a schema exists. The connector may have schemas that exist
* but are not enumerable via {@link #listSchemaNames}.
*/
default boolean schemaExists(ConnectorSession session, String schemaName)
{
return listSchemaNames(session).contains(schemaName);
}
/**
* Returns the schemas provided by this connector.
*/
default List listSchemaNames(ConnectorSession session)
{
return emptyList();
}
/**
* Returns a table handle for the specified table name, or null if the connector does not contain the table.
*/
@Nullable
default ConnectorTableHandle getTableHandle(ConnectorSession session, SchemaTableName tableName)
{
return null;
}
/**
* Returns a table handle for the specified table name, or null if the connector does not contain the table.
* The returned table handle can contain information in analyzeProperties.
*/
@Nullable
default ConnectorTableHandle getTableHandleForStatisticsCollection(ConnectorSession session, SchemaTableName tableName, Map analyzeProperties)
{
throw new TrinoException(NOT_SUPPORTED, "This connector does not support analyze");
}
/**
* Returns the system table for the specified table name, if one exists.
* The system tables handled via {@link #getSystemTable} differ form those returned by {@link Connector#getSystemTables()}.
* The former mechanism allows dynamic resolution of system tables, while the latter is
* based on static list of system tables built during startup.
*/
default Optional getSystemTable(ConnectorSession session, SchemaTableName tableName)
{
return Optional.empty();
}
/**
* Return a list of table layouts that satisfy the given constraint.
*
* For each layout, connectors must return an "unenforced constraint" representing the part of the constraint summary that isn't guaranteed by the layout.
*/
@Deprecated
default List getTableLayouts(
ConnectorSession session,
ConnectorTableHandle table,
Constraint constraint,
Optional> desiredColumns)
{
if (usesLegacyTableLayouts()) {
throw new IllegalStateException("Connector uses legacy Table Layout but doesn't implement getTableLayouts()");
}
throw new UnsupportedOperationException("Not yet implemented");
}
@Deprecated
default ConnectorTableLayout getTableLayout(ConnectorSession session, ConnectorTableLayoutHandle handle)
{
if (usesLegacyTableLayouts()) {
throw new IllegalStateException("Connector uses legacy Table Layout but doesn't implement getTableLayout()");
}
throw new UnsupportedOperationException("Not yet implemented");
}
/**
* Return a table layout handle whose partitioning is converted to the provided partitioning handle,
* but otherwise identical to the provided table layout handle.
* The provided table layout handle must be one that the connector can transparently convert to from
* the original partitioning handle associated with the provided table layout handle,
* as promised by {@link #getCommonPartitioningHandle}.
*
* @deprecated use the version without layouts
*/
@Deprecated
default ConnectorTableLayoutHandle makeCompatiblePartitioning(ConnectorSession session, ConnectorTableLayoutHandle tableLayoutHandle, ConnectorPartitioningHandle partitioningHandle)
{
throw new TrinoException(GENERIC_INTERNAL_ERROR, "ConnectorMetadata getCommonPartitioningHandle() is implemented without makeCompatiblePartitioning()");
}
/**
* Return a table handle whose partitioning is converted to the provided partitioning handle,
* but otherwise identical to the provided table handle.
* The provided table handle must be one that the connector can transparently convert to from
* the original partitioning handle associated with the provided table handle,
* as promised by {@link #getCommonPartitioningHandle}.
*/
default ConnectorTableHandle makeCompatiblePartitioning(ConnectorSession session, ConnectorTableHandle tableHandle, ConnectorPartitioningHandle partitioningHandle)
{
throw new TrinoException(GENERIC_INTERNAL_ERROR, "ConnectorMetadata getCommonPartitioningHandle() is implemented without makeCompatiblePartitioning()");
}
/**
* Return a partitioning handle which the connector can transparently convert both {@code left} and {@code right} into.
*/
default Optional getCommonPartitioningHandle(ConnectorSession session, ConnectorPartitioningHandle left, ConnectorPartitioningHandle right)
{
if (left.equals(right)) {
return Optional.of(left);
}
return Optional.empty();
}
/**
* Return the metadata for the specified table handle.
*
* @throws RuntimeException if table handle is no longer valid
*/
default ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle table)
{
throw new TrinoException(GENERIC_INTERNAL_ERROR, "ConnectorMetadata getTableHandle() is implemented without getTableMetadata()");
}
/**
* Return the connector-specific metadata for the specified table layout. This is the object that is passed to the event listener framework.
*
* @throws RuntimeException if table handle is no longer valid
*/
@Deprecated
default Optional
*/
default Optional> applyAggregation(
ConnectorSession session,
ConnectorTableHandle handle,
List aggregates,
Map assignments,
List> groupingSets)
{
return Optional.empty();
}
/**
* Attempt to push down the TopN into the table scan.
*
* Connectors can indicate whether they don't support topN pushdown or that the action had no effect
* by returning {@link Optional#empty()}. Connectors should expect this method may be called multiple times.
*
* Note: it's critical for connectors to return {@link Optional#empty()} if calling this method has no effect for that
* invocation, even if the connector generally supports topN pushdown. Doing otherwise can cause the optimizer
* to loop indefinitely.
*
* If the connector can handle TopN Pushdown and guarantee it will produce fewer rows than it should return a
* non-empty result with "topN guaranteed" flag set to true.
* @return
*/
default Optional> applyTopN(
ConnectorSession session,
ConnectorTableHandle handle,
long topNCount,
List sortItems,
Map assignments)
{
return Optional.empty();
}
/**
* Allows the connector to reject the table scan produced by the planner.
*
* Connectors can choose to reject a query based on the table scan potentially being too expensive, for example
* if no filtering is done on a partition column.
*
*/
default void validateScan(ConnectorSession session, ConnectorTableHandle handle) {}
/**
* Create the specified materialized view. The view definition is intended to
* be serialized by the connector for permanent storage.
* @throws TrinoException with {@code ALREADY_EXISTS} if the object already exists and {@param ignoreExisting} is not set
*
*/
default void createMaterializedView(ConnectorSession session, SchemaTableName viewName, ConnectorMaterializedViewDefinition definition, boolean replace, boolean ignoreExisting)
{
throw new TrinoException(NOT_SUPPORTED, "This connector does not support creating materialized views");
}
/**
* Drop the specified materialized view.
*/
default void dropMaterializedView(ConnectorSession session, SchemaTableName viewName)
{
throw new TrinoException(NOT_SUPPORTED, "This connector does not support dropping materialized views");
}
/**
* Gets the materialized view data for the specified materialized view name.
*/
default Optional getMaterializedView(ConnectorSession session, SchemaTableName viewName)
{
return Optional.empty();
}
/**
* The method is used by the engine to determine if a materialized view is current with respect to the tables it depends on.
*/
default MaterializedViewFreshness getMaterializedViewFreshness(ConnectorSession session, SchemaTableName name)
{
return new MaterializedViewFreshness(false);
}
default Optional applyTableScanRedirect(ConnectorSession session, ConnectorTableHandle tableHandle)
{
return Optional.empty();
}
}