Search in sources :

Example 26 with OptionalInt

use of java.util.OptionalInt in project presto by prestodb.

the class HivePageSinkProvider method createPageSink.

private ConnectorPageSink createPageSink(HiveWritableTableHandle handle, boolean isCreateTable, ConnectorSession session) {
    OptionalInt bucketCount = handle.getBucketProperty().isPresent() ? OptionalInt.of(handle.getBucketProperty().get().getBucketCount()) : OptionalInt.empty();
    HiveWriterFactory writerFactory = new HiveWriterFactory(fileWriterFactories, handle.getSchemaName(), handle.getTableName(), isCreateTable, handle.getInputColumns(), handle.getTableStorageFormat(), handle.getPartitionStorageFormat(), bucketCount, handle.getLocationHandle(), locationService, handle.getFilePrefix(), new HivePageSinkMetadataProvider(handle.getPageSinkMetadata(), metastore), typeManager, hdfsEnvironment, immutablePartitions, session);
    return new HivePageSink(writerFactory, handle.getInputColumns(), handle.getBucketProperty(), pageIndexerFactory, typeManager, hdfsEnvironment, maxOpenPartitions, writeVerificationExecutor, partitionUpdateCodec, session);
}
Also used : HivePageSinkMetadataProvider(com.facebook.presto.hive.metastore.HivePageSinkMetadataProvider) OptionalInt(java.util.OptionalInt)

Example 27 with OptionalInt

use of java.util.OptionalInt in project presto by prestodb.

the class HivePageSourceProvider method createHivePageSource.

public static Optional<ConnectorPageSource> createHivePageSource(Set<HiveRecordCursorProvider> cursorProviders, Set<HivePageSourceFactory> pageSourceFactories, String clientId, Configuration configuration, ConnectorSession session, Path path, OptionalInt bucketNumber, long start, long length, Properties schema, TupleDomain<HiveColumnHandle> effectivePredicate, List<HiveColumnHandle> hiveColumns, List<HivePartitionKey> partitionKeys, DateTimeZone hiveStorageTimeZone, TypeManager typeManager, Map<Integer, HiveType> columnCoercions) {
    List<ColumnMapping> columnMappings = ColumnMapping.buildColumnMappings(partitionKeys, hiveColumns, columnCoercions, path, bucketNumber);
    List<ColumnMapping> regularColumnMappings = ColumnMapping.extractRegularColumnMappings(columnMappings);
    for (HivePageSourceFactory pageSourceFactory : pageSourceFactories) {
        Optional<? extends ConnectorPageSource> pageSource = pageSourceFactory.createPageSource(configuration, session, path, start, length, schema, extractRegularColumnHandles(regularColumnMappings, true), effectivePredicate, hiveStorageTimeZone);
        if (pageSource.isPresent()) {
            return Optional.of(new HivePageSource(columnMappings, hiveStorageTimeZone, typeManager, pageSource.get()));
        }
    }
    for (HiveRecordCursorProvider provider : cursorProviders) {
        // GenericHiveRecordCursor will automatically do the coercion without HiveCoercionRecordCursor
        boolean doCoercion = !(provider instanceof GenericHiveRecordCursorProvider);
        Optional<RecordCursor> cursor = provider.createRecordCursor(clientId, configuration, session, path, start, length, schema, extractRegularColumnHandles(regularColumnMappings, doCoercion), effectivePredicate, hiveStorageTimeZone, typeManager);
        if (cursor.isPresent()) {
            RecordCursor delegate = cursor.get();
            // Need to wrap RcText and RcBinary into a wrapper, which will do the coercion for mismatch columns
            if (doCoercion) {
                delegate = new HiveCoercionRecordCursor(regularColumnMappings, typeManager, delegate);
            }
            HiveRecordCursor hiveRecordCursor = new HiveRecordCursor(columnMappings, hiveStorageTimeZone, typeManager, delegate);
            List<Type> columnTypes = hiveColumns.stream().map(input -> typeManager.getType(input.getTypeSignature())).collect(toList());
            return Optional.of(new RecordPageSource(columnTypes, hiveRecordCursor));
        }
    }
    return Optional.empty();
}
Also used : RecordPageSource(com.facebook.presto.spi.RecordPageSource) DateTimeZone(org.joda.time.DateTimeZone) TypeManager(com.facebook.presto.spi.type.TypeManager) REGULAR(com.facebook.presto.hive.HiveColumnHandle.ColumnType.REGULAR) Maps.uniqueIndex(com.google.common.collect.Maps.uniqueIndex) OptionalInt(java.util.OptionalInt) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) Inject(javax.inject.Inject) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) Type(com.facebook.presto.spi.type.Type) Configuration(org.apache.hadoop.conf.Configuration) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Path(org.apache.hadoop.fs.Path) ConnectorPageSourceProvider(com.facebook.presto.spi.connector.ConnectorPageSourceProvider) ColumnMapping.extractRegularColumnHandles(com.facebook.presto.hive.HivePageSourceProvider.ColumnMapping.extractRegularColumnHandles) ImmutableSet(com.google.common.collect.ImmutableSet) Properties(java.util.Properties) HiveUtil.getPrefilledColumnValue(com.facebook.presto.hive.HiveUtil.getPrefilledColumnValue) Set(java.util.Set) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ConnectorSession(com.facebook.presto.spi.ConnectorSession) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) RecordCursor(com.facebook.presto.spi.RecordCursor) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) ColumnHandle(com.facebook.presto.spi.ColumnHandle) Optional(java.util.Optional) RecordCursor(com.facebook.presto.spi.RecordCursor) RecordPageSource(com.facebook.presto.spi.RecordPageSource) Type(com.facebook.presto.spi.type.Type)

