Skip to content

Commit

Permalink
Clean up memory connector data structures
Browse files Browse the repository at this point in the history
Introduce TableId to represent the identity of a table
and separate it from the associated metadata, which is
now stored in TableInfo/ColumnInfo.

MemoryTableHandle is now use only in the interface between
engine and connector and is meant to represent the reference
to the entity over which the query will execute. Once we
add support for various types of pushdown, that information
will be encoded in the handle.
  • Loading branch information
martint committed Mar 12, 2019
1 parent a546ad2 commit aa802e8
Show file tree
Hide file tree
Showing 15 changed files with 223 additions and 274 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,43 @@
*/
package io.prestosql.plugin.memory;

import java.util.Objects;
import io.prestosql.spi.connector.ColumnHandle;
import io.prestosql.spi.connector.ColumnMetadata;
import io.prestosql.spi.type.Type;

import static java.util.Objects.requireNonNull;

public final class MemoryConnectorId
public class ColumnInfo
{
private final String id;
private final ColumnHandle handle;
private final String name;
private final Type type;

public MemoryConnectorId(String id)
public ColumnInfo(ColumnHandle handle, String name, Type type)
{
this.id = requireNonNull(id, "id is null");
this.handle = requireNonNull(handle, "handle is null");
this.name = requireNonNull(name, "name is null");
this.type = requireNonNull(type, "type is null");
}

@Override
public String toString()
public ColumnHandle getHandle()
{
return id;
return handle;
}

@Override
public int hashCode()
public String getName()
{
return Objects.hash(id);
return name;
}

public ColumnMetadata getMetadata()
{
return new ColumnMetadata(name, type);
}

@Override
public boolean equals(Object obj)
public String toString()
{
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
return false;
}

MemoryConnectorId other = (MemoryConnectorId) obj;
return Objects.equals(this.id, other.id);
return name + "::" + type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,67 +15,31 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;
import io.prestosql.spi.connector.ColumnHandle;
import io.prestosql.spi.connector.ColumnMetadata;
import io.prestosql.spi.type.Type;

import java.util.List;
import java.util.Objects;

import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;

public final class MemoryColumnHandle
implements ColumnHandle
{
private final String name;
private final Type columnType;
private final int columnIndex;

public MemoryColumnHandle(ColumnMetadata columnMetadata, int columnIndex)
{
this(columnMetadata.getName(), columnMetadata.getType(), columnIndex);
}

@JsonCreator
public MemoryColumnHandle(
@JsonProperty("name") String name,
@JsonProperty("columnType") Type columnType,
@JsonProperty("columnIndex") int columnIndex)
public MemoryColumnHandle(@JsonProperty("columnIndex") int columnIndex)
{
this.name = requireNonNull(name, "name is null");
this.columnType = requireNonNull(columnType, "columnType is null");
this.columnIndex = columnIndex;
}

@JsonProperty
public String getName()
{
return name;
}

@JsonProperty
public Type getColumnType()
{
return columnType;
}

@JsonProperty
public int getColumnIndex()
{
return columnIndex;
}

public ColumnMetadata toColumnMetadata()
{
return new ColumnMetadata(name, columnType);
}

@Override
public int hashCode()
{
return Objects.hash(name, columnType);
return Objects.hash(columnIndex);
}

@Override
Expand All @@ -88,29 +52,12 @@ public boolean equals(Object obj)
return false;
}
MemoryColumnHandle other = (MemoryColumnHandle) obj;
return Objects.equals(this.name, other.name) &&
Objects.equals(this.columnType, other.columnType) &&
Objects.equals(this.columnIndex, other.columnIndex);
}

public static List<MemoryColumnHandle> extractColumnHandles(List<ColumnMetadata> columns)
{
ImmutableList.Builder<MemoryColumnHandle> columnHandles = ImmutableList.builder();
int columnIndex = 0;
for (ColumnMetadata column : columns) {
columnHandles.add(new MemoryColumnHandle(column, columnIndex));
columnIndex++;
}
return columnHandles.build();
return Objects.equals(this.columnIndex, other.columnIndex);
}

@Override
public String toString()
{
return toStringHelper(this)
.add("name", name)
.add("columnType", columnType)
.add("columnIndex", columnIndex)
.toString();
return Integer.toString(columnIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Connector create(String catalogName, Map<String, String> requiredConfig,
// A plugin is not required to use Guice; it is just very convenient
Bootstrap app = new Bootstrap(
new JsonModule(),
new MemoryModule(catalogName, context.getTypeManager(), context.getNodeManager()));
new MemoryModule(context.getTypeManager(), context.getNodeManager()));

Injector injector = app
.strictConfig()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@
public class MemoryInsertTableHandle
implements ConnectorInsertTableHandle
{
private final MemoryTableHandle table;
private final long table;
private final Set<Long> activeTableIds;

@JsonCreator
public MemoryInsertTableHandle(
@JsonProperty("table") MemoryTableHandle table,
@JsonProperty("table") long table,
@JsonProperty("activeTableIds") Set<Long> activeTableIds)
{
this.table = requireNonNull(table, "table is null");
this.activeTableIds = requireNonNull(activeTableIds, "activeTableIds is null");
}

@JsonProperty
public MemoryTableHandle getTable()
public long getTable()
{
return table;
}
Expand Down
Loading

0 comments on commit aa802e8

Please sign in to comment.