diff --git a/presto-main/src/main/java/io/prestosql/metadata/MetadataManager.java b/presto-main/src/main/java/io/prestosql/metadata/MetadataManager.java index 65f84b3014fc6..9040f77d072f6 100644 --- a/presto-main/src/main/java/io/prestosql/metadata/MetadataManager.java +++ b/presto-main/src/main/java/io/prestosql/metadata/MetadataManager.java @@ -791,6 +791,11 @@ public boolean supportsMetadataDelete(Session session, TableHandle tableHandle) { CatalogName catalogName = tableHandle.getCatalogName(); ConnectorMetadata metadata = getMetadata(session, catalogName); + + if (!metadata.usesLegacyTableLayouts()) { + return false; + } + return metadata.supportsMetadataDelete( session.toConnectorSession(catalogName), tableHandle.getConnectorHandle(), diff --git a/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorHandleResolver.java b/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorHandleResolver.java index de3cf2c36e792..7936f3f415281 100644 --- a/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorHandleResolver.java +++ b/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorHandleResolver.java @@ -20,7 +20,6 @@ import io.prestosql.spi.connector.ConnectorPartitioningHandle; 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 RaptorHandleResolver @@ -38,12 +37,6 @@ public Class getColumnHandleClass() return RaptorColumnHandle.class; } - @Override - public Class getTableLayoutHandleClass() - { - return RaptorTableLayoutHandle.class; - } - @Override public Class getSplitClass() { diff --git a/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorMetadata.java b/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorMetadata.java index d812c5dbce4cc..abe5fc2c8e692 100644 --- a/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorMetadata.java +++ b/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorMetadata.java @@ -45,13 +45,13 @@ import io.prestosql.spi.connector.ConnectorPartitioningHandle; 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.ConnectorTablePartitioning; +import io.prestosql.spi.connector.ConnectorTableProperties; import io.prestosql.spi.connector.ConnectorViewDefinition; 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; @@ -185,6 +185,8 @@ private RaptorTableHandle getTableHandle(SchemaTableName tableName) table.getBucketCount(), table.isOrganized(), OptionalLong.empty(), + TupleDomain.all(), + table.getDistributionId().map(shardManager::getBucketAssignments), false); } @@ -297,35 +299,52 @@ public Map> listTableColumns(ConnectorSess } @Override - public List getTableLayouts(ConnectorSession session, ConnectorTableHandle table, Constraint constraint, Optional> desiredColumns) + public boolean usesLegacyTableLayouts() { - RaptorTableHandle handle = (RaptorTableHandle) table; - ConnectorTableLayout layout = getTableLayout(session, handle, constraint.getSummary()); - return ImmutableList.of(new ConnectorTableLayoutResult(layout, constraint.getSummary())); + return false; } @Override - public ConnectorTableLayout getTableLayout(ConnectorSession session, ConnectorTableLayoutHandle handle) + public Optional> applyFilter(ConnectorSession session, ConnectorTableHandle handle, Constraint constraint) { - RaptorTableLayoutHandle raptorHandle = (RaptorTableLayoutHandle) handle; - return getTableLayout(session, raptorHandle.getTable(), raptorHandle.getConstraint()); + RaptorTableHandle table = (RaptorTableHandle) handle; + TupleDomain newDomain = constraint.getSummary().transform(RaptorColumnHandle.class::cast); + + if (newDomain.equals(table.getConstraint())) { + return Optional.empty(); + } + + return Optional.of(new ConstraintApplicationResult( + new RaptorTableHandle(table.getSchemaName(), + table.getTableName(), + table.getTableId(), + table.getDistributionId(), + table.getDistributionName(), + table.getBucketCount(), + table.isOrganized(), + table.getTransactionId(), + newDomain.intersect(table.getConstraint()), + table.getBucketAssignments(), + table.isDelete()), + constraint.getSummary())); } - private ConnectorTableLayout getTableLayout(ConnectorSession session, RaptorTableHandle handle, TupleDomain constraint) + @Override + public ConnectorTableProperties getTableProperties(ConnectorSession session, ConnectorTableHandle handle) { - if (!handle.getDistributionId().isPresent()) { - return new ConnectorTableLayout(new RaptorTableLayoutHandle(handle, constraint, Optional.empty())); + RaptorTableHandle table = (RaptorTableHandle) handle; + + if (!table.getPartitioningHandle().isPresent()) { + return new ConnectorTableProperties(); } - List bucketColumnHandles = getBucketColumnHandles(handle.getTableId()); + List bucketColumnHandles = getBucketColumnHandles(table.getTableId()); - RaptorPartitioningHandle partitioning = getPartitioningHandle(handle.getDistributionId().getAsLong()); + RaptorPartitioningHandle partitioning = table.getPartitioningHandle().get(); - boolean oneSplitPerBucket = handle.getBucketCount().getAsInt() >= getOneSplitPerBucketThreshold(session); + boolean oneSplitPerBucket = table.getBucketCount().getAsInt() >= getOneSplitPerBucketThreshold(session); - return new ConnectorTableLayout( - new RaptorTableLayoutHandle(handle, constraint, Optional.of(partitioning)), - Optional.empty(), + return new ConnectorTableProperties( TupleDomain.all(), Optional.of(new ConnectorTablePartitioning( partitioning, @@ -780,6 +799,8 @@ public ConnectorTableHandle beginDelete(ConnectorSession session, ConnectorTable handle.getBucketCount(), handle.isOrganized(), OptionalLong.of(transactionId), + TupleDomain.all(), + handle.getBucketAssignments(), true); } diff --git a/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorPageSourceProvider.java b/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorPageSourceProvider.java index 9cf448b8b762e..b605afc50dfd9 100644 --- a/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorPageSourceProvider.java +++ b/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorPageSourceProvider.java @@ -52,9 +52,10 @@ public RaptorPageSourceProvider(StorageManager storageManager) public ConnectorPageSource createPageSource(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorSplit split, ConnectorTableHandle table, List columns) { RaptorSplit raptorSplit = (RaptorSplit) split; + RaptorTableHandle raptorTable = (RaptorTableHandle) table; OptionalInt bucketNumber = raptorSplit.getBucketNumber(); - TupleDomain predicate = raptorSplit.getEffectivePredicate(); + TupleDomain predicate = raptorTable.getConstraint(); ReaderAttributes attributes = ReaderAttributes.from(session); OptionalLong transactionId = raptorSplit.getTransactionId(); diff --git a/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorSplit.java b/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorSplit.java index 9c7334d4f6638..e8b7990caf547 100644 --- a/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorSplit.java +++ b/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorSplit.java @@ -19,7 +19,6 @@ import com.google.common.collect.ImmutableSet; import io.prestosql.spi.HostAddress; import io.prestosql.spi.connector.ConnectorSplit; -import io.prestosql.spi.predicate.TupleDomain; import java.util.List; import java.util.OptionalInt; @@ -36,49 +35,43 @@ public class RaptorSplit private final Set shardUuids; private final OptionalInt bucketNumber; private final List addresses; - private final TupleDomain effectivePredicate; private final OptionalLong transactionId; @JsonCreator public RaptorSplit( @JsonProperty("shardUuids") Set shardUuids, @JsonProperty("bucketNumber") OptionalInt bucketNumber, - @JsonProperty("effectivePredicate") TupleDomain effectivePredicate, @JsonProperty("transactionId") OptionalLong transactionId) { - this(shardUuids, bucketNumber, ImmutableList.of(), effectivePredicate, transactionId); + this(shardUuids, bucketNumber, ImmutableList.of(), transactionId); } public RaptorSplit( UUID shardUuid, List addresses, - TupleDomain effectivePredicate, OptionalLong transactionId) { - this(ImmutableSet.of(shardUuid), OptionalInt.empty(), addresses, effectivePredicate, transactionId); + this(ImmutableSet.of(shardUuid), OptionalInt.empty(), addresses, transactionId); } public RaptorSplit( Set shardUuids, int bucketNumber, HostAddress address, - TupleDomain effectivePredicate, OptionalLong transactionId) { - this(shardUuids, OptionalInt.of(bucketNumber), ImmutableList.of(address), effectivePredicate, transactionId); + this(shardUuids, OptionalInt.of(bucketNumber), ImmutableList.of(address), transactionId); } private RaptorSplit( Set shardUuids, OptionalInt bucketNumber, List addresses, - TupleDomain effectivePredicate, OptionalLong transactionId) { this.shardUuids = ImmutableSet.copyOf(requireNonNull(shardUuids, "shardUuid is null")); this.bucketNumber = requireNonNull(bucketNumber, "bucketNumber is null"); this.addresses = ImmutableList.copyOf(requireNonNull(addresses, "addresses is null")); - this.effectivePredicate = requireNonNull(effectivePredicate, "effectivePredicate is null"); this.transactionId = requireNonNull(transactionId, "transactionId is null"); } @@ -106,12 +99,6 @@ public OptionalInt getBucketNumber() return bucketNumber; } - @JsonProperty - public TupleDomain getEffectivePredicate() - { - return effectivePredicate; - } - @JsonProperty public OptionalLong getTransactionId() { diff --git a/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorSplitManager.java b/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorSplitManager.java index 00a4e0230b901..edb3ec752c0db 100644 --- a/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorSplitManager.java +++ b/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorSplitManager.java @@ -22,13 +22,12 @@ import io.prestosql.spi.HostAddress; import io.prestosql.spi.Node; import io.prestosql.spi.PrestoException; -import io.prestosql.spi.connector.ColumnHandle; import io.prestosql.spi.connector.ConnectorPartitionHandle; 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.predicate.TupleDomain; import org.skife.jdbi.v2.ResultIterator; @@ -91,18 +90,16 @@ public void destroy() } @Override - public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableLayoutHandle layout, SplitSchedulingStrategy splitSchedulingStrategy) + public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableHandle handle, SplitSchedulingStrategy splitSchedulingStrategy) { - RaptorTableLayoutHandle handle = (RaptorTableLayoutHandle) layout; - RaptorTableHandle table = handle.getTable(); - TupleDomain effectivePredicate = toRaptorTupleDomain(handle.getConstraint()); + RaptorTableHandle table = (RaptorTableHandle) handle; long tableId = table.getTableId(); boolean bucketed = table.getBucketCount().isPresent(); boolean merged = bucketed && !table.isDelete() && (table.getBucketCount().getAsInt() >= getOneSplitPerBucketThreshold(session)); OptionalLong transactionId = table.getTransactionId(); - Optional> bucketToNode = handle.getPartitioning().map(RaptorPartitioningHandle::getBucketToNode); + Optional> bucketToNode = table.getBucketAssignments(); verify(bucketed == bucketToNode.isPresent(), "mismatched bucketCount and bucketToNode presence"); - return new RaptorSplitSource(tableId, merged, effectivePredicate, transactionId, bucketToNode); + return new RaptorSplitSource(tableId, merged, table.getConstraint(), transactionId, bucketToNode); } private static List getAddressesForNodes(Map nodeMap, Iterable nodeIdentifiers) @@ -117,12 +114,6 @@ private static List getAddressesForNodes(Map nodeMap, return nodes.build(); } - @SuppressWarnings("unchecked") - private static TupleDomain toRaptorTupleDomain(TupleDomain tupleDomain) - { - return tupleDomain.transform(handle -> (RaptorColumnHandle) handle); - } - private static T selectRandom(Iterable elements) { List list = ImmutableList.copyOf(elements); @@ -134,10 +125,10 @@ private class RaptorSplitSource { private final Map nodesById = uniqueIndex(nodeSupplier.getWorkerNodes(), Node::getNodeIdentifier); private final long tableId; - private final TupleDomain effectivePredicate; private final OptionalLong transactionId; private final Optional> bucketToNode; private final ResultIterator iterator; + private final TupleDomain effectivePredicate; @GuardedBy("this") private CompletableFuture future; @@ -233,7 +224,7 @@ private ConnectorSplit createSplit(BucketShards bucketShards) addresses = ImmutableList.of(node.getHostAndPort()); } - return new RaptorSplit(shardId, addresses, effectivePredicate, transactionId); + return new RaptorSplit(shardId, addresses, transactionId); } private ConnectorSplit createBucketSplit(int bucketNumber, Set shards) @@ -252,7 +243,7 @@ private ConnectorSplit createBucketSplit(int bucketNumber, Set shard .collect(toSet()); HostAddress address = node.getHostAndPort(); - return new RaptorSplit(shardUuids, bucketNumber, address, effectivePredicate, transactionId); + return new RaptorSplit(shardUuids, bucketNumber, address, transactionId); } } } diff --git a/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorTableHandle.java b/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorTableHandle.java index 4ff55010cbcf9..b5afc371e7b3e 100644 --- a/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorTableHandle.java +++ b/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/RaptorTableHandle.java @@ -14,9 +14,13 @@ package io.prestosql.plugin.raptor.legacy; import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.collect.ImmutableList; import io.prestosql.spi.connector.ConnectorTableHandle; +import io.prestosql.spi.predicate.TupleDomain; +import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.OptionalInt; @@ -33,11 +37,13 @@ public final class RaptorTableHandle private final String schemaName; private final String tableName; private final long tableId; - private final OptionalLong distributionId; + private final Optional distributionId; private final Optional distributionName; private final OptionalInt bucketCount; private final boolean organized; private final OptionalLong transactionId; + private final TupleDomain constraint; + private final Optional> bucketAssignments; private final boolean delete; @JsonCreator @@ -45,11 +51,14 @@ public RaptorTableHandle( @JsonProperty("schemaName") String schemaName, @JsonProperty("tableName") String tableName, @JsonProperty("tableId") long tableId, - @JsonProperty("distributionId") OptionalLong distributionId, + @JsonProperty("distributionId") Optional distributionId, @JsonProperty("distributionName") Optional distributionName, @JsonProperty("bucketCount") OptionalInt bucketCount, @JsonProperty("organized") boolean organized, @JsonProperty("transactionId") OptionalLong transactionId, + @JsonProperty("constraint") TupleDomain constraint, + // this field will not be in the JSON, but keep it here to avoid duplicating the constructor + @JsonProperty("bucketAssignments") Optional> bucketAssignments, @JsonProperty("delete") boolean delete) { this.schemaName = checkSchemaName(schemaName); @@ -64,6 +73,8 @@ public RaptorTableHandle( this.organized = organized; this.transactionId = requireNonNull(transactionId, "transactionId is null"); + this.constraint = requireNonNull(constraint, "constraint is null"); + this.bucketAssignments = requireNonNull(bucketAssignments, "bucketAssignments is null").map(ImmutableList::copyOf); this.delete = delete; } @@ -91,7 +102,7 @@ public long getTableId() } @JsonProperty - public OptionalLong getDistributionId() + public Optional getDistributionId() { return distributionId; } @@ -114,6 +125,12 @@ public boolean isOrganized() return organized; } + @JsonProperty + public TupleDomain getConstraint() + { + return constraint; + } + @JsonProperty public OptionalLong getTransactionId() { @@ -126,6 +143,12 @@ public boolean isDelete() return delete; } + @JsonIgnore + public Optional> getBucketAssignments() + { + return bucketAssignments; + } + @Override public String toString() { @@ -152,4 +175,10 @@ public boolean equals(Object obj) Objects.equals(this.tableName, other.tableName) && Objects.equals(this.tableId, other.tableId); } + + @JsonIgnore + public Optional getPartitioningHandle() + { + return distributionId.map(id -> new RaptorPartitioningHandle(id, bucketAssignments.get())); + } } diff --git a/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/metadata/Table.java b/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/metadata/Table.java index f37496a40c30c..017b233329051 100644 --- a/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/metadata/Table.java +++ b/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/metadata/Table.java @@ -23,6 +23,7 @@ import java.util.OptionalLong; import static com.google.common.base.MoreObjects.toStringHelper; +import static io.prestosql.plugin.raptor.legacy.util.DatabaseUtil.getBoxedLong; import static io.prestosql.plugin.raptor.legacy.util.DatabaseUtil.getOptionalInt; import static io.prestosql.plugin.raptor.legacy.util.DatabaseUtil.getOptionalLong; import static java.util.Objects.requireNonNull; @@ -30,7 +31,7 @@ public final class Table { private final long tableId; - private final OptionalLong distributionId; + private final Optional distributionId; private final Optional distributionName; private final OptionalInt bucketCount; private final OptionalLong temporalColumnId; @@ -38,7 +39,7 @@ public final class Table public Table( long tableId, - OptionalLong distributionId, + Optional distributionId, Optional distributionName, OptionalInt bucketCount, OptionalLong temporalColumnId, @@ -57,7 +58,7 @@ public long getTableId() return tableId; } - public OptionalLong getDistributionId() + public Optional getDistributionId() { return distributionId; } @@ -87,7 +88,7 @@ public String toString() { return toStringHelper(this) .add("tableId", tableId) - .add("distributionId", distributionId.isPresent() ? distributionId.getAsLong() : null) + .add("distributionId", distributionId.orElse(null)) .add("bucketCount", bucketCount.isPresent() ? bucketCount.getAsInt() : null) .add("temporalColumnId", temporalColumnId.isPresent() ? temporalColumnId.getAsLong() : null) .add("organized", organized) @@ -104,7 +105,7 @@ public Table map(int index, ResultSet r, StatementContext ctx) { return new Table( r.getLong("table_id"), - getOptionalLong(r, "distribution_id"), + Optional.ofNullable(getBoxedLong(r, "distribution_id")), Optional.ofNullable(r.getString("distribution_name")), getOptionalInt(r, "bucket_count"), getOptionalLong(r, "temporal_column_id"), diff --git a/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/util/DatabaseUtil.java b/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/util/DatabaseUtil.java index 99b6c0322339c..df23c2579e262 100644 --- a/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/util/DatabaseUtil.java +++ b/presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/util/DatabaseUtil.java @@ -128,6 +128,13 @@ public static OptionalLong getOptionalLong(ResultSet rs, String name) return rs.wasNull() ? OptionalLong.empty() : OptionalLong.of(value); } + public static Long getBoxedLong(ResultSet rs, String name) + throws SQLException + { + long value = rs.getLong(name); + return rs.wasNull() ? null : value; + } + public static void bindOptionalInt(PreparedStatement statement, int index, OptionalInt value) throws SQLException { diff --git a/presto-raptor-legacy/src/test/java/io/prestosql/plugin/raptor/legacy/metadata/TestMetadataDao.java b/presto-raptor-legacy/src/test/java/io/prestosql/plugin/raptor/legacy/metadata/TestMetadataDao.java index 5830442143ab7..5d7ea09dbcd87 100644 --- a/presto-raptor-legacy/src/test/java/io/prestosql/plugin/raptor/legacy/metadata/TestMetadataDao.java +++ b/presto-raptor-legacy/src/test/java/io/prestosql/plugin/raptor/legacy/metadata/TestMetadataDao.java @@ -87,7 +87,7 @@ public void testGetTableInformation() private static void assertTable(Table info, long tableId) { assertEquals(info.getTableId(), tableId); - assertEquals(info.getDistributionId(), OptionalLong.empty()); + assertEquals(info.getDistributionId(), Optional.empty()); assertEquals(info.getDistributionName(), Optional.empty()); assertEquals(info.getBucketCount(), OptionalInt.empty()); assertEquals(info.getTemporalColumnId(), OptionalLong.empty()); diff --git a/presto-raptor-legacy/src/test/java/io/prestosql/plugin/raptor/legacy/metadata/TestRaptorSplitManager.java b/presto-raptor-legacy/src/test/java/io/prestosql/plugin/raptor/legacy/metadata/TestRaptorSplitManager.java index 52f89be920f5f..877e7d7602d24 100644 --- a/presto-raptor-legacy/src/test/java/io/prestosql/plugin/raptor/legacy/metadata/TestRaptorSplitManager.java +++ b/presto-raptor-legacy/src/test/java/io/prestosql/plugin/raptor/legacy/metadata/TestRaptorSplitManager.java @@ -25,17 +25,14 @@ import io.prestosql.plugin.raptor.legacy.RaptorMetadata; import io.prestosql.plugin.raptor.legacy.RaptorSplitManager; import io.prestosql.plugin.raptor.legacy.RaptorTableHandle; -import io.prestosql.plugin.raptor.legacy.RaptorTableLayoutHandle; import io.prestosql.plugin.raptor.legacy.RaptorTransactionHandle; import io.prestosql.plugin.raptor.legacy.util.DaoSupplier; import io.prestosql.spi.PrestoException; import io.prestosql.spi.connector.ConnectorSplit; import io.prestosql.spi.connector.ConnectorSplitSource; import io.prestosql.spi.connector.ConnectorTableHandle; -import io.prestosql.spi.connector.ConnectorTableLayoutResult; import io.prestosql.spi.connector.ConnectorTableMetadata; import io.prestosql.spi.connector.ConnectorTransactionHandle; -import io.prestosql.spi.connector.Constraint; import io.prestosql.spi.type.BigintType; import io.prestosql.testing.TestingNodeManager; import io.prestosql.type.InternalTypeManager; @@ -60,7 +57,6 @@ import static com.google.common.io.MoreFiles.deleteRecursively; import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE; import static io.airlift.concurrent.MoreFutures.getFutureValue; -import static io.airlift.testing.Assertions.assertInstanceOf; import static io.prestosql.metadata.MetadataManager.createTestMetadataManager; import static io.prestosql.plugin.raptor.legacy.metadata.DatabaseShardManager.shardIndexTable; import static io.prestosql.plugin.raptor.legacy.metadata.SchemaDaoUtil.createTablesWithRetry; @@ -145,12 +141,7 @@ public void teardown() @Test public void testSanity() { - List layouts = metadata.getTableLayouts(SESSION, tableHandle, Constraint.alwaysTrue(), Optional.empty()); - assertEquals(layouts.size(), 1); - ConnectorTableLayoutResult layout = getOnlyElement(layouts); - assertInstanceOf(layout.getTableLayout().getHandle(), RaptorTableLayoutHandle.class); - - ConnectorSplitSource splitSource = getSplits(raptorSplitManager, layout); + ConnectorSplitSource splitSource = getSplits(raptorSplitManager, tableHandle); int splitCount = 0; while (!splitSource.isFinished()) { splitCount += getSplits(splitSource, 1000).size(); @@ -163,8 +154,7 @@ public void testNoHostForShard() { deleteShardNodes(); - ConnectorTableLayoutResult layout = getOnlyElement(metadata.getTableLayouts(SESSION, tableHandle, Constraint.alwaysTrue(), Optional.empty())); - ConnectorSplitSource splitSource = getSplits(raptorSplitManager, layout); + ConnectorSplitSource splitSource = getSplits(raptorSplitManager, tableHandle); getSplits(splitSource, 1000); } @@ -181,8 +171,7 @@ public void testAssignRandomNodeWhenBackupAvailable() deleteShardNodes(); - ConnectorTableLayoutResult layout = getOnlyElement(metadata.getTableLayouts(SESSION, tableHandle, Constraint.alwaysTrue(), Optional.empty())); - ConnectorSplitSource partitionSplit = getSplits(raptorSplitManagerWithBackup, layout); + ConnectorSplitSource partitionSplit = getSplits(raptorSplitManagerWithBackup, tableHandle); List batch = getSplits(partitionSplit, 1); assertEquals(getOnlyElement(getOnlyElement(batch).getAddresses()), node.getHostAndPort()); } @@ -193,8 +182,7 @@ public void testNoNodes() deleteShardNodes(); RaptorSplitManager raptorSplitManagerWithBackup = new RaptorSplitManager(new RaptorConnectorId("fbraptor"), ImmutableSet::of, shardManager, true); - ConnectorTableLayoutResult layout = getOnlyElement(metadata.getTableLayouts(SESSION, tableHandle, Constraint.alwaysTrue(), Optional.empty())); - ConnectorSplitSource splitSource = getSplits(raptorSplitManagerWithBackup, layout); + ConnectorSplitSource splitSource = getSplits(raptorSplitManagerWithBackup, tableHandle); getSplits(splitSource, 1000); } @@ -204,10 +192,10 @@ private void deleteShardNodes() dummyHandle.execute(format("UPDATE %s SET node_ids = ''", shardIndexTable(tableId))); } - private static ConnectorSplitSource getSplits(RaptorSplitManager splitManager, ConnectorTableLayoutResult layout) + private static ConnectorSplitSource getSplits(RaptorSplitManager splitManager, ConnectorTableHandle table) { ConnectorTransactionHandle transaction = new RaptorTransactionHandle(); - return splitManager.getSplits(transaction, SESSION, layout.getTableLayout().getHandle(), UNGROUPED_SCHEDULING); + return splitManager.getSplits(transaction, SESSION, table, UNGROUPED_SCHEDULING); } private static List getSplits(ConnectorSplitSource source, int maxSize) diff --git a/presto-raptor-legacy/src/test/java/io/prestosql/plugin/raptor/legacy/storage/organization/TestCompactionSetCreator.java b/presto-raptor-legacy/src/test/java/io/prestosql/plugin/raptor/legacy/storage/organization/TestCompactionSetCreator.java index 391673931240d..0a0059b428923 100644 --- a/presto-raptor-legacy/src/test/java/io/prestosql/plugin/raptor/legacy/storage/organization/TestCompactionSetCreator.java +++ b/presto-raptor-legacy/src/test/java/io/prestosql/plugin/raptor/legacy/storage/organization/TestCompactionSetCreator.java @@ -40,10 +40,10 @@ public class TestCompactionSetCreator { private static final long MAX_SHARD_ROWS = 100; private static final DataSize MAX_SHARD_SIZE = new DataSize(100, DataSize.Unit.BYTE); - private static final Table tableInfo = new Table(1L, OptionalLong.empty(), Optional.empty(), OptionalInt.empty(), OptionalLong.empty(), false); - private static final Table temporalTableInfo = new Table(1L, OptionalLong.empty(), Optional.empty(), OptionalInt.empty(), OptionalLong.of(1), false); - private static final Table bucketedTableInfo = new Table(1L, OptionalLong.empty(), Optional.empty(), OptionalInt.of(3), OptionalLong.empty(), false); - private static final Table bucketedTemporalTableInfo = new Table(1L, OptionalLong.empty(), Optional.empty(), OptionalInt.of(3), OptionalLong.of(1), false); + private static final Table tableInfo = new Table(1L, Optional.empty(), Optional.empty(), OptionalInt.empty(), OptionalLong.empty(), false); + private static final Table temporalTableInfo = new Table(1L, Optional.empty(), Optional.empty(), OptionalInt.empty(), OptionalLong.of(1), false); + private static final Table bucketedTableInfo = new Table(1L, Optional.empty(), Optional.empty(), OptionalInt.of(3), OptionalLong.empty(), false); + private static final Table bucketedTemporalTableInfo = new Table(1L, Optional.empty(), Optional.empty(), OptionalInt.of(3), OptionalLong.of(1), false); private final CompactionSetCreator compactionSetCreator = new CompactionSetCreator(new TemporalFunction(UTC), MAX_SHARD_SIZE, MAX_SHARD_ROWS); diff --git a/presto-raptor-legacy/src/test/java/io/prestosql/plugin/raptor/legacy/storage/organization/TestShardOrganizationManager.java b/presto-raptor-legacy/src/test/java/io/prestosql/plugin/raptor/legacy/storage/organization/TestShardOrganizationManager.java index 49c64e79bfb08..ae0b86bc8b4dc 100644 --- a/presto-raptor-legacy/src/test/java/io/prestosql/plugin/raptor/legacy/storage/organization/TestShardOrganizationManager.java +++ b/presto-raptor-legacy/src/test/java/io/prestosql/plugin/raptor/legacy/storage/organization/TestShardOrganizationManager.java @@ -59,8 +59,8 @@ public class TestShardOrganizationManager private MetadataDao metadataDao; private ShardOrganizerDao organizerDao; - private static final Table tableInfo = new Table(1L, OptionalLong.empty(), Optional.empty(), OptionalInt.empty(), OptionalLong.empty(), true); - private static final Table temporalTableInfo = new Table(1L, OptionalLong.empty(), Optional.empty(), OptionalInt.empty(), OptionalLong.of(1), true); + private static final Table tableInfo = new Table(1L, Optional.empty(), Optional.empty(), OptionalInt.empty(), OptionalLong.empty(), true); + private static final Table temporalTableInfo = new Table(1L, Optional.empty(), Optional.empty(), OptionalInt.empty(), OptionalLong.of(1), true); private static final List types = ImmutableList.of(BIGINT, VARCHAR, DATE, TIMESTAMP); private static final TemporalFunction TEMPORAL_FUNCTION = new TemporalFunction(UTC);