Skip to content

Commit

Permalink
Remove table layouts from system connector
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed May 10, 2019
1 parent f7d52ac commit 37ad8be
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import io.prestosql.spi.connector.ConnectorHandleResolver;
import io.prestosql.spi.connector.ConnectorSplit;
import io.prestosql.spi.connector.ConnectorTableHandle;
import io.prestosql.spi.connector.ConnectorTableLayoutHandle;
import io.prestosql.spi.connector.ConnectorTransactionHandle;

public class SystemHandleResolver
Expand All @@ -29,12 +28,6 @@ public Class<? extends ConnectorTableHandle> getTableHandleClass()
return SystemTableHandle.class;
}

@Override
public Class<? extends ConnectorTableLayoutHandle> getTableLayoutHandleClass()
{
return SystemTableLayoutHandle.class;
}

@Override
public Class<? extends ColumnHandle> getColumnHandleClass()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,25 @@
import io.prestosql.metadata.InternalNode;
import io.prestosql.metadata.InternalNodeManager;
import io.prestosql.spi.HostAddress;
import io.prestosql.spi.PrestoException;
import io.prestosql.spi.connector.ColumnHandle;
import io.prestosql.spi.connector.ConnectorSession;
import io.prestosql.spi.connector.ConnectorSplit;
import io.prestosql.spi.connector.ConnectorSplitManager;
import io.prestosql.spi.connector.ConnectorSplitSource;
import io.prestosql.spi.connector.ConnectorTableLayoutHandle;
import io.prestosql.spi.connector.ConnectorTableHandle;
import io.prestosql.spi.connector.ConnectorTransactionHandle;
import io.prestosql.spi.connector.FixedSplitSource;
import io.prestosql.spi.connector.SystemTable;
import io.prestosql.spi.connector.SystemTable.Distribution;
import io.prestosql.spi.connector.TableNotFoundException;
import io.prestosql.spi.predicate.TupleDomain;

import java.util.Set;

import static io.prestosql.metadata.NodeState.ACTIVE;
import static io.prestosql.spi.StandardErrorCode.NOT_FOUND;
import static io.prestosql.spi.connector.SystemTable.Distribution.ALL_COORDINATORS;
import static io.prestosql.spi.connector.SystemTable.Distribution.ALL_NODES;
import static io.prestosql.spi.connector.SystemTable.Distribution.SINGLE_COORDINATOR;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

public class SystemSplitManager
Expand All @@ -54,15 +52,18 @@ public SystemSplitManager(InternalNodeManager nodeManager, SystemTablesProvider
}

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layout, SplitSchedulingStrategy splitSchedulingStrategy)
public ConnectorSplitSource getSplits(
ConnectorTransactionHandle transaction,
ConnectorSession session,
ConnectorTableHandle tableHandle,
SplitSchedulingStrategy splitSchedulingStrategy)
{
SystemTableLayoutHandle layoutHandle = (SystemTableLayoutHandle) layout;
SystemTableHandle tableHandle = layoutHandle.getTable();
SystemTableHandle table = (SystemTableHandle) tableHandle;
TupleDomain<ColumnHandle> constraint = table.getConstraint();

TupleDomain<ColumnHandle> constraint = layoutHandle.getConstraint();
SystemTable systemTable = tables.getSystemTable(session, tableHandle.getSchemaTableName())
SystemTable systemTable = tables.getSystemTable(session, table.getSchemaTableName())
// table might disappear in the meantime
.orElseThrow(() -> new PrestoException(NOT_FOUND, format("Table %s not found", tableHandle.getSchemaTableName())));
.orElseThrow(() -> new TableNotFoundException(table.getSchemaTableName()));

Distribution tableDistributionMode = systemTable.getDistribution();
if (tableDistributionMode == SINGLE_COORDINATOR) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.prestosql.spi.connector.ColumnHandle;
import io.prestosql.spi.connector.ConnectorTableHandle;
import io.prestosql.spi.connector.SchemaTableName;
import io.prestosql.spi.predicate.TupleDomain;

import java.util.Objects;

Expand All @@ -29,20 +31,23 @@ public class SystemTableHandle
{
private final String schemaName;
private final String tableName;
private final TupleDomain<ColumnHandle> constraint;

@JsonCreator
public SystemTableHandle(
@JsonProperty("schemaName") String schemaName,
@JsonProperty("tableName") String tableName)
@JsonProperty("tableName") String tableName,
@JsonProperty("constraint") TupleDomain<ColumnHandle> constraint)
{
this.schemaName = checkSchemaName(schemaName);
this.tableName = checkTableName(tableName);
this.constraint = requireNonNull(constraint, "constraint is null");
}

public static SystemTableHandle fromSchemaTableName(SchemaTableName tableName)
{
requireNonNull(tableName, "tableName is null");
return new SystemTableHandle(tableName.getSchemaName(), tableName.getTableName());
return new SystemTableHandle(tableName.getSchemaName(), tableName.getTableName(), TupleDomain.all());
}

@JsonProperty
Expand All @@ -62,6 +67,12 @@ public SchemaTableName getSchemaTableName()
return new SchemaTableName(schemaName, tableName);
}

