Skip to content
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

Fix AsStep optimization bug #886

Merged
merged 4 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/ExRam.Gremlinq.Core/Serialization/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ static void AddInnerInstruction(Instruction instruction, Bytecode byteCode)
{
AddStep(expandedStep, byteCode, env, recurse);
}
else if (recurse.TryTransform(step, env, out Traversal traversal))
{
foreach (var innerExpandedStep in traversal.Steps)
{
AddStep(innerExpandedStep, byteCode, env, recurse);
}
}
else if (recurse.TryTransform(step, env, out Instruction[]? expandedInstructions))
{
foreach (var expandedInstruction in expandedInstructions)
Expand Down Expand Up @@ -179,7 +186,7 @@ static void AddInnerInstruction(Instruction instruction, Bytecode byteCode)
if (span[j] is SelectStepLabelStep selectStep && ReferenceEquals(asStep.StepLabel, selectStep.StepLabels[0]))
continue;

if (span[j] is AsStep asStep2 && asStep2.StepLabel.Equals(asStep2.StepLabel))
if (span[j] is AsStep asStep2 && asStep2.StepLabel.Equals(asStep.StepLabel))
continue;

break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
g.V().hasLabel('Person').as('label1').as('label2').project('id','label','properties').by(id).by(label).by(__.properties().group().by(label).by(__.project('id','label','value','properties').by(id).by(label).by(value).by(__.valueMap()).fold()))
13 changes: 13 additions & 0 deletions test/ExRam.Gremlinq.Core.Tests/QueryExecutionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,19 @@ await _g
.Verify();
}

[Fact]
public virtual async Task As_As_with_different_labels()
{
var label1 = "label1";
var label2 = "label2";

await _g
.V<Person>()
.As(label1)
.As(label2)
.Verify();
}

