QueryIndexAsync rejects a DateTime bound
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
Research direction
Start with CreateIndexKeyFromObject in src/BLite.Core/DynamicCollection.cs and compare its supported bound types with BsonValueToIndexKey and CompareFilter.ToIndexObject, which the issue identifies as the working date conversion paths. Check how the BSON writer handles an unspecified DateTime, then run the DynamicCollection oracle cases in tests/BLite.Tests/Oracles/DynamicDifferentialTests.cs. Done means DateTime and DateTimeOffset bounds return the expected date range results.
Written by the indexing model from the issue text.
Description
DynamicCollection.QueryIndexAsync throws ArgumentException: Cannot create IndexKey from type DateTime for a DateTime (or DateTimeOffset) bound, although the index keys DateTime values and the README shows a date range through it. BLQL on the same index works, because it converts its bounds itself.
Found by the DynamicCollection oracle tests (tests/BLite.Tests/Oracles/DynamicDifferentialTests.cs, PR to follow, stacked on #263), which carry the affected rows (16: indexed/api, both oracles, e.g. when < t5, when >= t10 and < t20, Count(when < t5)) as a known candidate until this is fixed.
Repro
await col.CreateIndexAsync("when"); // m0, m5, m10: t0 plus 0, 5, 10 minutes, stored as DateTime
await col.QueryIndexAsync("idx_when", t0, t0.AddMinutes(5)).ToListAsync();
// expected [m0, m5], actual ArgumentException: Cannot create IndexKey from type DateTime
await col.QueryIndexAsync("idx_when", new DateTimeOffset(t0).ToUnixTimeMilliseconds(),
new DateTimeOffset(t0.AddMinutes(5)).ToUnixTimeMilliseconds()).ToListAsync(); // [m0, m5]
col.Query(BlqlFilter.Lte("when", t0.AddMinutes(5))).ToList(); // [m0, m5], right
Expected: README.md:801 shows a date range on a dynamic index: var recent = orders.QueryIndex("idx_placed_at", minDate, maxDate);.
Mechanism (verified on 0450b97)
CreateIndexKeyFromObject (src/BLite.Core/DynamicCollection.cs:2804-2816) has no DateTime or DateTimeOffset case, although BsonValueToIndexKey keys both as Unix milliseconds in an IndexKey(long) (:2726-2730) and BLQL converts its bounds the same way before calling it (CompareFilter.ToIndexObject, src/BLite.Core/Query/Blql/BlqlFilter.cs:378). A long bound is taken as milliseconds, which works by accident.
Affected versions: since 39e6c89 (v1.4.0). Reproduced on v5.2.3 / 0450b97.
Fix considerations
DateTimeandDateTimeOffsetcases inCreateIndexKeyFromObject, keyed like the stored values (new IndexKey(new DateTimeOffset(d).ToUnixTimeMilliseconds()); theDateTimeKindof an unspecifiedDateTimeshould be treated the way the BSON writer treats it).- The README sample also uses the old synchronous names (
QueryIndex,Near,Within), nowQueryIndexAsync,NearAsync,WithinAsync.
Related: #269 (the decimal and bool bounds that throw in the same switch), #254 (open, the double keys), #140 (closed, DateTimeOffset round-trip).
- Dominant language
- C#
- Stars
- 66
- Forks
- 6
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 43
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from EntglDb/BLite
-
area/linq bug package/core triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
area/indexing bug package/core triage
Difficulty 4/5 3-5 days Newbie friendliness 57/100
Maintainers usually reply within 1 day
-
area/indexing bug package/core triage
Difficulty 5/5 Over a week Newbie friendliness 35/100
Maintainers usually reply within 1 day
-
area/linq bug package/core triage
Difficulty 4/5 1-2 days Newbie friendliness 42/100
Maintainers usually reply within 1 day
-
area/linq bug package/core triage
Difficulty 3/5 1-2 days Newbie friendliness 55/100
Maintainers usually reply within 1 day
Similar issues
-
area: design documentation
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
eyalgolan/statecraft-israel#883 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 3 days
-
enhancement needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
elastic/docs-builder#4495 ·
Maintainers usually reply within 1 day
-
StreamProtoReader pool state corruption after interrupted deserializationPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
protobuf-net/protobuf-net#1375 · 2 comments ·
Maintainers usually reply within 2 days
-
ASP.NET Core container quickstart: `docker-run: debug` task sample is missing its closing braceOpen
Difficulty 1/5 Under an hour Newbie friendliness 88/100
microsoft/vscode-docs#10499 ·
Maintainers usually reply within 1 day