diff --git a/presto-main/src/main/java/io/prestosql/connector/system/SystemHandleResolver.java b/presto-main/src/main/java/io/prestosql/connector/system/SystemHandleResolver.java index 72c2edea7471..fc8030b41640 100644 --- a/presto-main/src/main/java/io/prestosql/connector/system/SystemHandleResolver.java +++ b/presto-main/src/main/java/io/prestosql/connector/system/SystemHandleResolver.java @@ -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 @@ -29,12 +28,6 @@ public Class getTableHandleClass() return SystemTableHandle.class; } - @Override - public Class getTableLayoutHandleClass() - { - return SystemTableLayoutHandle.class; - } - @Override public Class getColumnHandleClass() { diff --git a/presto-main/src/main/java/io/prestosql/connector/system/SystemSplitManager.java b/presto-main/src/main/java/io/prestosql/connector/system/SystemSplitManager.java index 9f4fe0bdf756..bc35a51ccf49 100644 --- a/presto-main/src/main/java/io/prestosql/connector/system/SystemSplitManager.java +++ b/presto-main/src/main/java/io/prestosql/connector/system/SystemSplitManager.java @@ -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 @@ -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 constraint = table.getConstraint(); - TupleDomain 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) { diff --git a/presto-main/src/main/java/io/prestosql/connector/system/SystemTableHandle.java b/presto-main/src/main/java/io/prestosql/connector/system/SystemTableHandle.java index 128a73eceb17..3af5e95beb49 100644 --- a/presto-main/src/main/java/io/prestosql/connector/system/SystemTableHandle.java +++ b/presto-main/src/main/java/io/prestosql/connector/system/SystemTableHandle.java @@ -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; @@ -29,20 +31,23 @@ public class SystemTableHandle { private final String schemaName; private final String tableName; + private final TupleDomain constraint; @JsonCreator public SystemTableHandle( @JsonProperty("schemaName") String schemaName, - @JsonProperty("tableName") String tableName) + @JsonProperty("tableName") String tableName, + @JsonProperty("constraint") TupleDomain 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 @@ -62,6 +67,12 @@ public SchemaTableName getSchemaTableName() return new SchemaTableName(schemaName, tableName); } + @JsonProperty + public TupleDomain getConstraint() + { + return constraint; + } + @Override public String toString() { diff --git a/presto-main/src/main/java/io/prestosql/connector/system/SystemTableLayoutHandle.java b/presto-main/src/main/java/io/prestosql/connector/system/SystemTableLayoutHandle.java deleted file mode 100644 index 5670f3acb6d2..000000000000 --- a/presto-main/src/main/java/io/prestosql/connector/system/SystemTableLayoutHandle.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.prestosql.connector.system; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import io.prestosql.spi.connector.ColumnHandle; -import io.prestosql.spi.connector.ConnectorTableLayoutHandle; -import io.prestosql.spi.predicate.TupleDomain; - -import static java.util.Objects.requireNonNull; - -public class SystemTableLayoutHandle - implements ConnectorTableLayoutHandle -{ - private final SystemTableHandle table; - private final TupleDomain constraint; - - @JsonCreator - public SystemTableLayoutHandle( - @JsonProperty("table") SystemTableHandle table, - @JsonProperty("constraint") TupleDomain constraint) - { - this.table = requireNonNull(table, "table is null"); - this.constraint = requireNonNull(constraint, "constraint is null"); - } - - @JsonProperty - public SystemTableHandle getTable() - { - return table; - } - - @JsonProperty - public TupleDomain getConstraint() - { - return constraint; - } - - @Override - public String toString() - { - return table.toString(); - } -} diff --git a/presto-main/src/main/java/io/prestosql/connector/system/SystemTablesMetadata.java b/presto-main/src/main/java/io/prestosql/connector/system/SystemTablesMetadata.java index 7419c1f4ce55..a7aefb3331b3 100644 --- a/presto-main/src/main/java/io/prestosql/connector/system/SystemTablesMetadata.java +++ b/presto-main/src/main/java/io/prestosql/connector/system/SystemTablesMetadata.java @@ -13,7 +13,6 @@ */ 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; @@ -21,19 +20,18 @@ 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; @@ -73,20 +71,6 @@ public ConnectorTableHandle getTableHandle(ConnectorSession session, SchemaTable return SystemTableHandle.fromSchemaTableName(tableName); } - @Override - public List getTableLayouts(ConnectorSession session, ConnectorTableHandle table, Constraint constraint, Optional> 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) { @@ -152,4 +136,32 @@ public Map> 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> applyFilter(ConnectorSession session, ConnectorTableHandle handle, Constraint constraint) + { + SystemTableHandle table = (SystemTableHandle) handle; + + TupleDomain oldDomain = table.getConstraint(); + TupleDomain 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())); + } } diff --git a/presto-main/src/test/java/io/prestosql/metadata/TestSystemTableHandle.java b/presto-main/src/test/java/io/prestosql/metadata/TestSystemTableHandle.java index e313ae0f6833..7b9f87b07307 100644 --- a/presto-main/src/test/java/io/prestosql/metadata/TestSystemTableHandle.java +++ b/presto-main/src/test/java/io/prestosql/metadata/TestSystemTableHandle.java @@ -15,6 +15,7 @@ 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; @@ -22,6 +23,7 @@ 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; @@ -37,7 +39,8 @@ public class TestSystemTableHandle private static final Map 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; @@ -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);