Skip to content

Commit

Permalink
Convert AtopTableHandle to record
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed May 25, 2024
1 parent 24b5f15 commit 0c4426f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ public ConnectorTableMetadata getTableMetadata(ConnectorSession session, Connect
{
AtopTableHandle atopTableHandle = (AtopTableHandle) tableHandle;
ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
for (AtopColumn column : atopTableHandle.getTable().getColumns()) {
for (AtopColumn column : atopTableHandle.table().getColumns()) {
columns.add(new ColumnMetadata(column.getName(), typeManager.getType(column.getType())));
}
SchemaTableName schemaTableName = new SchemaTableName(atopTableHandle.getSchema(), atopTableHandle.getTable().getName());
SchemaTableName schemaTableName = new SchemaTableName(atopTableHandle.schema(), atopTableHandle.table().getName());
return new ConnectorTableMetadata(schemaTableName, columns.build());
}

Expand All @@ -121,7 +121,7 @@ public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, Conn
{
AtopTableHandle atopTableHandle = (AtopTableHandle) tableHandle;
ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
for (AtopColumn column : atopTableHandle.getTable().getColumns()) {
for (AtopColumn column : atopTableHandle.table().getColumns()) {
columnHandles.put(column.getName(), new AtopColumnHandle(column.getName()));
}
return columnHandles.buildOrThrow();
Expand Down Expand Up @@ -150,7 +150,7 @@ public ColumnMetadata getColumnMetadata(ConnectorSession session, ConnectorTable
}

AtopTableHandle atopTableHandle = (AtopTableHandle) tableHandle;
SchemaTableName tableName = new SchemaTableName(atopTableHandle.getSchema(), atopTableHandle.getTable().getName());
SchemaTableName tableName = new SchemaTableName(atopTableHandle.schema(), atopTableHandle.table().getName());
throw new ColumnNotFoundException(tableName, columnName);
}

Expand All @@ -161,8 +161,8 @@ public Optional<ConstraintApplicationResult<ConnectorTableHandle>> applyFilter(C

Map<ColumnHandle, Domain> domains = constraint.getSummary().getDomains().orElseThrow(() -> new IllegalArgumentException("constraint summary is NONE"));

Domain oldEndTimeDomain = handle.getEndTimeConstraint();
Domain oldStartTimeDomain = handle.getStartTimeConstraint();
Domain oldEndTimeDomain = handle.endTimeConstraint();
Domain oldStartTimeDomain = handle.startTimeConstraint();
Domain newEndTimeDomain = oldEndTimeDomain;
Domain newStartTimeDomain = oldStartTimeDomain;

Expand All @@ -178,8 +178,8 @@ public Optional<ConstraintApplicationResult<ConnectorTableHandle>> applyFilter(C
}

handle = new AtopTableHandle(
handle.getSchema(),
handle.getTable(),
handle.schema(),
handle.table(),
newStartTimeDomain,
newEndTimeDomain);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ public ConnectorPageSource createPageSource(

for (ColumnHandle column : columns) {
AtopColumnHandle atopColumnHandle = (AtopColumnHandle) column;
AtopColumn atopColumn = tableHandle.getTable().getColumn(atopColumnHandle.name());
AtopColumn atopColumn = tableHandle.table().getColumn(atopColumnHandle.name());
atopColumns.add(atopColumn);
types.add(typeManager.getType(atopColumn.getType()));
}

ZonedDateTime date = atopSplit.getDate();
checkArgument(date.equals(date.withHour(0).withMinute(0).withSecond(0).withNano(0)), "Expected date to be at beginning of day");
return new AtopPageSource(readerPermits, atopFactory, session, utf8Slice(atopSplit.getHost().getHostText()), tableHandle.getTable(), date, atopColumns.build(), types.build());
return new AtopPageSource(readerPermits, atopFactory, session, utf8Slice(atopSplit.getHost().getHostText()), tableHandle.table(), date, atopColumns.build(), types.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public ConnectorSplitSource getSplits(
packDateTimeWithZone(splitEnd.toInstant().toEpochMilli(), UTC_KEY),
true)),
false);
if (tableHandle.getStartTimeConstraint().overlaps(splitDomain) && tableHandle.getEndTimeConstraint().overlaps(splitDomain)) {
if (tableHandle.startTimeConstraint().overlaps(splitDomain) && tableHandle.endTimeConstraint().overlaps(splitDomain)) {
splits.add(new AtopSplit(node.getHostAndPort(), start.toEpochSecond(), start.getZone().getId()));
}
start = start.plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,88 +13,31 @@
*/
package io.trino.plugin.atop;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.trino.spi.connector.ConnectorTableHandle;
import io.trino.spi.predicate.Domain;

import java.util.Objects;

import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS;
import static java.util.Objects.requireNonNull;

public class AtopTableHandle
public record AtopTableHandle(
String schema,
AtopTable table,
Domain startTimeConstraint,
Domain endTimeConstraint)
implements ConnectorTableHandle
{
private final String schema;
private final AtopTable table;
private final Domain startTimeConstraint;
private final Domain endTimeConstraint;

public AtopTableHandle(String schema, AtopTable table)
{
this(schema, table, Domain.all(TIMESTAMP_TZ_MILLIS), Domain.all(TIMESTAMP_TZ_MILLIS));
}

@JsonCreator
public AtopTableHandle(
@JsonProperty("schema") String schema,
@JsonProperty("table") AtopTable table,
@JsonProperty("startTimeConstraint") Domain startTimeConstraint,
@JsonProperty("endTimeConstraint") Domain endTimeConstraint)
{
this.schema = requireNonNull(schema, "schema is null");
this.table = requireNonNull(table, "table is null");
this.startTimeConstraint = requireNonNull(startTimeConstraint, "startTimeConstraint is null");
this.endTimeConstraint = requireNonNull(endTimeConstraint, "endTimeConstraint is null");
}

@JsonProperty
public String getSchema()
{
return schema;
}

@JsonProperty
public AtopTable getTable()
{
return table;
}

@JsonProperty
public Domain getStartTimeConstraint()
public AtopTableHandle
{
return startTimeConstraint;
requireNonNull(schema, "schema is null");
requireNonNull(table, "table is null");
requireNonNull(startTimeConstraint, "startTimeConstraint is null");
requireNonNull(endTimeConstraint, "endTimeConstraint is null");
}

@JsonProperty
public Domain getEndTimeConstraint()
{
return endTimeConstraint;
}

@Override
public int hashCode()
{
return Objects.hash(schema, table, startTimeConstraint, endTimeConstraint);
}

@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
AtopTableHandle other = (AtopTableHandle) obj;
return Objects.equals(this.schema, other.schema) &&
this.table == other.table &&
Objects.equals(startTimeConstraint, other.startTimeConstraint) &&
Objects.equals(endTimeConstraint, other.endTimeConstraint);
}

@Override
public String toString()
{
Expand Down

0 comments on commit 0c4426f

Please sign in to comment.