Skip to content

Commit

Permalink
Fix bug in OrderByCrossPartitionQueryPipelineStage to ensure that fai…
Browse files Browse the repository at this point in the history
…lures in creating the inner pipeline stage are bubbled up to the higher stages (#4419)
  • Loading branch information
neildsh authored and adityasa committed May 15, 2024
1 parent 83b8341 commit 335eb16
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public async ValueTask<bool> MoveNextAsync(ITrace trace, CancellationToken cance
}

TryCatch<bool> hasNext = await this.inner.TryAsync(pipelineStage => pipelineStage.MoveNextAsync(trace, cancellationToken));
return hasNext.Succeeded && hasNext.Result;
return hasNext.Failed || hasNext.Result;
}

public ValueTask DisposeAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,58 @@ public async Task TestMixedTypeOrderByAsync()
},
"/id",
indexV2Policy);
}

[TestMethod]
public async Task TestBadOrderByQueriesAsync()
{
const string NoCompositeIndex = "The order by query does not have a corresponding composite index that it can be served from.";
const string OrderByOverCorrelatedPath = "Order-by over correlated collections is not supported.";

static async Task ImplementationAsync(
Container container,
IReadOnlyList<CosmosObject> documents)
{
IReadOnlyList<(string query, string error)> queries = new List<(string query, string error)>
{
("SELECT * FROM c ORDER BY c.id, c.name", NoCompositeIndex),
("SELECT * FROM c ORDER BY c.id DESC, c._ts DESC", NoCompositeIndex),
(
@"SELECT DISTINCT VALUE v2
FROM root
JOIN (
SELECT DISTINCT VALUE v0
FROM root
JOIN v0 IN root.Parents) AS v2
WHERE (LENGTH(v2.FamilyName) > 10)
ORDER BY v2 ASC",
OrderByOverCorrelatedPath
),
};

foreach (bool enableOptmisticDirectExecution in new []{ false, true })
{
QueryRequestOptions options = new QueryRequestOptions()
{
EnableOptimisticDirectExecution = enableOptmisticDirectExecution,
};

foreach ((string query, string error) in queries)
{
using FeedIterator feedIterator = container.GetItemQueryStreamIterator(query, continuationToken: null, options);
ResponseMessage response = await feedIterator.ReadNextAsync();
Assert.AreEqual(System.Net.HttpStatusCode.BadRequest, response.StatusCode);
Assert.IsNotNull(response.CosmosException);
Assert.IsTrue(response.CosmosException.Message.Contains(error));
}
}
}

await this.CreateIngestQueryDeleteAsync(
ConnectionModes.Direct | ConnectionModes.Gateway,
CollectionTypes.SinglePartition | CollectionTypes.MultiPartition,
new List<string>(),
ImplementationAsync);
}

private sealed class MixedTypedDocument
Expand Down

0 comments on commit 335eb16

Please sign in to comment.