-
Notifications
You must be signed in to change notification settings - Fork 0
Fix filter scalar output and quoted properties #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mkrueger
wants to merge
11
commits into
main
Choose a base branch
from
dev/mkrueger/filter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
95a5deb
Initial plan
Copilot ec619d4
Initial plan
Copilot 642d36b
Consolidate CI build/test and packaging into one workflow job
mkrueger 2f278f9
Add native filter command with jq-inspired JSON expressions
mkrueger f800a2c
Fix filter property paths and scalar JSON output
mkrueger a97d0ee
Add filter integration tests
mkrueger c7f38f2
Merge branch 'main' into dev/mkrueger/filter
mkrueger 6e000fc
Address PR #67 review feedback and fix pipe+assignment regression
mkrueger 65da5a2
Restrict filter-path parsing to filter command context
mkrueger 845ef32
Skip version /p: args on PR builds when GitVersion step is skipped
mkrueger 6169984
Zip signed per-RID publish folders for easy download/upload
mkrueger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| // ------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // ------------------------------------------------------------ | ||
|
|
||
| namespace CosmosShell.Tests.CommandTests; | ||
|
|
||
| using System.Text.Json; | ||
| using Azure.Data.Cosmos.Shell.Commands; | ||
| using Azure.Data.Cosmos.Shell.Core; | ||
| using Azure.Data.Cosmos.Shell.Parser; | ||
|
|
||
| public class FilterCommandTests | ||
| { | ||
| [Fact] | ||
| public async Task ExecuteAsync_AppliesPathExpression_AndPreservesStructuredResult() | ||
| { | ||
| var shell = ShellInterpreter.CreateInstance(); | ||
| var state = new CommandState | ||
| { | ||
| Result = new ShellJson(JsonSerializer.SerializeToElement(new | ||
| { | ||
| items = new[] | ||
| { | ||
| new { id = "1", status = "active" }, | ||
| new { id = "2", status = "inactive" }, | ||
| }, | ||
| })), | ||
| }; | ||
|
|
||
| var command = new FilterCommand | ||
| { | ||
| ExpressionText = ".items[0].id", | ||
| }; | ||
|
|
||
| var result = await command.ExecuteAsync(shell, state, string.Empty, CancellationToken.None); | ||
|
|
||
| Assert.Same(state, result); | ||
| Assert.False(result.IsPrinted); | ||
| var json = Assert.IsType<ShellJson>(result.Result); | ||
| Assert.Equal("1", json.Value.GetString()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task ExecuteAsync_AppliesMapProjection() | ||
| { | ||
| var shell = ShellInterpreter.CreateInstance(); | ||
| var state = new CommandState | ||
| { | ||
| Result = new ShellJson(JsonSerializer.SerializeToElement(new | ||
| { | ||
| items = new[] | ||
| { | ||
| new { id = "1", status = "active" }, | ||
| new { id = "2", status = "inactive" }, | ||
| }, | ||
| })), | ||
| }; | ||
|
|
||
| var command = new FilterCommand | ||
| { | ||
| ExpressionText = ".items | map({id, status})", | ||
| }; | ||
|
|
||
| var result = await command.ExecuteAsync(shell, state, string.Empty, CancellationToken.None); | ||
|
|
||
| var json = Assert.IsType<ShellJson>(result.Result); | ||
| Assert.Equal(JsonValueKind.Array, json.Value.ValueKind); | ||
| Assert.Equal("1", json.Value[0].GetProperty("id").GetString()); | ||
| Assert.Equal("active", json.Value[0].GetProperty("status").GetString()); | ||
| Assert.Equal("2", json.Value[1].GetProperty("id").GetString()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task ExecuteAsync_NormalizesSequenceResult_ToJsonArray() | ||
| { | ||
| var shell = ShellInterpreter.CreateInstance(); | ||
| var state = new CommandState | ||
| { | ||
| Result = new ShellJson(JsonSerializer.SerializeToElement(new | ||
| { | ||
| items = new[] | ||
| { | ||
| new { id = "1" }, | ||
| new { id = "2" }, | ||
| }, | ||
| })), | ||
| }; | ||
|
|
||
| var command = new FilterCommand | ||
| { | ||
| ExpressionText = ".items[] | .id", | ||
| }; | ||
|
|
||
| var result = await command.ExecuteAsync(shell, state, string.Empty, CancellationToken.None); | ||
|
|
||
| var json = Assert.IsType<ShellJson>(result.Result); | ||
| Assert.Equal(JsonValueKind.Array, json.Value.ValueKind); | ||
| Assert.Equal("1", json.Value[0].GetString()); | ||
| Assert.Equal("2", json.Value[1].GetString()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task ExecuteAsync_NormalizesTextResult_ToJsonString() | ||
| { | ||
| var shell = ShellInterpreter.CreateInstance(); | ||
| var state = new CommandState | ||
| { | ||
| Result = new ShellJson(JsonSerializer.SerializeToElement(new { id = "1" })), | ||
| }; | ||
|
|
||
| var command = new FilterCommand | ||
| { | ||
| ExpressionText = "type", | ||
| }; | ||
|
|
||
| var result = await command.ExecuteAsync(shell, state, string.Empty, CancellationToken.None); | ||
|
|
||
| var json = Assert.IsType<ShellJson>(result.Result); | ||
| Assert.Equal(JsonValueKind.String, json.Value.ValueKind); | ||
| Assert.Equal("object", json.Value.GetString()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task ExecuteAsync_NormalizesBooleanResult_ToJsonBoolean() | ||
| { | ||
| var shell = ShellInterpreter.CreateInstance(); | ||
| var state = new CommandState | ||
| { | ||
| Result = new ShellJson(JsonSerializer.SerializeToElement(new { id = "1" })), | ||
| }; | ||
|
|
||
| var command = new FilterCommand | ||
| { | ||
| ExpressionText = "true", | ||
| }; | ||
|
|
||
| var result = await command.ExecuteAsync(shell, state, string.Empty, CancellationToken.None); | ||
|
|
||
| var json = Assert.IsType<ShellJson>(result.Result); | ||
| Assert.Equal(JsonValueKind.True, json.Value.ValueKind); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task ExecuteAsync_ThrowsWhenInputMissing() | ||
| { | ||
| var shell = ShellInterpreter.CreateInstance(); | ||
| var command = new FilterCommand | ||
| { | ||
| ExpressionText = ".items", | ||
| }; | ||
|
|
||
| var ex = await Assert.ThrowsAsync<CommandException>(() => command.ExecuteAsync(shell, new CommandState(), string.Empty, CancellationToken.None)); | ||
| Assert.Contains("requires piped JSON input", ex.Message, StringComparison.OrdinalIgnoreCase); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task ExecuteAsync_ThrowsWhenExpressionInvalid() | ||
| { | ||
| var shell = ShellInterpreter.CreateInstance(); | ||
| var state = new CommandState | ||
| { | ||
| Result = new ShellJson(JsonSerializer.SerializeToElement(new { items = new[] { 1, 2 } })), | ||
| }; | ||
| var command = new FilterCommand | ||
| { | ||
| ExpressionText = ".items[", | ||
| }; | ||
|
|
||
| await Assert.ThrowsAsync<CommandException>(() => command.ExecuteAsync(shell, state, string.Empty, CancellationToken.None)); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.