Example 28 with OptionalInt

use of java.util.OptionalInt in project presto by prestodb.

the class ShardIterator method compute.

/**
     * Compute split-per-shard (separate split for each shard).
     */
private BucketShards compute() throws SQLException {
    if (!resultSet.next()) {
        return endOfData();
    }
    UUID shardUuid = uuidFromBytes(resultSet.getBytes("shard_uuid"));
    Set<String> nodeIdentifiers;
    OptionalInt bucketNumber = OptionalInt.empty();
    if (bucketToNode != null) {
        int bucket = resultSet.getInt("bucket_number");
        bucketNumber = OptionalInt.of(bucket);
        nodeIdentifiers = ImmutableSet.of(getBucketNode(bucket));
    } else {
        List<Integer> nodeIds = intArrayFromBytes(resultSet.getBytes("node_ids"));
        nodeIdentifiers = getNodeIdentifiers(nodeIds, shardUuid);
    }
    ShardNodes shard = new ShardNodes(shardUuid, nodeIdentifiers);
    return new BucketShards(bucketNumber, ImmutableSet.of(shard));
}
Also used : OptionalInt(java.util.OptionalInt) UUID(java.util.UUID)

Example 29 with OptionalInt

use of java.util.OptionalInt in project presto by prestodb.

the class TableMetadataSystemTable method buildPages.

