Search in sources :

Example 1 with TpchColumn

use of io.airlift.tpch.TpchColumn in project presto by prestodb.

the class HiveFileFormatBenchmark method createTpchDataSet.

private static <E extends TpchEntity> TestData createTpchDataSet(FileFormat format, TpchTable<E> tpchTable, List<TpchColumn<E>> columns) {
    List<String> columnNames = columns.stream().map(TpchColumn::getColumnName).collect(toList());
    List<Type> columnTypes = columns.stream().map(HiveFileFormatBenchmark::getColumnType).map(type -> format.supportsDate() || !DATE.equals(type) ? type : createUnboundedVarcharType()).collect(toList());
    PageBuilder pageBuilder = new PageBuilder(columnTypes);
    ImmutableList.Builder<Page> pages = ImmutableList.builder();
    long dataSize = 0;
    for (E row : tpchTable.createGenerator(10, 1, 1)) {
        pageBuilder.declarePosition();
        for (int i = 0; i < columns.size(); i++) {
            TpchColumn<E> column = columns.get(i);
            BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(i);
            switch(column.getType().getBase()) {
                case IDENTIFIER:
                    BIGINT.writeLong(blockBuilder, column.getIdentifier(row));
                    break;
                case INTEGER:
                    INTEGER.writeLong(blockBuilder, column.getInteger(row));
                    break;
                case DATE:
                    if (format.supportsDate()) {
                        DATE.writeLong(blockBuilder, column.getDate(row));
                    } else {
                        createUnboundedVarcharType().writeString(blockBuilder, column.getString(row));
                    }
                    break;
                case DOUBLE:
                    DOUBLE.writeDouble(blockBuilder, column.getDouble(row));
                    break;
                case VARCHAR:
                    createUnboundedVarcharType().writeSlice(blockBuilder, Slices.utf8Slice(column.getString(row)));
                    break;
                default:
                    throw new IllegalArgumentException("Unsupported type " + column.getType());
            }
        }
        if (pageBuilder.isFull()) {
            Page page = pageBuilder.build();
            pages.add(page);
            pageBuilder.reset();
            dataSize += page.getSizeInBytes();
            if (dataSize >= MIN_DATA_SIZE) {
                break;
            }
        }
    }
    return new TestData(columnNames, columnTypes, pages.build());
}
Also used : HdfsEnvironment(com.facebook.presto.hive.HdfsEnvironment) Page(com.facebook.presto.common.Page) VarcharType.createUnboundedVarcharType(com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType) MoreFiles.deleteRecursively(com.google.common.io.MoreFiles.deleteRecursively) RunResult(org.openjdk.jmh.results.RunResult) LINE_ITEM(io.airlift.tpch.TpchTable.LINE_ITEM) Random(java.util.Random) CacheConfig(com.facebook.presto.cache.CacheConfig) Warmup(org.openjdk.jmh.annotations.Warmup) PageBuilder(com.facebook.presto.common.PageBuilder) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit) Files.createTempDirectory(java.nio.file.Files.createTempDirectory) Slices(io.airlift.slice.Slices) HiveCompressionCodec(com.facebook.presto.hive.HiveCompressionCodec) TearDown(org.openjdk.jmh.annotations.TearDown) HiveClientConfig(com.facebook.presto.hive.HiveClientConfig) Setup(org.openjdk.jmh.annotations.Setup) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) Param(org.openjdk.jmh.annotations.Param) Collection(java.util.Collection) UUID(java.util.UUID) String.format(java.lang.String.format) ConnectorSession(com.facebook.presto.spi.ConnectorSession) TpchTable(io.airlift.tpch.TpchTable) UncheckedIOException(java.io.UncheckedIOException) TpchEntity(io.airlift.tpch.TpchEntity) OptionsBuilder(org.openjdk.jmh.runner.options.OptionsBuilder) DataSize(io.airlift.units.DataSize) List(java.util.List) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) HiveSessionProperties(com.facebook.presto.hive.HiveSessionProperties) Options(org.openjdk.jmh.runner.options.Options) TpchColumn(io.airlift.tpch.TpchColumn) Measurement(org.openjdk.jmh.annotations.Measurement) ORDERS(io.airlift.tpch.TpchTable.ORDERS) MEGABYTE(io.airlift.units.DataSize.Unit.MEGABYTE) Scope(org.openjdk.jmh.annotations.Scope) ParquetFileWriterConfig(com.facebook.presto.hive.ParquetFileWriterConfig) OrderColumn(io.airlift.tpch.OrderColumn) DATE(com.facebook.presto.common.type.DateType.DATE) ArrayList(java.util.ArrayList) Statistics(org.openjdk.jmh.util.Statistics) HiveTestUtils.createTestHdfsEnvironment(com.facebook.presto.hive.HiveTestUtils.createTestHdfsEnvironment) AuxCounters(org.openjdk.jmh.annotations.AuxCounters) ALLOW_INSECURE(com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE) ImmutableList(com.google.common.collect.ImmutableList) METASTORE_CLIENT_CONFIG(com.facebook.presto.hive.HiveTestUtils.METASTORE_CLIENT_CONFIG) ArrayType(com.facebook.presto.common.type.ArrayType) HiveTestUtils.mapType(com.facebook.presto.hive.HiveTestUtils.mapType) Runner(org.openjdk.jmh.runner.Runner) Type(com.facebook.presto.common.type.Type) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) OrcFileWriterConfig(com.facebook.presto.hive.OrcFileWriterConfig) HadoopNative(com.facebook.presto.hadoop.HadoopNative) IOException(java.io.IOException) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) State(org.openjdk.jmh.annotations.State) Benchmark(org.openjdk.jmh.annotations.Benchmark) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) Fork(org.openjdk.jmh.annotations.Fork) IntArrays(it.unimi.dsi.fastutil.ints.IntArrays) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) MEGABYTE(io.airlift.units.DataSize.Unit.MEGABYTE) DATE(com.facebook.presto.common.type.DateType.DATE) ALLOW_INSECURE(com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE) ImmutableList(com.google.common.collect.ImmutableList) Page(com.facebook.presto.common.Page) PageBuilder(com.facebook.presto.common.PageBuilder) VarcharType.createUnboundedVarcharType(com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType) ArrayType(com.facebook.presto.common.type.ArrayType) HiveTestUtils.mapType(com.facebook.presto.hive.HiveTestUtils.mapType) Type(com.facebook.presto.common.type.Type) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 2 with TpchColumn

