Skip to content

Commit

Permalink
Check table existence in Pinot connector
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Aug 13, 2021
1 parent 3ec5790 commit 2663e49
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.airlift.log.Logger;
import io.trino.plugin.pinot.client.PinotClient;
import io.trino.plugin.pinot.query.AggregationExpression;
import io.trino.plugin.pinot.query.DynamicTable;
Expand Down Expand Up @@ -67,6 +68,8 @@
public class PinotMetadata
implements ConnectorMetadata
{
private static final Logger log = Logger.get(PinotMetadata.class);

private static final Object ALL_TABLES_CACHE_KEY = new Object();
private static final String SCHEMA_NAME = "default";
private static final String PINOT_COLUMN_NAME_PROPERTY = "pinotColumnName";
Expand Down Expand Up @@ -115,7 +118,15 @@ public PinotTableHandle getTableHandle(ConnectorSession session, SchemaTableName
DynamicTable dynamicTable = DynamicTableBuilder.buildFromPql(this, tableName);
return new PinotTableHandle(tableName.getSchemaName(), dynamicTable.getTableName(), TupleDomain.all(), OptionalLong.empty(), Optional.of(dynamicTable));
}
return new PinotTableHandle(tableName.getSchemaName(), tableName.getTableName());

try {
String pinotTableName = getPinotTableNameFromTrinoTableName(tableName.getTableName());
return new PinotTableHandle(tableName.getSchemaName(), pinotTableName);
}
catch (TableNotFoundException e) {
log.debug(e, "Table not found: %s", tableName);
return null;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,4 +796,20 @@ public void testLimitPushdown()
assertThat(query("SELECT string_col, long_col FROM " + ALL_TYPES_TABLE + " WHERE int_col >0 AND bool_col = 'false' LIMIT " + MAX_ROWS_PER_SPLIT_FOR_SEGMENT_QUERIES))
.isNotFullyPushedDown(LimitNode.class);
}

@Test
public void testCreateTable()
{
assertQueryFails("CREATE TABLE test_create_table (col INT)", "This connector does not support creating tables");
}

/**
* https://github.com/trinodb/trino/issues/8307
*/
@Test
public void testInformationSchemaColumnsTableNotExist()
{
assertThat(query("SELECT * FROM pinot.information_schema.columns WHERE table_name = 'table_not_exist'"))
.returnsEmptyResult();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@ public void testTables()
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());
PinotTableHandle withUppercaseTable = metadata.getTableHandle(session, new SchemaTableName("default", TEST_TABLE));
assertEquals(withUppercaseTable.getTableName(), "airlinestats");
}
}

0 comments on commit 2663e49

Please sign in to comment.