Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public PrometheusTableHandle getTableHandle(ConnectorSession session, SchemaTabl
return null;
}

return new PrometheusTableHandle(tableName.getSchemaName(), tableName.getTableName());
return new PrometheusTableHandle(tableName.getSchemaName(), tableName.getTableName(), Optional.empty());
}

@Override
Expand All @@ -108,7 +108,7 @@ public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, Conn
{
PrometheusTableHandle prometheusTableHandle = (PrometheusTableHandle) tableHandle;

PrometheusTable table = prometheusClient.getTable(prometheusTableHandle.getSchemaName(), prometheusTableHandle.getTableName());
PrometheusTable table = prometheusClient.getTable(prometheusTableHandle.schemaName(), prometheusTableHandle.tableName());
if (table == null) {
throw new TableNotFoundException(prometheusTableHandle.toSchemaTableName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public ConnectorSplitSource getSplits(
Constraint constraint)
{
PrometheusTableHandle tableHandle = (PrometheusTableHandle) connectorTableHandle;
PrometheusTable table = prometheusClient.getTable(tableHandle.getSchemaName(), tableHandle.getTableName());
PrometheusTable table = prometheusClient.getTable(tableHandle.schemaName(), tableHandle.tableName());

// this can happen if table is removed during a query
if (table == null) {
Expand Down Expand Up @@ -129,7 +129,7 @@ private static URI buildQuery(URI baseURI, String time, String metricName, Durat
protected static List<String> generateTimesForSplits(Instant defaultUpperBound, Duration maxQueryRangeDurationRequested, Duration queryChunkSizeDurationRequested,
PrometheusTableHandle tableHandle)
{
Optional<PrometheusPredicateTimeInfo> predicateRange = tableHandle.getPredicate()
Optional<PrometheusPredicateTimeInfo> predicateRange = tableHandle.predicate()
.flatMap(PrometheusSplitManager::determinePredicateTimes);

EffectiveLimits effectiveLimits = new EffectiveLimits(defaultUpperBound, maxQueryRangeDurationRequested, predicateRange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*/
package io.trino.plugin.prometheus;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.trino.spi.connector.ColumnHandle;
import io.trino.spi.connector.ConnectorTableHandle;
import io.trino.spi.connector.SchemaTableName;
Expand All @@ -25,43 +23,14 @@

import static java.util.Objects.requireNonNull;

public final class PrometheusTableHandle
public record PrometheusTableHandle(String schemaName, String tableName, Optional<TupleDomain<ColumnHandle>> predicate)
implements ConnectorTableHandle
{
private final String schemaName;
private final String tableName;
private final Optional<TupleDomain<ColumnHandle>> predicate;

@JsonCreator
public PrometheusTableHandle(
@JsonProperty("schemaName") String schemaName,
@JsonProperty("tableName") String tableName)
{
this(schemaName, tableName, Optional.empty());
}

private PrometheusTableHandle(String schemaName, String tableName, Optional<TupleDomain<ColumnHandle>> predicate)
{
this.schemaName = requireNonNull(schemaName, "schemaName is null");
this.tableName = requireNonNull(tableName, "tableName is null");
this.predicate = requireNonNull(predicate, "predicate is null");
}

@JsonProperty
public String getSchemaName()
{
return schemaName;
}

@JsonProperty
public String getTableName()
{
return tableName;
}

public Optional<TupleDomain<ColumnHandle>> getPredicate()
public PrometheusTableHandle
{
return this.predicate;
requireNonNull(schemaName, "schemaName is null");
requireNonNull(tableName, "tableName is null");
requireNonNull(predicate, "predicate is null");
}

public SchemaTableName toSchemaTableName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.concurrent.TimeUnit;

import static io.trino.plugin.prometheus.PrometheusQueryRunner.createPrometheusClient;
import static io.trino.plugin.prometheus.TestPrometheusTableHandle.newTableHandle;
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -122,7 +123,7 @@ public void testCorrectNumberOfSplitsCreated()
ConnectorSplitSource splits = splitManager.getSplits(
null,
null,
new PrometheusTableHandle("default", table.name()),
newTableHandle("default", table.name()),
(DynamicFilter) null,
Constraint.alwaysTrue());
int numSplits = splits.getNextBatch(NUMBER_MORE_THAN_EXPECTED_NUMBER_SPLITS).getNow(null).getSplits().size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static io.trino.plugin.prometheus.MetadataUtil.varcharMapType;
import static io.trino.plugin.prometheus.PrometheusClient.TIMESTAMP_COLUMN_TYPE;
import static io.trino.plugin.prometheus.PrometheusRecordCursor.getMapFromSqlMap;
import static io.trino.plugin.prometheus.TestPrometheusTableHandle.newTableHandle;
import static io.trino.testing.TestingConnectorSession.SESSION;
import static io.trino.type.InternalTypeManager.TESTING_TYPE_MANAGER;
import static java.time.Instant.ofEpochMilli;
Expand All @@ -57,7 +58,7 @@ public void tearDown()
@Test
public void testGetRecordSet()
{
ConnectorTableHandle tableHandle = new PrometheusTableHandle("schema", "table");
ConnectorTableHandle tableHandle = newTableHandle("schema", "table");
PrometheusRecordSetProvider recordSetProvider = new PrometheusRecordSetProvider(client);
RecordSet recordSet = recordSetProvider.getRecordSet(PrometheusTransactionHandle.INSTANCE, SESSION,
new PrometheusSplit(dataUri), tableHandle, ImmutableList.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import static io.trino.plugin.prometheus.PrometheusClock.fixedClockAt;
import static io.trino.plugin.prometheus.PrometheusSplitManager.OFFSET_MILLIS;
import static io.trino.plugin.prometheus.PrometheusSplitManager.decimalSecondString;
import static io.trino.plugin.prometheus.TestPrometheusTableHandle.newTableHandle;
import static io.trino.spi.type.DateTimeEncoding.packDateTimeWithZone;
import static io.trino.spi.type.TimeZoneKey.UTC_KEY;
import static io.trino.type.InternalTypeManager.TESTING_TYPE_MANAGER;
Expand Down Expand Up @@ -126,7 +127,7 @@ public void testQueryWithTableNameNeedingURLEncodeInSplits()
ConnectorSplitSource splits = splitManager.getSplits(
null,
null,
new PrometheusTableHandle("default", table.name()),
newTableHandle("default", table.name()),
(DynamicFilter) null,
Constraint.alwaysTrue());
PrometheusSplit split = (PrometheusSplit) splits.getNextBatch(1).getNow(null).getSplits().get(0);
Expand All @@ -150,7 +151,7 @@ public void testQueryDividedIntoSplitsFirstSplitHasRightTime()
ConnectorSplitSource splits = splitManager.getSplits(
null,
null,
new PrometheusTableHandle("default", table.name()),
newTableHandle("default", table.name()),
(DynamicFilter) null,
Constraint.alwaysTrue());
PrometheusSplit split = (PrometheusSplit) splits.getNextBatch(1).getNow(null).getSplits().get(0);
Expand All @@ -174,7 +175,7 @@ public void testQueryDividedIntoSplitsLastSplitHasRightTime()
ConnectorSplitSource splitsMaybe = splitManager.getSplits(
null,
null,
new PrometheusTableHandle("default", table.name()),
newTableHandle("default", table.name()),
(DynamicFilter) null,
Constraint.alwaysTrue());
List<ConnectorSplit> splits = splitsMaybe.getNextBatch(NUMBER_MORE_THAN_EXPECTED_NUMBER_SPLITS).getNow(null).getSplits();
Expand All @@ -199,7 +200,7 @@ public void testQueryDividedIntoSplitsShouldHaveCorrectSpacingBetweenTimes()
ConnectorSplitSource splits = splitManager.getSplits(
null,
null,
new PrometheusTableHandle("default", table.name()),
newTableHandle("default", table.name()),
(DynamicFilter) null,
Constraint.alwaysTrue());
PrometheusSplit split1 = (PrometheusSplit) splits.getNextBatch(1).getNow(null).getSplits().get(0);
Expand All @@ -219,7 +220,7 @@ public void testSplitTimesCorrect()
io.airlift.units.Duration queryChunkSizeDuration = new io.airlift.units.Duration(1, TimeUnit.DAYS);
Instant now = ofEpochMilli(1000000000L);

PrometheusTableHandle prometheusTableHandle = new PrometheusTableHandle("schemaName", "tableName");
PrometheusTableHandle prometheusTableHandle = newTableHandle("schemaName", "tableName");
List<String> splitTimes = PrometheusSplitManager.generateTimesForSplits(
now,
maxQueryRangeDuration, queryChunkSizeDuration, prometheusTableHandle);
Expand All @@ -235,7 +236,7 @@ public void testSplitTimesCorrectNonModuloZeroDurationToChunk()
io.airlift.units.Duration queryChunkSizeDuration = new io.airlift.units.Duration(2, TimeUnit.DAYS);
Instant now = ofEpochMilli(1000000000L);

PrometheusTableHandle prometheusTableHandle = new PrometheusTableHandle("schemaName", "tableName");
PrometheusTableHandle prometheusTableHandle = newTableHandle("schemaName", "tableName");
List<String> splitTimes = PrometheusSplitManager.generateTimesForSplits(now, maxQueryRangeDuration, queryChunkSizeDuration, prometheusTableHandle);
List<String> expectedSplitTimes = ImmutableList.of(
"827199.999", "1000000");
Expand All @@ -249,7 +250,7 @@ public void testSplitTimesCorrectVersusMock()
io.airlift.units.Duration queryChunkSizeDuration = new io.airlift.units.Duration(30, TimeUnit.SECONDS);
Instant now = ofEpochMilli(1568638172000L);

PrometheusTableHandle prometheusTableHandle = new PrometheusTableHandle("schemaName", "tableName");
PrometheusTableHandle prometheusTableHandle = newTableHandle("schemaName", "tableName");
List<String> splitTimes = PrometheusSplitManager.generateTimesForSplits(now, maxQueryRangeDuration, queryChunkSizeDuration, prometheusTableHandle);
List<String> promTimesReturned = mockPrometheusResponseToChunkedQueries(queryChunkSizeDuration, splitTimes);
assertThat(promTimesReturned).isEqualTo(convertMockTimesToStrings(promTimeValuesMock));
Expand All @@ -262,7 +263,7 @@ public void testSplitTimesAreTimesNearBoundaryNotMissing()
io.airlift.units.Duration queryChunkSizeDuration = new io.airlift.units.Duration(30, TimeUnit.SECONDS);
Instant now = ofEpochMilli(1568638171999L);

PrometheusTableHandle prometheusTableHandle = new PrometheusTableHandle("schemaName", "tableName");
PrometheusTableHandle prometheusTableHandle = newTableHandle("schemaName", "tableName");
List<String> splitTimes = PrometheusSplitManager.generateTimesForSplits(now, maxQueryRangeDuration, queryChunkSizeDuration, prometheusTableHandle);
List<String> promTimesReturned = mockPrometheusResponseToChunkedQueries(queryChunkSizeDuration, splitTimes);
assertThat(promTimesReturned).isEqualTo(convertMockTimesToStrings(promTimeValuesMock));
Expand Down Expand Up @@ -320,7 +321,7 @@ public void testPredicatePushDownSetsLowerBoundOnly()
Domain testDomain = Domain.create(valueSet, false);
TupleDomain<ColumnHandle> testTupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of(
new PrometheusColumnHandle("timestamp", TIMESTAMP_COLUMN_TYPE, 2), testDomain));
PrometheusTableHandle prometheusTableHandle = new PrometheusTableHandle("schemaName", "tableName")
PrometheusTableHandle prometheusTableHandle = newTableHandle("schemaName", "tableName")
.withPredicate(testTupleDomain);
io.airlift.units.Duration maxQueryRangeDuration = new io.airlift.units.Duration(120, TimeUnit.SECONDS);
io.airlift.units.Duration queryChunkSizeDuration = new io.airlift.units.Duration(30, TimeUnit.SECONDS);
Expand All @@ -347,7 +348,7 @@ public void testPredicatePushDownSetsUpperBoundOnly()
Domain testDomain = Domain.create(valueSet, false);
TupleDomain<ColumnHandle> testTupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of(
new PrometheusColumnHandle("timestamp", TIMESTAMP_COLUMN_TYPE, 2), testDomain));
PrometheusTableHandle prometheusTableHandle = new PrometheusTableHandle("schemaName", "tableName")
PrometheusTableHandle prometheusTableHandle = newTableHandle("schemaName", "tableName")
.withPredicate(testTupleDomain);
io.airlift.units.Duration maxQueryRangeDuration = new io.airlift.units.Duration(120, TimeUnit.SECONDS);
io.airlift.units.Duration queryChunkSizeDuration = new io.airlift.units.Duration(30, TimeUnit.SECONDS);
Expand Down Expand Up @@ -381,7 +382,7 @@ public void testPredicatePushDownSetsUpperAndLowerBound()
Domain testDomain = Domain.create(valueSet, false);
TupleDomain<ColumnHandle> testTupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of(
new PrometheusColumnHandle("timestamp", TIMESTAMP_COLUMN_TYPE, 2), testDomain));
PrometheusTableHandle prometheusTableHandle = new PrometheusTableHandle("schemaName", "tableName")
PrometheusTableHandle prometheusTableHandle = newTableHandle("schemaName", "tableName")
.withPredicate(testTupleDomain);
io.airlift.units.Duration maxQueryRangeDuration = new io.airlift.units.Duration(120, TimeUnit.SECONDS);
io.airlift.units.Duration queryChunkSizeDuration = new io.airlift.units.Duration(30, TimeUnit.SECONDS);
Expand All @@ -407,7 +408,7 @@ public void testPredicatePushDownSetsUpperAndLowerBound()
public void testEmptyPredicatePredicatePushDown()
{
long predicateLowValue = 1570460709643L;
PrometheusTableHandle prometheusTableHandle = new PrometheusTableHandle("schemaName", "tableName");
PrometheusTableHandle prometheusTableHandle = newTableHandle("schemaName", "tableName");
io.airlift.units.Duration maxQueryRangeDuration = new io.airlift.units.Duration(120, TimeUnit.SECONDS);
io.airlift.units.Duration queryChunkSizeDuration = new io.airlift.units.Duration(30, TimeUnit.SECONDS);
Instant now = ofEpochMilli(1568638171999L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
import io.airlift.testing.EquivalenceTester;
import org.junit.jupiter.api.Test;

import java.util.Optional;

import static io.airlift.json.JsonCodec.jsonCodec;
import static org.assertj.core.api.Assertions.assertThat;

public class TestPrometheusTableHandle
{
private final PrometheusTableHandle tableHandle = new PrometheusTableHandle("schemaName", "tableName");
private final PrometheusTableHandle tableHandle = newTableHandle("schemaName", "tableName");

@Test
public void testJsonRoundTrip()
Expand All @@ -37,9 +39,14 @@ public void testJsonRoundTrip()
public void testEquivalence()
{
EquivalenceTester.equivalenceTester()
.addEquivalentGroup(new PrometheusTableHandle("schema", "table"), new PrometheusTableHandle("schema", "table"))
.addEquivalentGroup(new PrometheusTableHandle("schemaX", "table"), new PrometheusTableHandle("schemaX", "table"))
.addEquivalentGroup(new PrometheusTableHandle("schema", "tableX"), new PrometheusTableHandle("schema", "tableX"))
.addEquivalentGroup(newTableHandle("schema", "table"), newTableHandle("schema", "table"))
.addEquivalentGroup(newTableHandle("schemaX", "table"), newTableHandle("schemaX", "table"))
.addEquivalentGroup(newTableHandle("schema", "tableX"), newTableHandle("schema", "tableX"))
.check();
}

public static PrometheusTableHandle newTableHandle(String schemaName, String tableName)
{
return new PrometheusTableHandle(schemaName, tableName, Optional.empty());
}
}