Skip to content
Open
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 @@ -23,6 +23,7 @@
import com.facebook.presto.spi.ConnectorTableLayoutResult;
import com.facebook.presto.spi.ConnectorTableMetadata;
import com.facebook.presto.spi.Constraint;
import com.facebook.presto.spi.PrestoException;
import com.facebook.presto.spi.SchemaTableName;
import com.facebook.presto.spi.SchemaTablePrefix;
import com.facebook.presto.spi.TableNotFoundException;
Expand All @@ -38,7 +39,9 @@

import static com.facebook.presto.pinot.PinotColumnHandle.PinotColumnType.REGULAR;
import static com.facebook.presto.pinot.PinotErrorCode.PINOT_UNCLASSIFIED_ERROR;
import static com.facebook.presto.spi.StandardErrorCode.NOT_FOUND;
import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
import static java.util.Locale.ROOT;
import static java.util.Objects.requireNonNull;

Expand All @@ -48,6 +51,7 @@ public class PinotMetadata
private final String connectorId;
private final PinotConnection pinotPrestoConnection;
private final PinotConfig pinotConfig;
private static final String SCHEMA_NAME = "default";

@Inject
public PinotMetadata(ConnectorId connectorId, PinotConnection pinotPrestoConnection, PinotConfig pinotConfig)
Expand All @@ -60,7 +64,7 @@ public PinotMetadata(ConnectorId connectorId, PinotConnection pinotPrestoConnect
@Override
public List<String> listSchemaNames(ConnectorSession session)
{
return ImmutableList.of("default");
return ImmutableList.of(SCHEMA_NAME);
}

private String getPinotTableNameFromPrestoTableName(String prestoTableName)
Expand All @@ -77,6 +81,9 @@ private String getPinotTableNameFromPrestoTableName(String prestoTableName)
@Override
public PinotTableHandle getTableHandle(ConnectorSession session, SchemaTableName tableName)
{
if (!SCHEMA_NAME.equals(normalizeIdentifier(session, tableName.getSchemaName()))) {
throw new PrestoException(NOT_FOUND, format("Schema %s does not exist", tableName.getSchemaName()));
}
String pinotTableName = getPinotTableNameFromPrestoTableName(tableName.getTableName());
return new PinotTableHandle(connectorId, tableName.getSchemaName(), pinotTableName);
}
Expand Down Expand Up @@ -115,7 +122,7 @@ public List<SchemaTableName> listTables(ConnectorSession session, String schemaN
{
ImmutableList.Builder<SchemaTableName> builder = ImmutableList.builder();
for (String table : pinotPrestoConnection.getTableNames()) {
builder.add(new SchemaTableName("default", table));
builder.add(new SchemaTableName(SCHEMA_NAME, table));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): listTables ignores schemaNameOrNull, which can be inconsistent with the stricter schema check in getTableHandle.

Since getTableHandle now enforces SCHEMA_NAME, listTables should probably also honor schemaNameOrNull. If schemaNameOrNull is non-null and its normalized value differs from SCHEMA_NAME, consider returning an empty list rather than listing tables from the default schema, to keep discovery consistent with getTableHandle’s access rules.

}
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package com.facebook.presto.pinot;

import com.facebook.presto.spi.ConnectorSession;
import com.facebook.presto.spi.PrestoException;
import com.facebook.presto.spi.SchemaTableName;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
Expand All @@ -22,7 +23,10 @@
import java.util.List;
import java.util.concurrent.Executors;

import static com.facebook.presto.pinot.TestPinotQueryBase.realtimeOnlyTable;
import static com.facebook.presto.pinot.TestPinotSplitManager.createSessionWithNumSplits;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertThrows;

public class TestPinotMetadata
{
Expand All @@ -33,14 +37,14 @@ public class TestPinotMetadata
@Test
public void testTables()
{
ConnectorSession session = TestPinotSplitManager.createSessionWithNumSplits(1, false, pinotConfig);
ConnectorSession session = createSessionWithNumSplits(1, false, pinotConfig);
List<SchemaTableName> schemaTableNames = metadata.listTables(session, (String) null);
assertEquals(ImmutableSet.copyOf(schemaTableNames), ImmutableSet.of(new SchemaTableName("default", TestPinotSplitManager.realtimeOnlyTable.getTableName()), new SchemaTableName("default", TestPinotSplitManager.hybridTable.getTableName())));
assertEquals(ImmutableSet.copyOf(schemaTableNames), ImmutableSet.of(new SchemaTableName("default", realtimeOnlyTable.getTableName()), new SchemaTableName("default", TestPinotSplitManager.hybridTable.getTableName())));
List<String> schemas = metadata.listSchemaNames(session);
assertEquals(ImmutableList.copyOf(schemas), ImmutableList.of("default"));
PinotTableHandle withWeirdSchema = metadata.getTableHandle(session, new SchemaTableName("foo", TestPinotSplitManager.realtimeOnlyTable.getTableName()));
assertEquals(withWeirdSchema.getTableName(), TestPinotSplitManager.realtimeOnlyTable.getTableName());
PinotTableHandle withAnotherSchema = metadata.getTableHandle(session, new SchemaTableName(TestPinotSplitManager.realtimeOnlyTable.getTableName(), TestPinotSplitManager.realtimeOnlyTable.getTableName()));
assertEquals(withAnotherSchema.getTableName(), TestPinotSplitManager.realtimeOnlyTable.getTableName());
assertThrows(PrestoException.class, () -> metadata.getTableHandle(session,
new SchemaTableName("foo", realtimeOnlyTable.getTableName())));
assertThrows(PrestoException.class, () -> metadata.getTableHandle(session,
new SchemaTableName(realtimeOnlyTable.getTableName(), realtimeOnlyTable.getTableName())));
}
}
Loading