@JsonProperty
public TupleDomain<ColumnHandle> getConstraint()
{
return constraint;
}

@Override
public String toString()
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,25 @@
*/
package io.prestosql.connector.system;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.prestosql.spi.PrestoException;
import io.prestosql.spi.connector.ColumnHandle;
import io.prestosql.spi.connector.ColumnMetadata;
import io.prestosql.spi.connector.ConnectorMetadata;
import io.prestosql.spi.connector.ConnectorSession;
import io.prestosql.spi.connector.ConnectorTableHandle;
import io.prestosql.spi.connector.ConnectorTableLayout;
import io.prestosql.spi.connector.ConnectorTableLayoutHandle;
import io.prestosql.spi.connector.ConnectorTableLayoutResult;
import io.prestosql.spi.connector.ConnectorTableMetadata;
import io.prestosql.spi.connector.ConnectorTableProperties;
import io.prestosql.spi.connector.Constraint;
import io.prestosql.spi.connector.ConstraintApplicationResult;
import io.prestosql.spi.connector.SchemaTableName;
import io.prestosql.spi.connector.SchemaTablePrefix;
import io.prestosql.spi.connector.SystemTable;
import io.prestosql.spi.predicate.TupleDomain;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList;
Expand Down Expand Up @@ -73,20 +71,6 @@ public ConnectorTableHandle getTableHandle(ConnectorSession session, SchemaTable
return SystemTableHandle.fromSchemaTableName(tableName);
}

@Override
public List<ConnectorTableLayoutResult> getTableLayouts(ConnectorSession session, ConnectorTableHandle table, Constraint constraint, Optional<Set<ColumnHandle>> desiredColumns)
{
SystemTableHandle tableHandle = (SystemTableHandle) table;
ConnectorTableLayout layout = new ConnectorTableLayout(new SystemTableLayoutHandle(tableHandle, constraint.getSummary()));
return ImmutableList.of(new ConnectorTableLayoutResult(layout, constraint.getSummary()));
}

@Override
public ConnectorTableLayout getTableLayout(ConnectorSession session, ConnectorTableLayoutHandle handle)
{
return new ConnectorTableLayout(handle);
}

@Override
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle tableHandle)
{
Expand Down Expand Up @@ -152,4 +136,32 @@ public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSess
}
return builder.build();
}

@Override
public boolean usesLegacyTableLayouts()
{
return false;
}

@Override
public ConnectorTableProperties getTableProperties(ConnectorSession session, ConnectorTableHandle table)
{
return new ConnectorTableProperties();
}

@Override
public Optional<ConstraintApplicationResult<ConnectorTableHandle>> applyFilter(ConnectorSession session, ConnectorTableHandle handle, Constraint constraint)
{
SystemTableHandle table = (SystemTableHandle) handle;

TupleDomain<ColumnHandle> oldDomain = table.getConstraint();
TupleDomain<ColumnHandle> newDomain = oldDomain.intersect(constraint.getSummary());
if (oldDomain.equals(newDomain)) {
return Optional.empty();
}

table = new SystemTableHandle(table.getSchemaName(), table.getTableName(), newDomain);

return Optional.of(new ConstraintApplicationResult<>(table, constraint.getSummary()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Guice;
import com.google.inject.Injector;
import io.airlift.json.JsonModule;
import io.prestosql.connector.system.SystemTableHandle;
import io.prestosql.spi.connector.ConnectorTableHandle;
import io.prestosql.spi.connector.SchemaTableName;
import io.prestosql.spi.predicate.TupleDomain;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

Expand All @@ -37,7 +39,8 @@ public class TestSystemTableHandle
private static final Map<String, Object> SCHEMA_AS_MAP = ImmutableMap.of(
"@type", "$system",
"schemaName", "system_schema",
"tableName", "system_table");
"tableName", "system_table",
"constraint", ImmutableMap.of("columnDomains", ImmutableList.of()));

private ObjectMapper objectMapper;

Expand All @@ -53,7 +56,7 @@ public void startUp()
public void testSystemSerialize()
throws Exception
{
SystemTableHandle internalHandle = new SystemTableHandle("system_schema", "system_table");
SystemTableHandle internalHandle = new SystemTableHandle("system_schema", "system_table", TupleDomain.all());

assertTrue(objectMapper.canSerialize(SystemTableHandle.class));
String json = objectMapper.writeValueAsString(internalHandle);
Expand Down

0 comments on commit 37ad8be

Please sign in to comment.