Skip to content

Commit dba1df3

Browse files
Add validation for schema names in Pinot
1 parent cd65280 commit dba1df3

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

presto-pinot-toolkit/src/main/java/com/facebook/presto/pinot/PinotMetadata.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.facebook.presto.spi.ConnectorTableLayoutResult;
2424
import com.facebook.presto.spi.ConnectorTableMetadata;
2525
import com.facebook.presto.spi.Constraint;
26+
import com.facebook.presto.spi.PrestoException;
2627
import com.facebook.presto.spi.SchemaTableName;
2728
import com.facebook.presto.spi.SchemaTablePrefix;
2829
import com.facebook.presto.spi.TableNotFoundException;
@@ -38,7 +39,9 @@
3839

3940
import static com.facebook.presto.pinot.PinotColumnHandle.PinotColumnType.REGULAR;
4041
import static com.facebook.presto.pinot.PinotErrorCode.PINOT_UNCLASSIFIED_ERROR;
42+
import static com.facebook.presto.spi.StandardErrorCode.NOT_FOUND;
4143
import static com.google.common.base.Preconditions.checkArgument;
44+
import static java.lang.String.format;
4245
import static java.util.Locale.ROOT;
4346
import static java.util.Objects.requireNonNull;
4447

@@ -48,6 +51,7 @@ public class PinotMetadata
4851
private final String connectorId;
4952
private final PinotConnection pinotPrestoConnection;
5053
private final PinotConfig pinotConfig;
54+
private static final String SCHEMA_NAME = "default";
5155

5256
@Inject
5357
public PinotMetadata(ConnectorId connectorId, PinotConnection pinotPrestoConnection, PinotConfig pinotConfig)
@@ -60,7 +64,7 @@ public PinotMetadata(ConnectorId connectorId, PinotConnection pinotPrestoConnect
6064
@Override
6165
public List<String> listSchemaNames(ConnectorSession session)
6266
{
63-
return ImmutableList.of("default");
67+
return ImmutableList.of(SCHEMA_NAME);
6468
}
6569

6670
private String getPinotTableNameFromPrestoTableName(String prestoTableName)
@@ -77,6 +81,9 @@ private String getPinotTableNameFromPrestoTableName(String prestoTableName)
7781
@Override
7882
public PinotTableHandle getTableHandle(ConnectorSession session, SchemaTableName tableName)
7983
{
84+
if (!SCHEMA_NAME.equals(normalizeIdentifier(session, tableName.getSchemaName()))) {
85+
throw new PrestoException(NOT_FOUND, format("Schema %s does not exist", tableName.getSchemaName()));
86+
}
8087
String pinotTableName = getPinotTableNameFromPrestoTableName(tableName.getTableName());
8188
return new PinotTableHandle(connectorId, tableName.getSchemaName(), pinotTableName);
8289
}
@@ -115,7 +122,7 @@ public List<SchemaTableName> listTables(ConnectorSession session, String schemaN
115122
{
116123
ImmutableList.Builder<SchemaTableName> builder = ImmutableList.builder();
117124
for (String table : pinotPrestoConnection.getTableNames()) {
118-
builder.add(new SchemaTableName("default", table));
125+
builder.add(new SchemaTableName(SCHEMA_NAME, table));
119126
}
120127
return builder.build();
121128
}

presto-pinot-toolkit/src/test/java/com/facebook/presto/pinot/TestPinotMetadata.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.util.List;
2323
import java.util.concurrent.Executors;
2424

25+
import static com.facebook.presto.pinot.TestPinotQueryBase.realtimeOnlyTable;
26+
import static com.facebook.presto.pinot.TestPinotSplitManager.createSessionWithNumSplits;
2527
import static org.testng.Assert.assertEquals;
2628

2729
public class TestPinotMetadata
@@ -33,14 +35,14 @@ public class TestPinotMetadata
3335
@Test
3436
public void testTables()
3537
{
36-
ConnectorSession session = TestPinotSplitManager.createSessionWithNumSplits(1, false, pinotConfig);
38+
ConnectorSession session = createSessionWithNumSplits(1, false, pinotConfig);
3739
List<SchemaTableName> schemaTableNames = metadata.listTables(session, (String) null);
38-
assertEquals(ImmutableSet.copyOf(schemaTableNames), ImmutableSet.of(new SchemaTableName("default", TestPinotSplitManager.realtimeOnlyTable.getTableName()), new SchemaTableName("default", TestPinotSplitManager.hybridTable.getTableName())));
40+
assertEquals(ImmutableSet.copyOf(schemaTableNames), ImmutableSet.of(new SchemaTableName("default", realtimeOnlyTable.getTableName()), new SchemaTableName("default", TestPinotSplitManager.hybridTable.getTableName())));
3941
List<String> schemas = metadata.listSchemaNames(session);
4042
assertEquals(ImmutableList.copyOf(schemas), ImmutableList.of("default"));
41-
PinotTableHandle withWeirdSchema = metadata.getTableHandle(session, new SchemaTableName("foo", TestPinotSplitManager.realtimeOnlyTable.getTableName()));
42-
assertEquals(withWeirdSchema.getTableName(), TestPinotSplitManager.realtimeOnlyTable.getTableName());
43-
PinotTableHandle withAnotherSchema = metadata.getTableHandle(session, new SchemaTableName(TestPinotSplitManager.realtimeOnlyTable.getTableName(), TestPinotSplitManager.realtimeOnlyTable.getTableName()));
44-
assertEquals(withAnotherSchema.getTableName(), TestPinotSplitManager.realtimeOnlyTable.getTableName());
43+
PinotTableHandle withWeirdSchema = metadata.getTableHandle(session, new SchemaTableName("foo", realtimeOnlyTable.getTableName()));
44+
assertEquals(withWeirdSchema.getTableName(), realtimeOnlyTable.getTableName());
45+
PinotTableHandle withAnotherSchema = metadata.getTableHandle(session, new SchemaTableName(realtimeOnlyTable.getTableName(), realtimeOnlyTable.getTableName()));
46+
assertEquals(withAnotherSchema.getTableName(), realtimeOnlyTable.getTableName());
4547
}
4648
}

0 commit comments

Comments
 (0)