private static List<Page> buildPages(MetadataDao dao, ConnectorTableMetadata tableMetadata, TupleDomain<Integer> tupleDomain) {
    Map<Integer, NullableValue> domainValues = extractFixedValues(tupleDomain).orElse(ImmutableMap.of());
    String schemaName = getStringValue(domainValues.get(getColumnIndex(tableMetadata, SCHEMA_NAME)));
    String tableName = getStringValue(domainValues.get(getColumnIndex(tableMetadata, TABLE_NAME)));
    PageListBuilder pageBuilder = new PageListBuilder(tableMetadata.getColumns().stream().map(ColumnMetadata::getType).collect(toList()));
    List<TableMetadataRow> tableRows = dao.getTableMetadataRows(schemaName, tableName);
    PeekingIterator<ColumnMetadataRow> columnRowIterator = peekingIterator(dao.getColumnMetadataRows(schemaName, tableName).iterator());
    for (TableMetadataRow tableRow : tableRows) {
        while (columnRowIterator.hasNext() && columnRowIterator.peek().getTableId() < tableRow.getTableId()) {
            columnRowIterator.next();
        }
        String temporalColumnName = null;
        SortedMap<Integer, String> sortColumnNames = new TreeMap<>();
        SortedMap<Integer, String> bucketColumnNames = new TreeMap<>();
        OptionalLong temporalColumnId = tableRow.getTemporalColumnId();
        while (columnRowIterator.hasNext() && columnRowIterator.peek().getTableId() == tableRow.getTableId()) {
            ColumnMetadataRow columnRow = columnRowIterator.next();
            if (temporalColumnId.isPresent() && columnRow.getColumnId() == temporalColumnId.getAsLong()) {
                temporalColumnName = columnRow.getColumnName();
            }
            OptionalInt sortOrdinalPosition = columnRow.getSortOrdinalPosition();
            if (sortOrdinalPosition.isPresent()) {
                sortColumnNames.put(sortOrdinalPosition.getAsInt(), columnRow.getColumnName());
            }
            OptionalInt bucketOrdinalPosition = columnRow.getBucketOrdinalPosition();
            if (bucketOrdinalPosition.isPresent()) {
                bucketColumnNames.put(bucketOrdinalPosition.getAsInt(), columnRow.getColumnName());
            }
        }
        pageBuilder.beginRow();
        // schema_name, table_name
        VARCHAR.writeSlice(pageBuilder.nextBlockBuilder(), utf8Slice(tableRow.getSchemaName()));
        VARCHAR.writeSlice(pageBuilder.nextBlockBuilder(), utf8Slice(tableRow.getTableName()));
        // temporal_column
        if (temporalColumnId.isPresent()) {
            if (temporalColumnName == null) {
                throw new PrestoException(RAPTOR_CORRUPT_METADATA, format("Table ID %s has corrupt metadata (invalid temporal column ID)", tableRow.getTableId()));
            }
            VARCHAR.writeSlice(pageBuilder.nextBlockBuilder(), utf8Slice(temporalColumnName));
        } else {
            pageBuilder.nextBlockBuilder().appendNull();
        }
        // ordering_columns
        writeArray(pageBuilder.nextBlockBuilder(), sortColumnNames.values());
        // distribution_name
        Optional<String> distributionName = tableRow.getDistributionName();
        if (distributionName.isPresent()) {
            VARCHAR.writeSlice(pageBuilder.nextBlockBuilder(), utf8Slice(distributionName.get()));
        } else {
            pageBuilder.nextBlockBuilder().appendNull();
        }
        // bucket_count
        OptionalInt bucketCount = tableRow.getBucketCount();
        if (bucketCount.isPresent()) {
            BIGINT.writeLong(pageBuilder.nextBlockBuilder(), bucketCount.getAsInt());
        } else {
            pageBuilder.nextBlockBuilder().appendNull();
        }
        // bucketing_columns
        writeArray(pageBuilder.nextBlockBuilder(), bucketColumnNames.values());
        // organized
        BOOLEAN.writeBoolean(pageBuilder.nextBlockBuilder(), tableRow.isOrganized());
    }
    return pageBuilder.build();
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) NullableValue(com.facebook.presto.spi.predicate.NullableValue) PrestoException(com.facebook.presto.spi.PrestoException) ColumnMetadataRow(com.facebook.presto.raptor.metadata.ColumnMetadataRow) OptionalInt(java.util.OptionalInt) TreeMap(java.util.TreeMap) OptionalLong(java.util.OptionalLong) TableMetadataRow(com.facebook.presto.raptor.metadata.TableMetadataRow)

Example 30 with OptionalInt

use of java.util.OptionalInt in project android by JetBrains.

the class StringResourceTable method setModel.

@Override
public void setModel(@NotNull TableModel model) {
    super.setModel(model);
    OptionalInt optionalWidth = getKeyColumnPreferredWidth();
    if (optionalWidth.isPresent()) {
        columnModel.getColumn(KEY_COLUMN).setPreferredWidth(optionalWidth.getAsInt());
    }
    if (tableHeader == null) {
        return;
    }
    setLocaleColumnHeaderRenderers();
    optionalWidth = getDefaultValueAndLocaleColumnPreferredWidths();
    if (optionalWidth.isPresent()) {
        int width = optionalWidth.getAsInt();
        IntStream.range(DEFAULT_VALUE_COLUMN, getColumnCount()).mapToObj(columnModel::getColumn).forEach(column -> column.setPreferredWidth(width));
    }
}
Also used : OptionalInt(java.util.OptionalInt)

Aggregations

OptionalInt (java.util.OptionalInt)38 Test (org.testng.annotations.Test)11 List (java.util.List)8 UUID (java.util.UUID)7 Arrays (java.util.Arrays)6 IntStream (java.util.stream.IntStream)6 Optional (java.util.Optional)5 Test (org.junit.Test)5 ConnectivityManager (android.net.ConnectivityManager)4 NetworkCallback (android.net.ConnectivityManager.NetworkCallback)4 Network (android.net.Network)4 DnsEvent (android.net.metrics.DnsEvent)4 INetdEventListener (android.net.metrics.INetdEventListener)4 IpConnectivityLog (android.net.metrics.IpConnectivityLog)4 RemoteException (android.os.RemoteException)4 SmallTest (android.test.suitebuilder.annotation.SmallTest)4 PrestoException (com.facebook.presto.spi.PrestoException)4 Type (com.facebook.presto.spi.type.Type)4 FileOutputStream (java.io.FileOutputStream)4 PrintWriter (java.io.PrintWriter)4