Skip to content

Commit

Permalink
Add config property 'tpcds.use-varchar-type'
Browse files Browse the repository at this point in the history
Co-authored-by: Pramod Satya <[email protected]>
  • Loading branch information
2 people authored and Pratik Joseph Dabre committed Jan 21, 2025
1 parent 551b2a9 commit ef3e428
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 15 deletions.
12 changes: 7 additions & 5 deletions presto-docs/src/main/sphinx/connector/tpcds.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ testing.
General Configuration Properties
---------------------------------

+-------------------------------------------------+--------------------------------------------------------------------------+------------------------------+
| Property Name | Description | Default |
================================================== ========================================================================== ==============================
Property Name Description Default
================================================== ========================================================================== ==============================
``tpcds.splits-per-node`` Number of data splits generated per Presto worker node when querying Number of available processors
data from the TPCDS connector.
================================================== ========================================================================== ==============================
| ``tpcds.splits-per-node`` | Number of data splits generated per Presto worker node when querying Number of available processors
data from the TPCDS connector.
-------------------------------------------------- -------------------------------------------------------------------------- ------------------------------
``tpcds.use-varchar-type`` Toggle all char columns to varchar in the TPC-DS connector. false
-------------------------------------------------- -------------------------------------------------------------------------- ------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public ConnectorHandleResolver getHandleResolver()
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
{
int splitsPerNode = getSplitsPerNode(config);
boolean useVarcharType = useVarcharType(config);
NodeManager nodeManager = context.getNodeManager();
return new Connector()
{
Expand All @@ -76,7 +77,7 @@ public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel
@Override
public ConnectorMetadata getMetadata(ConnectorTransactionHandle transactionHandle)
{
return new TpcdsMetadata();
return new TpcdsMetadata(useVarcharType);
}

@Override
Expand Down Expand Up @@ -109,6 +110,16 @@ private int getSplitsPerNode(Map<String, String> properties)
}
}

private boolean useVarcharType(Map<String, String> properties)
{
try {
return parseBoolean(firstNonNull(properties.get("tpcds.use-varchar-type"), String.valueOf(false)));
}
catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid property tpcds.use-varchar-type");
}
}

private boolean isWithNoSexism(Map<String, String> properties)
{
return parseBoolean(firstNonNull(properties.get("tpcds.with-no-sexism"), String.valueOf(false)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,16 @@ public class TpcdsMetadata
private final Set<String> tableNames;
private final TpcdsTableStatisticsFactory tpcdsTableStatisticsFactory = new TpcdsTableStatisticsFactory();

public TpcdsMetadata()
private final boolean useVarcharType;

public TpcdsMetadata(boolean useVarcharType)
{
ImmutableSet.Builder<String> tableNames = ImmutableSet.builder();
for (Table tpcdsTable : Table.getBaseTables()) {
tableNames.add(tpcdsTable.getName().toLowerCase(ENGLISH));
}
this.tableNames = tableNames.build();
this.useVarcharType = useVarcharType;
}

@Override
Expand Down Expand Up @@ -134,14 +137,14 @@ public ConnectorTableMetadata getTableMetadata(ConnectorSession session, Connect
Table table = Table.getTable(tpcdsTableHandle.getTableName());
String schemaName = scaleFactorSchemaName(tpcdsTableHandle.getScaleFactor());

return getTableMetadata(schemaName, table);
return getTableMetadata(schemaName, table, useVarcharType);
}

private static ConnectorTableMetadata getTableMetadata(String schemaName, Table tpcdsTable)
private static ConnectorTableMetadata getTableMetadata(String schemaName, Table tpcdsTable, boolean useVarcharType)
{
ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
for (Column column : tpcdsTable.getColumns()) {
columns.add(new ColumnMetadata(column.getName(), getPrestoType(column.getType())));
columns.add(new ColumnMetadata(column.getName(), getPrestoType(column.getType(), useVarcharType)));
}
SchemaTableName tableName = new SchemaTableName(schemaName, tpcdsTable.getName());
return new ConnectorTableMetadata(tableName, columns.build());
Expand Down Expand Up @@ -189,7 +192,7 @@ public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSess
for (String schemaName : getSchemaNames(session, Optional.ofNullable(prefix.getSchemaName()))) {
for (Table tpcdsTable : Table.getBaseTables()) {
if (prefix.getTableName() == null || tpcdsTable.getName().equals(prefix.getTableName())) {
ConnectorTableMetadata tableMetadata = getTableMetadata(schemaName, tpcdsTable);
ConnectorTableMetadata tableMetadata = getTableMetadata(schemaName, tpcdsTable, useVarcharType);
tableColumns.put(new SchemaTableName(schemaName, tpcdsTable.getName()), tableMetadata.getColumns());
}
}
Expand Down Expand Up @@ -243,7 +246,7 @@ public static double schemaNameToScaleFactor(String schemaName)
}
}

public static Type getPrestoType(ColumnType tpcdsType)
public static Type getPrestoType(ColumnType tpcdsType, boolean useVarcharType)
{
switch (tpcdsType.getBase()) {
case IDENTIFIER:
Expand All @@ -255,6 +258,9 @@ public static Type getPrestoType(ColumnType tpcdsType)
case DECIMAL:
return createDecimalType(tpcdsType.getPrecision().get(), tpcdsType.getScale().get());
case CHAR:
if (useVarcharType) {
return createVarcharType(tpcdsType.getPrecision().get());
}
return createCharType(tpcdsType.getPrecision().get());
case VARCHAR:
return createVarcharType(tpcdsType.getPrecision().get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ public TpcdsRecordSet(Results results, List<Column> columns)
this.columns = ImmutableList.copyOf(columns);
ImmutableList.Builder<Type> columnTypes = ImmutableList.builder();
for (Column column : columns) {
columnTypes.add(getPrestoType(column.getType()));
// The TPCDS config tpcds.use-varchar-type is set to true only for native execution, since char type is
// currently unsupported in Presto native. This function is only used by the Presto java TPCDS connector
// so the argument useVarcharType is false here.
columnTypes.add(getPrestoType(column.getType(), false));
}
this.columnTypes = columnTypes.build();
}
Expand Down Expand Up @@ -103,7 +106,7 @@ public long getReadTimeNanos()
@Override
public Type getType(int field)
{
return getPrestoType(columns.get(field).getType());
return getPrestoType(columns.get(field).getType(), false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class TestTpcdsMetadataStatistics
{
private static final EstimateAssertion estimateAssertion = new EstimateAssertion(0.01);
private static final ConnectorSession session = null;
private final TpcdsMetadata metadata = new TpcdsMetadata();
private final TpcdsMetadata metadata = new TpcdsMetadata(false);

@Test
public void testNoTableStatsForNotSupportedSchema()
Expand Down

0 comments on commit ef3e428

Please sign in to comment.