-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: respect iox::column_type::field metadata when mapping query (#132)
- Loading branch information
1 parent
115c12d
commit 41045ca
Showing
12 changed files
with
460 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using Apache.Arrow; | ||
using Apache.Arrow.Types; | ||
using InfluxDB3.Client.Internal; | ||
using InfluxDB3.Client.Write; | ||
|
||
namespace InfluxDB3.Client.Test.Internal; | ||
|
||
public class RecordBatchConverterTest | ||
{ | ||
[Test] | ||
public void ConvertToPointDataValue() | ||
{ | ||
Schema schema; | ||
RecordBatch recordBatch; | ||
PointDataValues point; | ||
|
||
var stringField = new Field("measurement", StringType.Default, true); | ||
var stringArray = new StringArray.Builder().Append("host").Build(); | ||
schema = new Schema(new[] { stringField, }, null); | ||
recordBatch = new RecordBatch(schema, new[] { stringArray }, 1); | ||
point = RecordBatchConverter.ConvertToPointDataValue(recordBatch, 0); | ||
Assert.That(point.GetMeasurement(), Is.EqualTo("host")); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
var now = new DateTimeOffset(); | ||
|
||
var timeField = new Field("time", TimestampType.Default, true); | ||
var timeArray = new TimestampArray.Builder().Append(now).Build(); | ||
schema = new Schema(new[] { timeField, }, null); | ||
recordBatch = new RecordBatch(schema, new[] { timeArray }, 1); | ||
|
||
point = RecordBatchConverter.ConvertToPointDataValue(recordBatch, 0); | ||
Assert.That(point.GetTimestamp(), Is.EqualTo(TimestampConverter.GetNanoTime(now.UtcDateTime))); | ||
|
||
timeField = new Field("test", TimestampType.Default, true); | ||
schema = new Schema(new[] { timeField, }, null); | ||
recordBatch = new RecordBatch(schema, new[] { timeArray }, 1); | ||
point = RecordBatchConverter.ConvertToPointDataValue(recordBatch, 0); | ||
Assert.That(point.GetField("test"), Is.EqualTo(now)); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Numerics; | ||
using InfluxDB3.Client.Internal; | ||
|
||
namespace InfluxDB3.Client.Test.Internal; | ||
|
||
public class TimestampConverterTest | ||
{ | ||
private static readonly DateTime EpochStart = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); | ||
|
||
[Test] | ||
public void GetNanoTime() | ||
{ | ||
var now = DateTime.Now; | ||
|
||
var localTime = DateTime.SpecifyKind(now, DateTimeKind.Local); | ||
var timestamp = TimestampConverter.GetNanoTime(localTime); | ||
BigInteger nanoTime = now.ToUniversalTime().Subtract(EpochStart).Ticks * 100; | ||
Assert.That(nanoTime, Is.EqualTo(timestamp)); | ||
|
||
var unspecifiedTime = DateTime.SpecifyKind(now, DateTimeKind.Unspecified); | ||
timestamp = TimestampConverter.GetNanoTime(unspecifiedTime); | ||
nanoTime = DateTime.SpecifyKind(now, DateTimeKind.Utc).Subtract(EpochStart).Ticks * 100; | ||
Assert.That(nanoTime, Is.EqualTo(timestamp)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
using System.Collections.Generic; | ||
using Apache.Arrow; | ||
using Apache.Arrow.Types; | ||
using InfluxDB3.Client.Internal; | ||
|
||
namespace InfluxDB3.Client.Test.Internal; | ||
|
||
public class TypeCastTest | ||
{ | ||
[Test] | ||
public void IsNumber() | ||
{ | ||
Assert.Multiple(() => | ||
{ | ||
Assert.That(TypeCasting.IsNumber(1), Is.True); | ||
Assert.That(TypeCasting.IsNumber(1.2), Is.True); | ||
Assert.That(TypeCasting.IsNumber(-1.2), Is.True); | ||
}); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
Assert.That(TypeCasting.IsNumber('1'), Is.False); | ||
Assert.That(TypeCasting.IsNumber('a'), Is.False); | ||
Assert.That(TypeCasting.IsNumber(true), Is.False); | ||
Assert.That(TypeCasting.IsNumber(null), Is.False); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void GetMappedValue() | ||
{ | ||
// If pass the correct value type to GetMappedValue() it will return the value with a correct type | ||
// If pass the incorrect value type to GetMappedValue() it will NOT throws any error but return the passed value | ||
const string fieldName = "test"; | ||
|
||
var field = GenerateIntField(fieldName); | ||
Assert.Multiple(() => | ||
{ | ||
Assert.That(TypeCasting.GetMappedValue(field, 1)!, Is.EqualTo(1)); | ||
Assert.That(TypeCasting.GetMappedValue(field, "a")!, Is.EqualTo("a")); | ||
}); | ||
|
||
field = GenerateUIntField(fieldName); | ||
Assert.Multiple(() => | ||
{ | ||
Assert.That(TypeCasting.GetMappedValue(field, 1)!, Is.EqualTo(1)); | ||
Assert.That(TypeCasting.GetMappedValue(field, -1)!, Is.EqualTo(-1)); | ||
Assert.That(TypeCasting.GetMappedValue(field, "a")!, Is.EqualTo("a")); | ||
}); | ||
|
||
field = GenerateDoubleField(fieldName); | ||
Assert.Multiple(() => | ||
{ | ||
Assert.That(TypeCasting.GetMappedValue(field, 1.2)!, Is.EqualTo(1.2)); | ||
Assert.That(TypeCasting.GetMappedValue(field, "a")!, Is.EqualTo("a")); | ||
}); | ||
|
||
field = GenerateBooleanField(fieldName); | ||
Assert.Multiple(() => | ||
{ | ||
Assert.That(TypeCasting.GetMappedValue(field, true)!, Is.EqualTo(true)); | ||
Assert.That(TypeCasting.GetMappedValue(field, 10)!, Is.EqualTo(10)); | ||
}); | ||
|
||
field = GenerateStringField(fieldName); | ||
Assert.Multiple(() => | ||
{ | ||
Assert.That(TypeCasting.GetMappedValue(field, "a")!, Is.EqualTo("a")); | ||
Assert.That(TypeCasting.GetMappedValue(field, 10)!, Is.EqualTo(10)); | ||
}); | ||
|
||
|
||
field = GenerateIntFieldTestTypeMeta(fieldName); | ||
Assert.That(TypeCasting.GetMappedValue(field, 1)!, Is.EqualTo(1)); | ||
} | ||
|
||
private static Field GenerateIntFieldTestTypeMeta(string fieldName) | ||
{ | ||
var meta = new Dictionary<string, string> | ||
{ | ||
{ | ||
"iox::column::type", "iox::column_type::field::test" | ||
} | ||
}; | ||
return new Field(fieldName, Int64Type.Default, true, meta); | ||
} | ||
|
||
private static Field GenerateIntField(string fieldName) | ||
{ | ||
var meta = new Dictionary<string, string> | ||
{ | ||
{ | ||
"iox::column::type", "iox::column_type::field::integer" | ||
} | ||
}; | ||
return new Field(fieldName, Int64Type.Default, true, meta); | ||
} | ||
|
||
private static Field GenerateUIntField(string fieldName) | ||
{ | ||
var meta = new Dictionary<string, string> | ||
{ | ||
{ | ||
"iox::column::type", "iox::column_type::field::uinteger" | ||
} | ||
}; | ||
return new Field(fieldName, UInt64Type.Default, true, meta); | ||
} | ||
|
||
private static Field GenerateDoubleField(string fieldName) | ||
{ | ||
var meta = new Dictionary<string, string> | ||
{ | ||
{ | ||
"iox::column::type", "iox::column_type::field::float" | ||
} | ||
}; | ||
return new Field(fieldName, DoubleType.Default, true, meta); | ||
} | ||
|
||
private static Field GenerateBooleanField(string fieldName) | ||
{ | ||
var meta = new Dictionary<string, string> | ||
{ | ||
{ | ||
"iox::column::type", "iox::column_type::field::boolean" | ||
} | ||
}; | ||
return new Field(fieldName, BooleanType.Default, true, meta); | ||
} | ||
|
||
private static Field GenerateStringField(string fieldName) | ||
{ | ||
var meta = new Dictionary<string, string> | ||
{ | ||
{ | ||
"iox::column::type", "iox::column_type::field::string" | ||
} | ||
}; | ||
return new Field(fieldName, StringType.Default, true, meta); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.