Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a config flag tpcds.use-varchar-type in Presto - Java TPC-DS Connector #24406

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions presto-docs/src/main/sphinx/connector/tpcds.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ Property Name Description
================================================== ========================================================================== ==============================
``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
Loading