public static TryCatch <DistinctMap> TryCreate(CosmosElement requestContinuationToken) { UInt128 lastHash; if (requestContinuationToken != null) { switch (requestContinuationToken) { case CosmosString cosmosString: if (!UInt128.TryParse(cosmosString.Value, out lastHash)) { return(TryCatch <DistinctMap> .FromException( new MalformedContinuationTokenException( $"Malformed {nameof(OrderedDistinctMap)} continuation token: {requestContinuationToken}."))); } break; case CosmosBinary cosmosBinary: if (!UInt128.TryCreateFromByteArray(cosmosBinary.Value.Span, out lastHash)) { return(TryCatch <DistinctMap> .FromException( new MalformedContinuationTokenException( $"Malformed {nameof(OrderedDistinctMap)} continuation token: {requestContinuationToken}."))); } break; default: throw new ArgumentOutOfRangeException($"Unknown {nameof(requestContinuationToken)} type. {requestContinuationToken.GetType()}."); } } else { lastHash = default; } return(TryCatch <DistinctMap> .FromResult(new OrderedDistinctMap(lastHash))); }
public RewrittenAggregateProjections(bool isValueAggregateQuery, CosmosElement raw) { if (raw == null) { throw new ArgumentNullException(nameof(raw)); } if (isValueAggregateQuery) { // SELECT VALUE [{"item": {"sum": SUM(c.blah), "count": COUNT(c.blah)}}] if (!(raw is CosmosArray aggregates)) { throw new ArgumentException($"{nameof(RewrittenAggregateProjections)} was not an array for a value aggregate query. Type is: {raw.GetType()}"); } this.Payload = aggregates[0]; } else { if (!(raw is CosmosObject cosmosObject)) { throw new ArgumentException($"{nameof(raw)} must not be an object."); } if (!cosmosObject.TryGetValue("payload", out CosmosElement cosmosPayload)) { throw new InvalidOperationException($"Underlying object does not have an 'payload' field."); } this.Payload = cosmosPayload ?? throw new ArgumentException($"{nameof(RewrittenAggregateProjections)} does not have a 'payload' property."); } }
public override Output ExecuteTest(Input input) { CosmosElement value = input.PartitionKeyValue; PartitionKeyHash partitionKeyHashV1; PartitionKeyHash partitionKeyHashV2; switch (value) { case null: partitionKeyHashV1 = PartitionKeyHash.V1.HashUndefined(); partitionKeyHashV2 = PartitionKeyHash.V2.HashUndefined(); break; case CosmosNull cosmosNull: partitionKeyHashV1 = PartitionKeyHash.V1.HashNull(); partitionKeyHashV2 = PartitionKeyHash.V2.HashNull(); break; case CosmosBoolean cosmosBoolean: partitionKeyHashV1 = PartitionKeyHash.V1.Hash(cosmosBoolean.Value); partitionKeyHashV2 = PartitionKeyHash.V2.Hash(cosmosBoolean.Value); break; case CosmosString cosmosString: partitionKeyHashV1 = PartitionKeyHash.V1.Hash(cosmosString.Value); partitionKeyHashV2 = PartitionKeyHash.V2.Hash(cosmosString.Value); break; case CosmosNumber cosmosNumber: partitionKeyHashV1 = PartitionKeyHash.V1.Hash(Number64.ToDouble(cosmosNumber.Value)); partitionKeyHashV2 = PartitionKeyHash.V2.Hash(Number64.ToDouble(cosmosNumber.Value)); break; default: throw new ArgumentOutOfRangeException($"Unknown {nameof(CosmosElement)} type: {value.GetType()}."); } return(new Output(partitionKeyHashV1, partitionKeyHashV2)); }