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

Review GroovyWriter #1615

Merged
merged 3 commits into from
Jun 6, 2024
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
38 changes: 14 additions & 24 deletions src/Core/SerializedQueries/GroovyWriter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Collections.Immutable;
#pragma warning disable IDE0003 // Remove qualification

using System.Collections;
using System.Collections.Immutable;
using System.Text;

using ExRam.Gremlinq.Core.Serialization;
Expand Down Expand Up @@ -45,7 +48,7 @@ public static GroovyGremlinScript ToGroovyScript(Bytecode bytecode, IGremlinQuer
}

private GroovyWriter Append(
object obj,
object? obj,
StringBuilder stringBuilder,
Dictionary<object, Label>? bindings,
IGremlinQueryEnvironment environment,
Expand Down Expand Up @@ -85,7 +88,6 @@ private GroovyWriter Append(
}
case Instruction instruction:
{
#pragma warning disable IDE0003 // Remove qualification
return this
.StartOperator(instruction.OperatorName, stringBuilder)
.Append(instruction.Arguments, stringBuilder, bindings, environment, true)
Expand All @@ -105,7 +107,6 @@ private GroovyWriter Append(
.StartOperator(operatorName, stringBuilder)
.Append(pValue, stringBuilder, bindings, environment, true)
.EndOperator(stringBuilder);
#pragma warning restore IDE0003 // Remove qualification
}
case EnumWrapper t:
{
Expand Down Expand Up @@ -146,33 +147,22 @@ private GroovyWriter Append(
environment,
allowEnumerableExpansion);
}
case object[] objectArray when allowEnumerableExpansion:
{
var writer = this;

for (var i = 0; i < objectArray.Length; i++)
{
writer = writer
.StartParameter(i, stringBuilder)
.Append(objectArray[i], stringBuilder, bindings, environment);
}

return writer;
}
case object[] objectArray:
case IList list when !environment.SupportsTypeNatively(list.GetType()):
{
var writer = this
.StartArray(stringBuilder);
var writer = allowEnumerableExpansion
? this
: StartArray(stringBuilder);

for (var i = 0; i < objectArray.Length; i++)
for (var i = 0; i < list.Count; i++)
{
writer = writer
.StartElement(i, stringBuilder)
.Append(objectArray[i], stringBuilder, bindings, environment);
.Append(list[i], stringBuilder, bindings, environment);
}

return writer
.EndArray(stringBuilder);
return allowEnumerableExpansion
? writer
: writer.EndArray(stringBuilder);
}
case null:
return Write("null", stringBuilder);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
g.V().constant([])
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
g.V().constant([true])
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
g.V().constant('Hallo')
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
StepInstructions: [
{
OperatorName: V
},
{
OperatorName: constant,
Arguments: []
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
StepInstructions: [
{
OperatorName: V
},
{
OperatorName: constant,
Arguments: [
[
true
]
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
StepInstructions: [
{
OperatorName: V
},
{
OperatorName: constant,
Arguments: [
Hallo
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
StepInstructions: [
{
OperatorName: V
},
{
OperatorName: constant,
Arguments: []
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
StepInstructions: [
{
OperatorName: V
},
{
OperatorName: constant,
Arguments: [
[
true
]
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
StepInstructions: [
{
OperatorName: V
},
{
OperatorName: constant,
Arguments: [
Hallo
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"requestId": "00000000-0000-0000-0000-000000000000",
"op": "bytecode",
"processor": "traversal",
"args": {
"gremlin": {
"@type": "g:Bytecode",
"@value": {
"step": [
[
"V"
],
[
"constant",
[]
]
]
}
},
"aliases": {
"g": "g"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"requestId": "00000000-0000-0000-0000-000000000000",
"op": "bytecode",
"processor": "traversal",
"args": {
"gremlin": {
"@type": "g:Bytecode",
"@value": {
"step": [
[
"V"
],
[
"constant",
[
true
]
]
]
}
},
"aliases": {
"g": "g"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"requestId": "00000000-0000-0000-0000-000000000000",
"op": "bytecode",
"processor": "traversal",
"args": {
"gremlin": {
"@type": "g:Bytecode",
"@value": {
"step": [
[
"V"
],
[
"constant",
"Hallo"
]
]
}
},
"aliases": {
"g": "g"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"requestId": "00000000-0000-0000-0000-000000000000",
"op": "bytecode",
"processor": "traversal",
"args": {
"gremlin": {
"@type": "g:Bytecode",
"@value": {
"step": [
[
"V"
],
[
"constant",
[]
]
]
}
},
"aliases": {
"g": "g"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"requestId": "00000000-0000-0000-0000-000000000000",
"op": "bytecode",
"processor": "traversal",
"args": {
"gremlin": {
"@type": "g:Bytecode",
"@value": {
"step": [
[
"V"
],
[
"constant",
[
true
]
]
]
}
},
"aliases": {
"g": "g"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"requestId": "00000000-0000-0000-0000-000000000000",
"op": "bytecode",
"processor": "traversal",
"args": {
"gremlin": {
"@type": "g:Bytecode",
"@value": {
"step": [
[
"V"
],
[
"constant",
"Hallo"
]
]
}
},
"aliases": {
"g": "g"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"requestId": "00000000-0000-0000-0000-000000000000",
"op": "eval",
"processor": "",
"args": {
"gremlin": "g.V().constant([])",
"bindings": {},
"aliases": {
"g": "g"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"requestId": "00000000-0000-0000-0000-000000000000",
"op": "eval",
"processor": "",
"args": {
"gremlin": "g.V().constant([_a])",
"bindings": {
"_a": true
},
"aliases": {
"g": "g"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"requestId": "00000000-0000-0000-0000-000000000000",
"op": "eval",
"processor": "",
"args": {
"gremlin": "g.V().constant(_a)",
"bindings": {
"_a": "Hallo"
},
"aliases": {
"g": "g"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
Script: g.V().constant([])
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
Script: g.V().constant([_a]),
Bindings: {
_a: true
}
}
Loading