Search in sources :

Example 11 with OptionalLong

use of java.util.OptionalLong in project jdk8u_jdk by JetBrains.

the class BasicLong method testEmptyGet.

@Test(expectedExceptions = NoSuchElementException.class)
public void testEmptyGet() {
    OptionalLong empty = OptionalLong.empty();
    long got = empty.getAsLong();
}
Also used : OptionalLong(java.util.OptionalLong) Test(org.testng.annotations.Test)

Example 12 with OptionalLong

use of java.util.OptionalLong in project jdk8u_jdk by JetBrains.

the class BasicLong method testEmptyOrElseThrow.

@Test(expectedExceptions = ObscureException.class)
public void testEmptyOrElseThrow() throws Exception {
    OptionalLong empty = OptionalLong.empty();
    long got = empty.orElseThrow(ObscureException::new);
}
Also used : OptionalLong(java.util.OptionalLong) Test(org.testng.annotations.Test)

Example 13 with OptionalLong

use of java.util.OptionalLong in project fastjson by alibaba.

the class OptionalCodec method write.

public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
    if (object == null) {
        serializer.writeNull();
        return;
    }
    if (object instanceof Optional) {
        Optional<?> optional = (Optional<?>) object;
        Object value = optional.isPresent() ? optional.get() : null;
        serializer.write(value);
        return;
    }
    if (object instanceof OptionalDouble) {
        OptionalDouble optional = (OptionalDouble) object;
        if (optional.isPresent()) {
            double value = optional.getAsDouble();
            serializer.write(value);
        } else {
            serializer.writeNull();
        }
        return;
    }
    if (object instanceof OptionalInt) {
        OptionalInt optional = (OptionalInt) object;
        if (optional.isPresent()) {
            int value = optional.getAsInt();
            serializer.out.writeInt(value);
        } else {
            serializer.writeNull();
        }
        return;
    }
    if (object instanceof OptionalLong) {
        OptionalLong optional = (OptionalLong) object;
        if (optional.isPresent()) {
            long value = optional.getAsLong();
            serializer.out.writeLong(value);
        } else {
            serializer.writeNull();
        }
        return;
    }
    throw new JSONException("not support optional : " + object.getClass());
}
Also used : Optional(java.util.Optional) OptionalLong(java.util.OptionalLong) JSONException(com.alibaba.fastjson.JSONException) OptionalInt(java.util.OptionalInt) OptionalDouble(java.util.OptionalDouble)

Example 14 with OptionalLong

use of java.util.OptionalLong in project lucene-solr by apache.

the class Boolean2ScorerSupplier method computeCost.

private long computeCost() {
    OptionalLong minRequiredCost = Stream.concat(subs.get(Occur.MUST).stream(), subs.get(Occur.FILTER).stream()).mapToLong(ScorerSupplier::cost).min();
    if (minRequiredCost.isPresent() && minShouldMatch == 0) {
        return minRequiredCost.getAsLong();
    } else {
        final Collection<ScorerSupplier> optionalScorers = subs.get(Occur.SHOULD);
        final long shouldCost = MinShouldMatchSumScorer.cost(optionalScorers.stream().mapToLong(ScorerSupplier::cost), optionalScorers.size(), minShouldMatch);
        return Math.min(minRequiredCost.orElse(Long.MAX_VALUE), shouldCost);
    }
}
Also used : OptionalLong(java.util.OptionalLong)

Example 15 with OptionalLong

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

the class RaptorMetadata method finishDelete.

