Skip to content

Commit 17be1a7

Browse files
committed
Merge branch '3.8-dev'
2 parents a55ed71 + 0ac0710 commit 17be1a7

File tree

18 files changed

+84
-57
lines changed

18 files changed

+84
-57
lines changed

CHANGELOG.asciidoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ This release also includes changes from <<release-3-7-XXX, 3.7.XXX>>.
9999
* Removed Vertex/ReferenceVertex from grammar. Use vertex id in traversals now instead.
100100
* Removed `has(key, traversal)` and `has(T, traversal)` options for `has()` step.
101101
* Fixed bug where `InlineFilterStrategy` could add an empty `has()`.
102+
* Normalized dotnet `Element.properties` to lists.
102103
* Normalized python and javascript `Element.properties` to lists.
103104
* Renamed `none()` step to `discard()`.
104105
* Repurposed `none()` step as a list filtering step with the signature `none(P)`.
@@ -116,6 +117,8 @@ This release also includes changes from <<release-3-7-XXX, 3.7.XXX>>.
116117
* Added missing strategies to `strategies.py` in `gremlin-python`.
117118
* Fixed fully qualified class names for `TraversalStrategy` names in `gremlin-dotnet`.
118119
* Updated `OptionsStrategy` in `gremlin-python` to take options directly as keyword arguments.
120+
* Fixed `statics.BigDecimal` implementation in `gremlin-python` to properly calculate `scale` and `unscaled_value`, and added `value` attribute to return a `decimal.Decimal` representation.
121+
* Updated `GraphSON` in `gremlin-python` to return `statics.BigDecimal` instead of `decimal.Decimal` for consistency with `GraphBinary`.
119122
* Added static `instance()` method to `ElementIdStrategy` to an instance with the default configuration.
120123
* Updated `ElementIdStrategy.getConfiguration()` to help with serialization.
121124
* Added grammar-based `Translator` for all languages including explicit ones for Java and anonymization.

docs/src/upgrade/release-3.8.x.asciidoc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -625,18 +625,19 @@ See: link:https://issues.apache.org/jira/browse/TINKERPOP-1463[TINKERPOP-1463]
625625
626626
==== Serialization Changes
627627
628-
*Properties on Element Serialization in Python & Javascript*
628+
*Properties on Element Serialization in GLVs*
629629
630630
Element properties handling has been inconsistent across GLVs. Previously,`gremlin-python` deserialized empty properties
631-
as None or array depending on the serializer, while `gremlin-javascript` returned properties as objects or arrays, with
632-
empty properties as empty lists or undefined depending on the serializer.
631+
as `None` or array depending on the serializer, while `gremlin-javascript`, and `gremlin-dotnet` returned properties as
632+
objects or arrays, with empty properties as empty lists or undefined depending on the serializer. (Note that
633+
`gremlin-go` already returns empty slices for null properties so no changes is needed.)
633634
634635
This inconsistency is now resolved, aligning to how properties are handled in Gremlin core and in the Java GLV.
635-
Both GLVs will deserialize element properties into lists of property objects, returning empty lists instead of null values
636+
All GLVs will deserialize element properties into lists of property objects, returning empty lists instead of null values
636637
for missing properties.
637638
638-
For python, the most notable difference is in graphSON when "tokens" is turned on for "materializeProperties". The
639-
properties returned are no longer `None`, but empty lists. Users should update their code accordingly.
639+
For python and dotnet, the most notable difference is in graphSON when "tokens" is turned on for "materializeProperties". The
640+
properties returned are no longer `None` or `null`, but empty lists. Users should update their code accordingly.
640641
641642
For javascript, the change is slightly more extensive, as user should no longer expect javascript objects to be returned.
642643
All properties are returned as lists of Property or VertexProperty objects.

gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/language/translator/PythonTranslateVisitor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,15 @@ public Void visitFloatLiteral(final GremlinParser.FloatLiteralContext ctx) {
224224
final int lastCharIndex = floatLiteral.length() - 1;
225225
final char lastChar = floatLiteral.charAt(lastCharIndex);
226226
switch (lastChar) {
227-
case 'm':
228227
case 'f':
229228
case 'd':
230229
sb.append(floatLiteral, 0, lastCharIndex);
231230
break;
231+
case 'm':
232+
sb.append("bigdecimal(");
233+
sb.append(floatLiteral, 0, lastCharIndex);
234+
sb.append(")");
235+
break;
232236
default:
233237
// everything else just goes as specified
234238
sb.append(floatLiteral);

gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/translator/GremlinTranslatorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public static Collection<Object[]> data() {
332332
"g.with('x', 1.0)",
333333
"g.with(\"x\", new BigDecimal(\"1.0\"))",
334334
"g.with_(\"x\", 1.0)",
335-
"g.with_('x', 1.0)"},
335+
"g.with_('x', bigdecimal(1.0))"},
336336
{"g.with('x', -1.0m)",
337337
null,
338338
"g.with(string0, bigdecimal0)",
@@ -341,7 +341,7 @@ public static Collection<Object[]> data() {
341341
"g.with('x', -1.0)",
342342
"g.with(\"x\", new BigDecimal(\"-1.0\"))",
343343
"g.with_(\"x\", -1.0)",
344-
"g.with_('x', -1.0)"},
344+
"g.with_('x', bigdecimal(-1.0))"},
345345
{"g.with('x', -1.0M)",
346346
"g.with('x', -1.0m)",
347347
"g.with(string0, bigdecimal0)",
@@ -350,7 +350,7 @@ public static Collection<Object[]> data() {
350350
"g.with('x', -1.0)",
351351
"g.with(\"x\", new BigDecimal(\"-1.0\"))",
352352
"g.with_(\"x\", -1.0)",
353-
"g.with_('x', -1.0)"},
353+
"g.with_('x', bigdecimal(-1.0))"},
354354
{"g.with('x', 1b)",
355355
null,
356356
"g.with(string0, byte0)",

gremlin-dotnet/src/Gremlin.Net/Structure/Element.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected Element(object? id, string label, dynamic[]? properties = null)
4141
{
4242
Id = id;
4343
Label = label;
44-
Properties = properties;
44+
Properties = properties ?? Array.Empty<dynamic>();
4545
}
4646

4747
/// <summary>
@@ -57,7 +57,7 @@ protected Element(object? id, string label, dynamic[]? properties = null)
5757
/// <summary>
5858
/// Gets the properties of this <see cref="Element" />.
5959
/// </summary>
60-
public dynamic[]? Properties { get; }
60+
public dynamic[] Properties { get; }
6161

6262
/// <inheritdoc />
6363
public bool Equals(Element? other)

gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/EdgeDeserializer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#endregion
2323

24+
using System;
2425
using System.Linq;
2526
using System.Text.Json;
2627

@@ -45,7 +46,7 @@ public dynamic Objectify(JsonElement graphsonObject, GraphSONReader reader)
4546
? labelProperty.GetString()!
4647
: "edge";
4748

48-
dynamic[]? properties = null;
49+
dynamic[] properties = Array.Empty<dynamic>();
4950
if (graphsonObject.TryGetProperty("properties", out var propertiesObject)
5051
&& propertiesObject.ValueKind == JsonValueKind.Object)
5152
{

gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/VertexDeserializer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#endregion
2323

24+
using System;
2425
using System.Collections.Generic;
2526
using System.Linq;
2627
using System.Text.Json;
@@ -36,7 +37,7 @@ public dynamic Objectify(JsonElement graphsonObject, GraphSONReader reader)
3637
? labelProperty.GetString()!
3738
: Vertex.DefaultLabel;
3839

39-
dynamic[]? properties = null;
40+
dynamic[] properties = Array.Empty<dynamic>();
4041
if (graphsonObject.TryGetProperty("properties", out var propertiesObject)
4142
&& propertiesObject.ValueKind == JsonValueKind.Object)
4243
{

gremlin-dotnet/src/Gremlin.Net/Structure/IO/GraphSON/VertexPropertyDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public dynamic Objectify(JsonElement graphsonObject, GraphSONReader reader)
3737
? new Vertex(reader.ToObject(vertexProperty))
3838
: null;
3939

40-
Property[]? properties = null;
40+
Property[] properties = System.Array.Empty<Property>();
4141
if (graphsonObject.TryGetProperty("properties", out var propertiesObject)
4242
&& propertiesObject.ValueKind == JsonValueKind.Object)
4343
{

gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/DriverRemoteConnection/GraphTraversalTests.cs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -293,49 +293,46 @@ public async Task ShouldThrowExceptionOnRollbackWhenGraphNotSupportTx()
293293
}
294294

295295
[Fact]
296-
public void shouldUseMaterializedPropertiesTokenInV()
296+
public void ShouldUseMaterializedPropertiesTokenInV()
297297
{
298298
var connection = _connectionFactory.CreateRemoteConnection();
299299
var g = AnonymousTraversalSource.Traversal().With(connection);
300300
var vertices = g.With("materializeProperties", "tokens").V().ToList();
301301
foreach (var v in vertices)
302302
{
303303
Assert.NotNull(v);
304-
// GraphSON will deserialize into null and GraphBinary to []
305-
Assert.True(v.Properties == null || v.Properties.Length == 0);
304+
Assert.Empty(v.Properties);
306305
}
307306
}
308307

309308
[Fact]
310-
public void shouldUseMaterializedPropertiesTokenInE()
309+
public void ShouldUseMaterializedPropertiesTokenInE()
311310
{
312311
var connection = _connectionFactory.CreateRemoteConnection();
313312
var g = AnonymousTraversalSource.Traversal().With(connection);
314313
var edges = g.With("materializeProperties", "tokens").E().ToList();
315314
foreach (var e in edges)
316315
{
317316
Assert.NotNull(e);
318-
// GraphSON will deserialize into null and GraphBinary to []
319-
Assert.True(e.Properties == null || e.Properties.Length == 0);
317+
Assert.Empty(e.Properties);
320318
}
321319
}
322320

323321
[Fact]
324-
public void shouldUseMaterializedPropertiesTokenInVP()
322+
public void ShouldUseMaterializedPropertiesTokenInVP()
325323
{
326324
var connection = _connectionFactory.CreateRemoteConnection();
327325
var g = AnonymousTraversalSource.Traversal().With(connection);
328326
var vps = g.With("materializeProperties", "tokens").V().Properties<VertexProperty>().ToList();
329327
foreach (var vp in vps)
330328
{
331329
Assert.NotNull(vp);
332-
// GraphSON will deserialize into null and GraphBinary to []
333-
Assert.True(vp.Properties == null || vp.Properties.Length == 0);
330+
Assert.Empty(vp.Properties);
334331
}
335332
}
336333

337334
[Fact]
338-
public void shouldUseMaterializedPropertiesTokenInPath()
335+
public void ShouldUseMaterializedPropertiesTokenInPath()
339336
{
340337
var connection = _connectionFactory.CreateRemoteConnection();
341338
var g = AnonymousTraversalSource.Traversal().With(connection);
@@ -352,14 +349,13 @@ public void shouldUseMaterializedPropertiesTokenInPath()
352349
Assert.NotNull(b);
353350
Assert.NotNull(c);
354351

355-
// GraphSON will deserialize into null and GraphBinary to []
356-
Assert.True(a.Properties == null || a.Properties.Length == 0);
357-
Assert.True(b.Properties == null || b.Properties.Length == 0);
358-
Assert.True(c.Properties == null || c.Properties.Length == 0);
352+
Assert.Empty(a.Properties);
353+
Assert.Empty(b.Properties);
354+
Assert.Empty(c.Properties);
359355
}
360356

361357
[Fact]
362-
public void shouldMaterializePropertiesAllInPath()
358+
public void ShouldMaterializePropertiesAllInPath()
363359
{
364360
var connection = _connectionFactory.CreateRemoteConnection();
365361
var g = AnonymousTraversalSource.Traversal().With(connection);

gremlin-dotnet/test/Gremlin.Net.UnitTest/Structure/IO/GraphSON/GraphSONReaderTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ public void ShouldDeserializePathFromGraphSON3()
395395
Assert.Equal(new Vertex(5L), readPath[0]);
396396
Assert.Equal(new Vertex(5L), readPath["z"]);
397397
Assert.Single(readPath);
398+
Assert.Empty(readPath[0]!.Properties);
398399
}
399400

400401
[Theory, MemberData(nameof(Versions))]
@@ -459,6 +460,7 @@ public void ShouldDeserializeVertexProperty(int version)
459460
Assert.Equal("aKey", readVertexProperty.Label);
460461
Assert.True(readVertexProperty.Value);
461462
Assert.NotNull(readVertexProperty.Vertex);
463+
Assert.Empty(readVertexProperty.Properties);
462464
}
463465

464466
[Theory, MemberData(nameof(Versions))]
@@ -475,6 +477,7 @@ public void ShouldDeserializeVertexPropertyWithLabel(int version)
475477
Assert.Equal("name", readVertexProperty.Label);
476478
Assert.Equal("marko", readVertexProperty.Value);
477479
Assert.Null(readVertexProperty.Vertex);
480+
Assert.Empty(readVertexProperty.Properties);
478481
}
479482

480483
[Theory, MemberData(nameof(Versions))]
@@ -488,6 +491,7 @@ public void ShouldDeserializeVertex(int version)
488491
var deserializedValue = reader.ToObject(jsonElement);
489492

490493
Assert.Equal(new Vertex(45.23f), deserializedValue);
494+
Assert.Empty(deserializedValue!.Properties);
491495
}
492496

493497
[Theory, MemberData(nameof(Versions))]
@@ -501,6 +505,7 @@ public void ShouldDeserializeVertexWithLabel(int version)
501505
Vertex deserializedValue = reader.ToObject(jsonElement)!;
502506

503507
Assert.Equal("person", deserializedValue.Label);
508+
Assert.Empty(deserializedValue.Properties);
504509
}
505510

506511
[Theory, MemberData(nameof(Versions))]

0 commit comments

Comments
 (0)