use of io.airlift.tpch.TpchColumn in project presto by prestodb.

the class ThriftTpchService method getTableMetadata.

@Override
public final PrestoThriftNullableTableMetadata getTableMetadata(PrestoThriftSchemaTableName schemaTableName) {
    String schemaName = schemaTableName.getSchemaName();
    String tableName = schemaTableName.getTableName();
    if (!SCHEMAS.contains(schemaName) || TpchTable.getTables().stream().noneMatch(table -> table.getTableName().equals(tableName))) {
        return new PrestoThriftNullableTableMetadata(null);
    }
    TpchTable<?> tpchTable = TpchTable.getTable(schemaTableName.getTableName());
    List<PrestoThriftColumnMetadata> columns = new ArrayList<>();
    for (TpchColumn<? extends TpchEntity> column : tpchTable.getColumns()) {
        columns.add(new PrestoThriftColumnMetadata(column.getSimplifiedColumnName(), getTypeString(column), null, false));
    }
    List<Set<String>> indexableKeys = getIndexableKeys(schemaName, tableName);
    return new PrestoThriftNullableTableMetadata(new PrestoThriftTableMetadata(schemaTableName, columns, null, !indexableKeys.isEmpty() ? indexableKeys : null));
}
Also used : RecordPageSource(com.facebook.presto.spi.RecordPageSource) PrestoThriftNullableSchemaName(com.facebook.presto.thrift.api.connector.PrestoThriftNullableSchemaName) TpchColumn(io.airlift.tpch.TpchColumn) MoreExecutors.listeningDecorator(com.google.common.util.concurrent.MoreExecutors.listeningDecorator) JsonCodec(com.facebook.airlift.json.JsonCodec) Page(com.facebook.presto.common.Page) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) PrestoThriftNullableTableMetadata(com.facebook.presto.thrift.api.connector.PrestoThriftNullableTableMetadata) PrestoThriftNullableColumnSet(com.facebook.presto.thrift.api.connector.PrestoThriftNullableColumnSet) TpchRecordSet.createTpchRecordSet(com.facebook.presto.tpch.TpchRecordSet.createTpchRecordSet) PrestoThriftSplitBatch(com.facebook.presto.thrift.api.connector.PrestoThriftSplitBatch) PrestoThriftPageResult(com.facebook.presto.thrift.api.connector.PrestoThriftPageResult) ArrayList(java.util.ArrayList) PreDestroy(javax.annotation.PreDestroy) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) PrestoThriftSchemaTableName(com.facebook.presto.thrift.api.connector.PrestoThriftSchemaTableName) PrestoThriftBlock(com.facebook.presto.thrift.api.datatypes.PrestoThriftBlock) SplitInfo.normalSplit(com.facebook.presto.connector.thrift.server.SplitInfo.normalSplit) PrestoThriftNullableToken(com.facebook.presto.thrift.api.connector.PrestoThriftNullableToken) PrestoThriftTupleDomain(com.facebook.presto.thrift.api.connector.PrestoThriftTupleDomain) PrestoThriftColumnMetadata(com.facebook.presto.thrift.api.connector.PrestoThriftColumnMetadata) Type(com.facebook.presto.common.type.Type) Nullable(javax.annotation.Nullable) PrestoThriftService(com.facebook.presto.thrift.api.connector.PrestoThriftService) PrestoThriftServiceException(com.facebook.presto.thrift.api.connector.PrestoThriftServiceException) DEFAULT_MAX_PAGE_SIZE_IN_BYTES(com.facebook.presto.common.block.PageBuilderStatus.DEFAULT_MAX_PAGE_SIZE_IN_BYTES) Threads.threadsNamed(com.facebook.airlift.concurrent.Threads.threadsNamed) Set(java.util.Set) PrestoThriftBlock.fromBlock(com.facebook.presto.thrift.api.datatypes.PrestoThriftBlock.fromBlock) Math.min(java.lang.Math.min) PrestoThriftId(com.facebook.presto.thrift.api.connector.PrestoThriftId) JsonCodec.jsonCodec(com.facebook.airlift.json.JsonCodec.jsonCodec) PrestoThriftSplit(com.facebook.presto.thrift.api.connector.PrestoThriftSplit) Ints(com.google.common.primitives.Ints) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) Executors.newFixedThreadPool(java.util.concurrent.Executors.newFixedThreadPool) Preconditions.checkState(com.google.common.base.Preconditions.checkState) TpchTable(io.airlift.tpch.TpchTable) TpchEntity(io.airlift.tpch.TpchEntity) TpchMetadata.getPrestoType(com.facebook.presto.tpch.TpchMetadata.getPrestoType) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) PrestoThriftTableMetadata(com.facebook.presto.thrift.api.connector.PrestoThriftTableMetadata) Closeable(java.io.Closeable) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) PrestoThriftNullableTableMetadata(com.facebook.presto.thrift.api.connector.PrestoThriftNullableTableMetadata) PrestoThriftNullableColumnSet(com.facebook.presto.thrift.api.connector.PrestoThriftNullableColumnSet) TpchRecordSet.createTpchRecordSet(com.facebook.presto.tpch.TpchRecordSet.createTpchRecordSet) Set(java.util.Set) ArrayList(java.util.ArrayList) PrestoThriftColumnMetadata(com.facebook.presto.thrift.api.connector.PrestoThriftColumnMetadata) PrestoThriftTableMetadata(com.facebook.presto.thrift.api.connector.PrestoThriftTableMetadata)

Aggregations

Page (com.facebook.presto.common.Page)2 Type (com.facebook.presto.common.type.Type)2 ConnectorPageSource (com.facebook.presto.spi.ConnectorPageSource)2 ImmutableList (com.google.common.collect.ImmutableList)2 TpchColumn (io.airlift.tpch.TpchColumn)2 TpchEntity (io.airlift.tpch.TpchEntity)2 TpchTable (io.airlift.tpch.TpchTable)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors.toList (java.util.stream.Collectors.toList)2 Threads.threadsNamed (com.facebook.airlift.concurrent.Threads.threadsNamed)1 JsonCodec (com.facebook.airlift.json.JsonCodec)1 JsonCodec.jsonCodec (com.facebook.airlift.json.JsonCodec.jsonCodec)1 CacheConfig (com.facebook.presto.cache.CacheConfig)1 PageBuilder (com.facebook.presto.common.PageBuilder)1 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)1 DEFAULT_MAX_PAGE_SIZE_IN_BYTES (com.facebook.presto.common.block.PageBuilderStatus.DEFAULT_MAX_PAGE_SIZE_IN_BYTES)1 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)1 ArrayType (com.facebook.presto.common.type.ArrayType)1 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)1