Skip to content

Commit b48147e

Browse files
author
Kosta Panic
committed
Fixed DateTimeOffset filter in Qdrant connector
1 parent 2d64013 commit b48147e

2 files changed

Lines changed: 41 additions & 10 deletions

File tree

dotnet/src/VectorData/Qdrant/QdrantFilterTranslator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ bool TryProcessComparison(Expression first, Expression second, [NotNullWhen(true
133133
Key = property.StorageName,
134134
DatetimeRange = new DatetimeRange
135135
{
136-
Gt = Timestamp.FromDateTimeOffset(v),
137-
Gte = Timestamp.FromDateTimeOffset(v),
138-
Lt = Timestamp.FromDateTimeOffset(v),
139-
Lte = Timestamp.FromDateTimeOffset(v)
136+
Gt = comparison.NodeType == ExpressionType.GreaterThan ? Timestamp.FromDateTimeOffset(v) : null,
137+
Gte = comparison.NodeType == ExpressionType.GreaterThanOrEqual ? Timestamp.FromDateTimeOffset(v) : null,
138+
Lt = comparison.NodeType == ExpressionType.LessThan ? Timestamp.FromDateTimeOffset(v) : null,
139+
Lte = comparison.NodeType == ExpressionType.LessThanOrEqual ? Timestamp.FromDateTimeOffset(v) : null
140140
}
141141
},
142142

dotnet/test/VectorData/VectorData.ConformanceTests/Filter/BasicFilterTests.cs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,30 @@ public virtual Task LessThanOrEqual_with_int()
217217
r => r.Int <= 10,
218218
r => (int)r["Int"] <= 10);
219219

220+
[ConditionalFact]
221+
public virtual Task GreaterThan_with_DateTimeOffset()
222+
=> this.TestFilterAsync(
223+
r => r.DateTimeOffset > new DateTimeOffset(2025, 1, 1, 0, 0, 0, TimeSpan.Zero),
224+
r => (DateTimeOffset)r["DateTimeOffset"] > new DateTimeOffset(2025, 1, 1, 0, 0, 0, TimeSpan.Zero));
225+
226+
[ConditionalFact]
227+
public virtual Task GreaterThanOrEqual_with_DateTimeOffset()
228+
=> this.TestFilterAsync(
229+
r => r.DateTimeOffset >= new DateTimeOffset(2025, 1, 1, 0, 0, 0, TimeSpan.Zero),
230+
r => (DateTimeOffset)r["DateTimeOffset"] >= new DateTimeOffset(2025, 1, 1, 0, 0, 0, TimeSpan.Zero));
231+
232+
[ConditionalFact]
233+
public virtual Task LessThan_with_DateTimeOffset()
234+
=> this.TestFilterAsync(
235+
r => r.DateTimeOffset < new DateTimeOffset(2025, 1, 1, 0, 0, 0, TimeSpan.Zero),
236+
r => (DateTimeOffset)r["DateTimeOffset"] < new DateTimeOffset(2025, 1, 1, 0, 0, 0, TimeSpan.Zero));
237+
238+
[ConditionalFact]
239+
public virtual Task LessThanOrEqual_with_DateTimeOffset()
240+
=> this.TestFilterAsync(
241+
r => r.DateTimeOffset <= new DateTimeOffset(2025, 1, 1, 0, 0, 0, TimeSpan.Zero),
242+
r => (DateTimeOffset)r["DateTimeOffset"] <= new DateTimeOffset(2025, 1, 1, 0, 0, 0, TimeSpan.Zero));
243+
220244
#endregion Comparison
221245

222246
#region Logical operators
@@ -550,6 +574,7 @@ public class FilterRecord
550574
public int Int2 { get; set; }
551575
public string[] StringArray { get; set; } = null!;
552576
public List<string> StringList { get; set; } = null!;
577+
public DateTimeOffset DateTimeOffset { get; set; }
553578
}
554579

555580
public abstract class Fixture : VectorStoreCollectionFixture<TKey, FilterRecord>
@@ -594,7 +619,8 @@ public override VectorStoreCollectionDefinition CreateRecordDefinition()
594619
new VectorStoreDataProperty(nameof(FilterRecord.Bool), typeof(bool)) { IsIndexed = true },
595620
new VectorStoreDataProperty(nameof(FilterRecord.Int2), typeof(int)) { IsIndexed = true },
596621
new VectorStoreDataProperty(nameof(FilterRecord.StringArray), typeof(string[])) { IsIndexed = true },
597-
new VectorStoreDataProperty(nameof(FilterRecord.StringList), typeof(List<string>)) { IsIndexed = true }
622+
new VectorStoreDataProperty(nameof(FilterRecord.StringList), typeof(List<string>)) { IsIndexed = true },
623+
new VectorStoreDataProperty(nameof(FilterRecord.DateTimeOffset), typeof(DateTimeOffset)) { IsIndexed = true }
598624
]
599625
};
600626

@@ -611,7 +637,8 @@ protected override List<FilterRecord> BuildTestData()
611637
Int2 = 80,
612638
StringArray = ["x", "y"],
613639
StringList = ["x", "y"],
614-
Vector = this.GetVector(3)
640+
Vector = this.GetVector(3),
641+
DateTimeOffset = new DateTimeOffset(2025, 1, 1, 0, 0, 0, new TimeSpan(1, 0, 0))
615642
},
616643
new()
617644
{
@@ -622,7 +649,8 @@ protected override List<FilterRecord> BuildTestData()
622649
Int2 = 90,
623650
StringArray = ["a", "b"],
624651
StringList = ["a", "b"],
625-
Vector = this.GetVector(3)
652+
Vector = this.GetVector(3),
653+
DateTimeOffset = new DateTimeOffset(2024, 12, 31, 23, 0, 0, TimeSpan.Zero)
626654
},
627655
new()
628656
{
@@ -633,7 +661,8 @@ protected override List<FilterRecord> BuildTestData()
633661
Int2 = 9,
634662
StringArray = ["x"],
635663
StringList = ["x"],
636-
Vector = this.GetVector(3)
664+
Vector = this.GetVector(3),
665+
DateTimeOffset = new DateTimeOffset(2024, 12, 31, 23, 0, 0, new TimeSpan(-1, 0, 0))
637666
},
638667
new()
639668
{
@@ -644,7 +673,8 @@ protected override List<FilterRecord> BuildTestData()
644673
Int2 = 100,
645674
StringArray = ["x", "y", "z"],
646675
StringList = ["x", "y", "z"],
647-
Vector = this.GetVector(3)
676+
Vector = this.GetVector(3),
677+
DateTimeOffset = new DateTimeOffset(2025, 1, 1, 0, 0, 0, TimeSpan.Zero)
648678
},
649679
new()
650680
{
@@ -655,7 +685,8 @@ protected override List<FilterRecord> BuildTestData()
655685
Int2 = 101,
656686
StringArray = ["y", "z"],
657687
StringList = ["y", "z"],
658-
Vector = this.GetVector(3)
688+
Vector = this.GetVector(3),
689+
DateTimeOffset = new DateTimeOffset(2025, 1, 1, 1, 0, 1, new TimeSpan(1, 0, 0))
659690
}
660691
];
661692
}

0 commit comments

Comments
 (0)