Skip to content

Commit a671601

Browse files
authored
fix: mapping long type into AST (#236)
1 parent 25639c8 commit a671601

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Adds a `Type` overload for POCOs to `QueryAsync`. This will add `object ConvertT
77
1. [#232](https://github.com/influxdata/influxdb-client-csharp/pull/232): Add a `Type` overload for POCOs to `QueryAsync`.
88
1. [#233](https://github.com/influxdata/influxdb-client-csharp/pull/233): Add possibility to follow HTTP redirects
99

10+
### Bug Fixes
11+
1. [#236](https://github.com/influxdata/influxdb-client-csharp/pull/236): Mapping `long` type into Flux AST [LINQ]
12+
1013
## 2.1.0 [2021-08-20]
1114

1215
### Bug Fixes

Client.Linq.Test/DomainObjects.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,9 @@ class TagIsNotDefinedAsString
6969
[Column(IsTimestamp = true)]
7070
public DateTime Timestamp { get; set; }
7171
}
72+
73+
public class DataEntityWithLong
74+
{
75+
public long EndWithTicks { get; set; }
76+
}
7277
}

Client.Linq.Test/InfluxDBQueryVisitorTest.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,35 @@ from s in InfluxDBQueryable<TagIsNotDefinedAsString>.Queryable("my-bucket", "my-
805805
Assert.AreEqual("123456", GetLiteral<StringLiteral>(ast, 3).Value);
806806
}
807807
}
808+
809+
[Test]
810+
public void FilterByLong()
811+
{
812+
var query = from s in InfluxDBQueryable<DataEntityWithLong>.Queryable("my-bucket", "my-org", _queryApi)
813+
where s.EndWithTicks <= 637656739543829486
814+
select s;
815+
var visitor = BuildQueryVisitor(query);
816+
817+
Assert.AreEqual(FluxStart + " |> filter(fn: (r) => (r[\"EndWithTicks\"] <= p3))", visitor.BuildFluxQuery());
818+
819+
var ast = visitor.BuildFluxAST();
820+
821+
Assert.NotNull(ast);
822+
Assert.NotNull(ast.Body);
823+
Assert.AreEqual(3, ast.Body.Count);
824+
825+
var bucketAssignment = ((OptionStatement) ast.Body[0]).Assignment as VariableAssignment;
826+
Assert.AreEqual("p1", bucketAssignment?.Id.Name);
827+
Assert.AreEqual("my-bucket", (bucketAssignment?.Init as StringLiteral)?.Value);
828+
829+
var rangeAssignment = ((OptionStatement) ast.Body[1]).Assignment as VariableAssignment;
830+
Assert.AreEqual("p2", rangeAssignment?.Id.Name);
831+
Assert.AreEqual("0", (rangeAssignment?.Init as IntegerLiteral)?.Value);
832+
833+
var endWithTicksAssignment = ((OptionStatement) ast.Body[2]).Assignment as VariableAssignment;
834+
Assert.AreEqual("p3", endWithTicksAssignment?.Id.Name);
835+
Assert.AreEqual("637656739543829486", (endWithTicksAssignment?.Init as IntegerLiteral)?.Value);
836+
}
808837

809838
private InfluxDBQueryVisitor BuildQueryVisitor(IQueryable queryable, Expression expression = null)
810839
{

Client.Linq/Internal/VariableAggregator.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ internal List<Statement> GetStatements()
4646
{
4747
literal = new IntegerLiteral("IntegerLiteral", Convert.ToString(i));
4848
}
49+
else if (variable.Value is long l)
50+
{
51+
literal = new IntegerLiteral("IntegerLiteral", Convert.ToString(l));
52+
}
4953
else if (variable.Value is bool b)
5054
{
5155
literal = new BooleanLiteral("BooleanLiteral", b);

0 commit comments

Comments
 (0)