Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
NguyenHoangSon96 committed Dec 9, 2024
1 parent 3d8614c commit 4cc8d6b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
17 changes: 13 additions & 4 deletions Client.Test/Internal/TypeCastTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,22 @@ public void GetMappedValue()
Assert.That(TypeCasting.GetMappedValue(field, 10)!, Is.EqualTo(10));
});

// Field without metadata case
field = new Field(fieldName, Int64Type.Default, true);
Assert.That(TypeCasting.GetMappedValue(field, 1)!, Is.EqualTo(1));

// Assert.That(TypeCasting.GetMappedValue(field, )!, Is.EqualTo("a"));
field = GenerateIntFieldNullTypeMeta(fieldName);
Assert.That(TypeCasting.GetMappedValue(field, 1)!, Is.EqualTo(1));
}

private static Field GenerateIntFieldNullTypeMeta(string fieldName)
{
var meta = new Dictionary<string, string>
{
{
"iox::column::type", null
}
};
return new Field(fieldName, Int64Type.Default, true, meta);
}

private static Field GenerateIntField(string fieldName)
{
var meta = new Dictionary<string, string>
Expand Down
14 changes: 9 additions & 5 deletions Client/InfluxDBClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Threading;
using System.Threading.Tasks;
using Apache.Arrow;
using Apache.Arrow.Types;
using InfluxDB3.Client.Config;
using InfluxDB3.Client.Internal;
using InfluxDB3.Client.Query;
Expand Down Expand Up @@ -467,9 +466,17 @@ public InfluxDBClient() : this(
for (var j = 0; j < columnCount; j++)
{
if (batch.Column(j) is not ArrowArray array) continue;
var value = array.GetObjectValue(i);
if (value is null)
{
row[j] = null;
continue;

Check warning on line 473 in Client/InfluxDBClient.cs

View check run for this annotation

Codecov / codecov/patch

Client/InfluxDBClient.cs#L472-L473

Added lines #L472 - L473 were not covered by tests
}

row[j] = TypeCasting.GetMappedValue(
batch.Schema.FieldsList[j],
array.GetObjectValue(i));
value
);
}

yield return row;
Expand Down Expand Up @@ -567,9 +574,6 @@ public async IAsyncEnumerable<PointDataValues> QueryPoints(string query, QueryTy
var valueType = parts[2];
// string fieldType = parts.Length > 3 ? parts[3] : "";
var mappedValue = TypeCasting.GetMappedValue(schema, objectValue);
if (mappedValue is null)
continue;

if (valueType == "field")
{
point = point.SetField(fullName, mappedValue);
Expand Down
8 changes: 1 addition & 7 deletions Client/Internal/TypeCasting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Diagnostics;
using System.Numerics;
using Apache.Arrow;
using Apache.Arrow.Types;

namespace InfluxDB3.Client.Internal;

Expand All @@ -14,13 +13,8 @@ public class TypeCasting
/// <param name="field">The Field object from Arrow</param>
/// <param name="value">The value to cast</param>
/// <returns>The value with the correct type</returns>
public static object? GetMappedValue(Field field, object? value)
public static object GetMappedValue(Field field, object value)
{
if (value is null)
{
return null;
}

var fieldName = field.Name;
if (fieldName is "measurement" or "iox::measurement")
{
Expand Down

0 comments on commit 4cc8d6b

Please sign in to comment.