This is an automated email from the ASF dual-hosted git repository.

Cole-Greer pushed a commit to branch 3.7-dev
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/3.7-dev by this push:
     new fd25c7727b Preserve float type in DotNetTranslator (#3567)
fd25c7727b is described below

commit fd25c7727b0d527aa37ba8f3e40c26295751935f
Author: kirill-stepanishin <[email protected]>
AuthorDate: Mon Jul 27 12:04:35 2026 -0700

    Preserve float type in DotNetTranslator (#3567)
    
    Assisted-by: Claude Code:claude-opus-4-8
---
 .../gremlin/process/traversal/translator/DotNetTranslator.java |  4 ++++
 .../process/traversal/translator/DotNetTranslatorTest.java     | 10 ++++++++++
 .../Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs   |  3 +--
 .../test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs        |  2 +-
 .../Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs     |  8 +-------
 5 files changed, 17 insertions(+), 10 deletions(-)

diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslator.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslator.java
index 7754b13838..fc6f2cb980 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslator.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslator.java
@@ -197,6 +197,10 @@ public final class DotNetTranslator implements 
Translator.ScriptTranslator {
                     return (o instanceof Float ? "Single" : "Double") + 
".PositiveInfinity";
                 if (NumberHelper.isNegativeInfinity(o))
                     return (o instanceof Float ? "Single" : "Double") + 
".NegativeInfinity";
+                // a bare decimal literal is a double in C#, so a float needs 
an explicit suffix to
+                // preserve its type through translation
+                if (o instanceof Float)
+                    return o + "f";
             }
             return o.toString();
         }
diff --git 
a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslatorTest.java
 
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslatorTest.java
index 798378f905..cf59e623a7 100644
--- 
a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslatorTest.java
+++ 
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/translator/DotNetTranslatorTest.java
@@ -112,6 +112,16 @@ public class DotNetTranslatorTest {
         assertEquals("g.V().Values<object>(\"age\").Inject(null,null)", 
script);
     }
 
+    @Test
+    public void shouldTranslateFloatingPointLiterals() {
+        // a float needs an explicit suffix so it is not read back as a 
double, while a double
+        // is the default type for a bare decimal literal in C# and needs no 
suffix
+        assertEquals("g.Inject(0.5f)",
+                
translator.translate(g.inject(0.5f).asAdmin().getBytecode()).getScript());
+        assertEquals("g.Inject(0.5)",
+                
translator.translate(g.inject(0.5d).asAdmin().getBytecode()).getScript());
+    }
+
     @Test
     public void shouldTranslateGroup() {
         final String script = 
translator.translate(g.V().group("x").group().by("name").asAdmin().getBytecode()).getScript();
diff --git 
a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs 
b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
index 1d5199e377..5462260cff 100644
--- 
a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
+++ 
b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs
@@ -49,8 +49,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
             {
                 // Add here the name of scenarios to ignore and the reason, 
e.g.:
                 {"g_withStrategiesXProductiveByStrategyX_V_group_byXageX", 
IgnoreReason.NullKeysInMapNotSupported},
-                
{"g_withStrategiesXProductiveByStrategyX_V_groupCount_byXageX", 
IgnoreReason.NullKeysInMapNotSupported},
-                {"g_injectXpoint5fX", 
IgnoreReason.FloatLiteralTypeNotPreserved}
+                
{"g_withStrategiesXProductiveByStrategyX_V_groupCount_byXageX", 
IgnoreReason.NullKeysInMapNotSupported}
             };
 
         private static class Keywords
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs 
b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
index 73378300f4..fe51031bab 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/Gremlin.cs
@@ -1540,7 +1540,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
                {"g_injectX1_3lX_injectX100_300X", new 
List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> 
{(g,p) =>g.Inject(1,3).Inject(100,300)}}, 
                {"g_injectXbigintBoundaryValuesX", new 
List<Func<GraphTraversalSource, IDictionary<string, object>, ITraversal>> 
{(g,p) =>g.Inject(p["xx1"],p["xx2"],p["xx3"])}}, 
                {"g_injectXpoint5X", new List<Func<GraphTraversalSource, 
IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject(0.5)}}, 
-               {"g_injectXpoint5fX", new List<Func<GraphTraversalSource, 
IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject(0.5)}}, 
+               {"g_injectXpoint5fX", new List<Func<GraphTraversalSource, 
IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject(0.5f)}}, 
                {"g_injectXpoint5dX", new List<Func<GraphTraversalSource, 
IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject(0.5)}}, 
                {"g_injectX1to5X", new List<Func<GraphTraversalSource, 
IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject(new List<object> 
{1, 2, 3, 4, 5})}}, 
                {"g_injectXaTocX", new List<Func<GraphTraversalSource, 
IDictionary<string, object>, ITraversal>> {(g,p) =>g.Inject(new List<object> 
{"a", "b", "c"})}}, 
diff --git 
a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs 
b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs
index feafc86bf3..3eb59d4f57 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs
@@ -60,12 +60,6 @@ namespace Gremlin.Net.IntegrationTest.Gherkin
         /// <summary>
         /// The GLV suite does not test against a graph that has null property 
values enabled.
         /// </summary>
-        NullPropertyValuesNotSupportedOnTestGraph,
-
-        /// <summary>
-        /// The translator does not preserve the numeric type of a float 
literal, so a value such as
-        /// <c>.5f</c> is emitted as a bare <c>0.5</c> and read back as a 
<c>double</c> rather than a <c>float</c>.
-        /// </summary>
-        FloatLiteralTypeNotPreserved
+        NullPropertyValuesNotSupportedOnTestGraph
     }
 }
\ No newline at end of file

Reply via email to