[Fact]
public virtual async Task As_followed_by_Select()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
[
{
"Id": "00000000-0000-0000-0000-000000000000",
"Bytecode": {
"SourceInstructions": [],
"StepInstructions": [
{
"OperatorName": "V",
"Arguments": []
},
{
"OperatorName": "hasLabel",
"Arguments": [
"Person"
]
},
{
"OperatorName": "as",
"Arguments": [
"label1"
]
},
{
"OperatorName": "as",
"Arguments": [
"label2"
]
},
{
"OperatorName": "project",
"Arguments": [
"id",
"label",
"properties"
]
},
{
"OperatorName": "by",
"Arguments": [
{
"EnumName": "T",
"EnumValue": "id"
}
]
},
{
"OperatorName": "by",
"Arguments": [
{
"EnumName": "T",
"EnumValue": "label"
}
]
},
{
"OperatorName": "by",
"Arguments": [
{
"SourceInstructions": [],
"StepInstructions": [
{
"OperatorName": "properties",
"Arguments": []
},
{
"OperatorName": "group",
"Arguments": []
},
{
"OperatorName": "by",
"Arguments": [
{
"EnumName": "T",
"EnumValue": "label"
}
]
},
{
"OperatorName": "by",
"Arguments": [
{
"SourceInstructions": [],
"StepInstructions": [
{
"OperatorName": "project",
"Arguments": [
"id",
"label",
"value",
"properties"
]
},
{
"OperatorName": "by",
"Arguments": [
{
"EnumName": "T",
"EnumValue": "id"
}
]
},
{
"OperatorName": "by",
"Arguments": [
{
"EnumName": "T",
"EnumValue": "label"
}
]
},
{
"OperatorName": "by",
"Arguments": [
{
"EnumName": "T",
"EnumValue": "value"
}
]
},
{
"OperatorName": "by",
"Arguments": [
{
"SourceInstructions": [],
"StepInstructions": [
{
"OperatorName": "valueMap",
"Arguments": []
}
]
}
]
},
{
"OperatorName": "fold",
"Arguments": []
}
]
}
]
}
]
}
]
}
]
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"Id": "00000000-0000-0000-0000-000000000000",
"GraphSON": "{\"@type\":\"g:Bytecode\",\"@value\":{\"step\":[[\"V\"],[\"hasLabel\",\"Person\"],[\"as\",\"label1\"],[\"as\",\"label2\"],[\"project\",\"id\",\"label\",\"properties\"],[\"by\",{\"@type\":\"g:T\",\"@value\":\"id\"}],[\"by\",{\"@type\":\"g:T\",\"@value\":\"label\"}],[\"by\",{\"@type\":\"g:Bytecode\",\"@value\":{\"step\":[[\"properties\"],[\"group\"],[\"by\",{\"@type\":\"g:T\",\"@value\":\"label\"}],[\"by\",{\"@type\":\"g:Bytecode\",\"@value\":{\"step\":[[\"project\",\"id\",\"label\",\"value\",\"properties\"],[\"by\",{\"@type\":\"g:T\",\"@value\":\"id\"}],[\"by\",{\"@type\":\"g:T\",\"@value\":\"label\"}],[\"by\",{\"@type\":\"g:T\",\"@value\":\"value\"}],[\"by\",{\"@type\":\"g:Bytecode\",\"@value\":{\"step\":[[\"valueMap\"]]}}],[\"fold\"]]}}]]}}]]}}"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"Id": "00000000-0000-0000-0000-000000000000",
"GraphSON": "{\"@type\":\"g:Bytecode\",\"@value\":{\"step\":[[\"V\"],[\"hasLabel\",\"Person\"],[\"as\",\"label1\"],[\"as\",\"label2\"],[\"project\",\"id\",\"label\",\"properties\"],[\"by\",{\"@type\":\"g:T\",\"@value\":\"id\"}],[\"by\",{\"@type\":\"g:T\",\"@value\":\"label\"}],[\"by\",{\"@type\":\"g:Bytecode\",\"@value\":{\"step\":[[\"properties\"],[\"group\"],[\"by\",{\"@type\":\"g:T\",\"@value\":\"label\"}],[\"by\",{\"@type\":\"g:Bytecode\",\"@value\":{\"step\":[[\"project\",\"id\",\"label\",\"value\",\"properties\"],[\"by\",{\"@type\":\"g:T\",\"@value\":\"id\"}],[\"by\",{\"@type\":\"g:T\",\"@value\":\"label\"}],[\"by\",{\"@type\":\"g:T\",\"@value\":\"value\"}],[\"by\",{\"@type\":\"g:Bytecode\",\"@value\":{\"step\":[[\"valueMap\"]]}}],[\"fold\"]]}}]]}}]]}}"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
[
{
"Id": "00000000-0000-0000-0000-000000000000",
"Bytecode": {
"SourceInstructions": [],
"StepInstructions": [
{
"OperatorName": "V",
"Arguments": []
},
{
"OperatorName": "hasLabel",
"Arguments": [
"Person"
]
},
{
"OperatorName": "as",
"Arguments": [
"label1"
]
},
{
"OperatorName": "as",
"Arguments": [
"label2"
]
},
{
"OperatorName": "project",
"Arguments": [
"id",
"label",
"properties"
]
},
{
"OperatorName": "by",
"Arguments": [
{
"EnumName": "T",
"EnumValue": "id"
}
]
},
{
"OperatorName": "by",
"Arguments": [
{
"EnumName": "T",
"EnumValue": "label"
}
]
},
{
"OperatorName": "by",
"Arguments": [
{
"SourceInstructions": [],
"StepInstructions": [
{
"OperatorName": "properties",
"Arguments": []
},
{
"OperatorName": "group",
"Arguments": []
},
{
"OperatorName": "by",
"Arguments": [
{
"EnumName": "T",
"EnumValue": "label"
}
]
},
{
"OperatorName": "by",
"Arguments": [
{
"SourceInstructions": [],
"StepInstructions": [
{
"OperatorName": "project",
"Arguments": [
"id",
"label",
"value",
"properties"
]
},
{
"OperatorName": "by",
"Arguments": [
{
"EnumName": "T",
"EnumValue": "id"
}
]
},
{
"OperatorName": "by",
"Arguments": [
{
"EnumName": "T",
"EnumValue": "label"
}
]
},
{
"OperatorName": "by",
"Arguments": [
{
"EnumName": "T",
"EnumValue": "value"
}
]
},
{
"OperatorName": "by",
"Arguments": [
{
"SourceInstructions": [],
"StepInstructions": [
{
"OperatorName": "valueMap",
"Arguments": []
}
]
}
]
},
{
"OperatorName": "fold",
"Arguments": []
}
]
}
]
}
]
}
]
}
]
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"Script": "g.V().hasLabel(_a).as(_b).as(_c).project(_d,_e,_f).by(id).by(label).by(__.properties().group().by(label).by(__.project(_d,_e,_g,_f).by(id).by(label).by(value).by(__.valueMap()).fold()))",
"Id": "00000000-0000-0000-0000-000000000000",
"Bindings": {
"_a": "Person",
"_b": "label1",
"_c": "label2",
"_d": "id",
"_e": "label",
"_f": "properties",
"_g": "value"
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
g.V().hasLabel('Person').as('label1').as('label2')
Loading