@Override
public void finishDelete(ConnectorSession session, ConnectorTableHandle tableHandle, Collection<Slice> fragments) {
    RaptorTableHandle table = (RaptorTableHandle) tableHandle;
    long transactionId = table.getTransactionId().getAsLong();
    long tableId = table.getTableId();
    List<ColumnInfo> columns = getColumnHandles(session, tableHandle).values().stream().map(RaptorColumnHandle.class::cast).map(ColumnInfo::fromHandle).collect(toList());
    ImmutableSet.Builder<UUID> oldShardUuidsBuilder = ImmutableSet.builder();
    ImmutableList.Builder<ShardInfo> newShardsBuilder = ImmutableList.builder();
    fragments.stream().map(fragment -> SHARD_DELTA_CODEC.fromJson(fragment.getBytes())).forEach(delta -> {
        oldShardUuidsBuilder.addAll(delta.getOldShardUuids());
        newShardsBuilder.addAll(delta.getNewShards());
    });
    Set<UUID> oldShardUuids = oldShardUuidsBuilder.build();
    List<ShardInfo> newShards = newShardsBuilder.build();
    OptionalLong updateTime = OptionalLong.of(session.getStartTime());
    log.info("Finishing delete for tableId %s (removed: %s, rewritten: %s)", tableId, oldShardUuids.size() - newShards.size(), newShards.size());
    shardManager.replaceShardUuids(transactionId, tableId, columns, oldShardUuids, newShards, updateTime);
    clearRollback();
}
Also used : SHARD_UUID_COLUMN_TYPE(com.facebook.presto.raptor.RaptorColumnHandle.SHARD_UUID_COLUMN_TYPE) NOT_FOUND(com.facebook.presto.spi.StandardErrorCode.NOT_FOUND) DatabaseUtil.runIgnoringConstraintViolation(com.facebook.presto.raptor.util.DatabaseUtil.runIgnoringConstraintViolation) Map(java.util.Map) ShardManager(com.facebook.presto.raptor.metadata.ShardManager) INVALID_TABLE_PROPERTY(com.facebook.presto.spi.StandardErrorCode.INVALID_TABLE_PROPERTY) RaptorTableProperties.getSortColumns(com.facebook.presto.raptor.RaptorTableProperties.getSortColumns) ColumnInfo(com.facebook.presto.raptor.metadata.ColumnInfo) ViewResult(com.facebook.presto.raptor.metadata.ViewResult) Set(java.util.Set) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) RaptorColumnHandle.shardUuidColumnHandle(com.facebook.presto.raptor.RaptorColumnHandle.shardUuidColumnHandle) ConnectorPartitioningHandle(com.facebook.presto.spi.connector.ConnectorPartitioningHandle) Slice(io.airlift.slice.Slice) ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) Multimaps(com.google.common.collect.Multimaps) ArrayList(java.util.ArrayList) OptionalLong(java.util.OptionalLong) Type(com.facebook.presto.spi.type.Type) BUCKET_NUMBER_COLUMN_NAME(com.facebook.presto.raptor.RaptorColumnHandle.BUCKET_NUMBER_COLUMN_NAME) RaptorSessionProperties.getExternalBatchId(com.facebook.presto.raptor.RaptorSessionProperties.getExternalBatchId) TIMESTAMP(com.facebook.presto.spi.type.TimestampType.TIMESTAMP) DatabaseUtil.daoTransaction(com.facebook.presto.raptor.util.DatabaseUtil.daoTransaction) Nullable(javax.annotation.Nullable) RaptorTableProperties.isOrganized(com.facebook.presto.raptor.RaptorTableProperties.isOrganized) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) Distribution(com.facebook.presto.raptor.metadata.Distribution) BUCKETED_ON_PROPERTY(com.facebook.presto.raptor.RaptorTableProperties.BUCKETED_ON_PROPERTY) ORDERING_PROPERTY(com.facebook.presto.raptor.RaptorTableProperties.ORDERING_PROPERTY) RaptorSessionProperties.getOneSplitPerBucketThreshold(com.facebook.presto.raptor.RaptorSessionProperties.getOneSplitPerBucketThreshold) ColumnIdentity(com.facebook.presto.spi.ColumnIdentity) Constraint(com.facebook.presto.spi.Constraint) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) RaptorTableProperties.getBucketColumns(com.facebook.presto.raptor.RaptorTableProperties.getBucketColumns) MetadataDao(com.facebook.presto.raptor.metadata.MetadataDao) JsonCodec.jsonCodec(io.airlift.json.JsonCodec.jsonCodec) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) RAPTOR_ERROR(com.facebook.presto.raptor.RaptorErrorCode.RAPTOR_ERROR) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) TreeMap(java.util.TreeMap) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ConnectorNewTableLayout(com.facebook.presto.spi.ConnectorNewTableLayout) ConnectorViewDefinition(com.facebook.presto.spi.ConnectorViewDefinition) BUCKET_COUNT_PROPERTY(com.facebook.presto.raptor.RaptorTableProperties.BUCKET_COUNT_PROPERTY) ViewNotFoundException(com.facebook.presto.spi.ViewNotFoundException) ShardDelta(com.facebook.presto.raptor.metadata.ShardDelta) IDBI(org.skife.jdbi.v2.IDBI) RaptorBucketFunction.validateBucketType(com.facebook.presto.raptor.RaptorBucketFunction.validateBucketType) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) SchemaTableName(com.facebook.presto.spi.SchemaTableName) TableColumn(com.facebook.presto.raptor.metadata.TableColumn) DatabaseUtil.runTransaction(com.facebook.presto.raptor.util.DatabaseUtil.runTransaction) ImmutableSet(com.google.common.collect.ImmutableSet) RaptorTableProperties.getDistributionName(com.facebook.presto.raptor.RaptorTableProperties.getDistributionName) ImmutableMap(com.google.common.collect.ImmutableMap) DISTRIBUTION_NAME_PROPERTY(com.facebook.presto.raptor.RaptorTableProperties.DISTRIBUTION_NAME_PROPERTY) Collections.nCopies(java.util.Collections.nCopies) Collection(java.util.Collection) RaptorTableProperties.getTemporalColumn(com.facebook.presto.raptor.RaptorTableProperties.getTemporalColumn) UUID(java.util.UUID) RaptorColumnHandle.isHiddenColumn(com.facebook.presto.raptor.RaptorColumnHandle.isHiddenColumn) RaptorColumnHandle.bucketNumberColumnHandle(com.facebook.presto.raptor.RaptorColumnHandle.bucketNumberColumnHandle) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) List(java.util.List) RaptorTableProperties.getBucketCount(com.facebook.presto.raptor.RaptorTableProperties.getBucketCount) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) NOT_SUPPORTED(com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED) TEMPORAL_COLUMN_PROPERTY(com.facebook.presto.raptor.RaptorTableProperties.TEMPORAL_COLUMN_PROPERTY) Optional(java.util.Optional) INTEGER(com.facebook.presto.spi.type.IntegerType.INTEGER) SortedMap(java.util.SortedMap) JsonCodec(io.airlift.json.JsonCodec) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ORGANIZED_PROPERTY(com.facebook.presto.raptor.RaptorTableProperties.ORGANIZED_PROPERTY) Logger(io.airlift.log.Logger) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) PrestoException(com.facebook.presto.spi.PrestoException) OptionalInt(java.util.OptionalInt) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors.toCollection(java.util.stream.Collectors.toCollection) ImmutableList(com.google.common.collect.ImmutableList) ALREADY_EXISTS(com.facebook.presto.spi.StandardErrorCode.ALREADY_EXISTS) ASC_NULLS_FIRST(com.facebook.presto.spi.block.SortOrder.ASC_NULLS_FIRST) SHARD_UUID_COLUMN_NAME(com.facebook.presto.raptor.RaptorColumnHandle.SHARD_UUID_COLUMN_NAME) Objects.requireNonNull(java.util.Objects.requireNonNull) DatabaseUtil.onDemandDao(com.facebook.presto.raptor.util.DatabaseUtil.onDemandDao) ConnectorNodePartitioning(com.facebook.presto.spi.ConnectorNodePartitioning) Table(com.facebook.presto.raptor.metadata.Table) ConnectorInsertTableHandle(com.facebook.presto.spi.ConnectorInsertTableHandle) ConnectorOutputMetadata(com.facebook.presto.spi.connector.ConnectorOutputMetadata) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) Maps(com.google.common.collect.Maps) ShardInfo(com.facebook.presto.raptor.metadata.ShardInfo) LongConsumer(java.util.function.LongConsumer) Collectors.toList(java.util.stream.Collectors.toList) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) DATE(com.facebook.presto.spi.type.DateType.DATE) RaptorColumnHandle.shardRowIdHandle(com.facebook.presto.raptor.RaptorColumnHandle.shardRowIdHandle) ImmutableList(com.google.common.collect.ImmutableList) ColumnInfo(com.facebook.presto.raptor.metadata.ColumnInfo) ImmutableSet(com.google.common.collect.ImmutableSet) OptionalLong(java.util.OptionalLong) UUID(java.util.UUID) ShardInfo(com.facebook.presto.raptor.metadata.ShardInfo)

Aggregations

OptionalLong (java.util.OptionalLong)23 Test (org.testng.annotations.Test)7 OptionalInt (java.util.OptionalInt)5 MetadataDao (com.facebook.presto.raptor.metadata.MetadataDao)3 Type (com.facebook.presto.spi.type.Type)3 List (java.util.List)3 ColumnInfo (com.facebook.presto.raptor.metadata.ColumnInfo)2 ShardManager (com.facebook.presto.raptor.metadata.ShardManager)2 Table (com.facebook.presto.raptor.metadata.Table)2 TableColumn (com.facebook.presto.raptor.metadata.TableColumn)2 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)2 PrestoException (com.facebook.presto.spi.PrestoException)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 TreeMap (java.util.TreeMap)2 UUID (java.util.UUID)2 Inject (javax.inject.Inject)2 JSONException (com.alibaba.fastjson.JSONException)1 ErrorCode (com.eightkdata.mongowp.ErrorCode)1 Status (com.eightkdata.mongowp.Status)1 BsonDocument (com.eightkdata.mongowp.bson.BsonDocument)1