Possible C# client escaping bug in @in<> query (m-reduce index)

ยอดดู 49 ครั้ง
ข้ามไปที่ข้อความที่ยังไม่อ่านรายการแรก

Antoine

ยังไม่อ่าน,
29 พ.ย. 2560 12:20:2729/11/60
ถึง RavenDB - 2nd generation document database
On the client side (3.5.4), I've got this query:

            var query = this.Query<VCPCoverageIndex.Projection, VCPCoverageIndex>();

            if (filter != null && filter.CIds != null) // string[] CIds
            {
                query = query.Where(x => x.CId.In(filter.CIds));
            }

            if (filter != null && filter.Batches != null) // string[] Batches
            {
                query = query.Where(x => x.Batch.In(filter.Batches));
            }

            return query;

Which becomes:

            ( @in<CId>:(VC\-97) ) AND ( @in<Batch>:(2017\-11\-23T21\:34\:35.6870721Z) )

Zero results are given. If I change the query like that:

            ( ( @in<CId>: (VC-97) ) AND   @in<Batch>: (2017-11-23T21:34:35.6870721Z) )

it works... It looks like the client library is escaping dashes and semicolons within the parentheses and RavenDB doesn't like that.

Am I doing something wrong?

The index:

    public sealed class VCPCoverageIndex : AbstractIndexCreationTask<VST, VCPCoverageIndex.Projection>
    {
        public VCPCoverageIndex()
        {
            this.Map = docs =>
                from d in docs
                select new Projection
                {
                    CId = d.CId,
                    ProviderId = d.ProviderId,
                    Batch = d.DateCreatedUtc.ToString("o"),

                    StatusPending = d.Status == VSTStatus.Pending ? 1 : 0,
                    StatusDone = d.Status == VSTStatus.Done ? 1 : 0,
                    StatusFailed = d.Status == VSTStatus.Failed ? 1 : 0,
                };
            this.Reduce = results =>
                from r in results
                group r by new
                {
                    r.CId,
                    r.ProviderId,
                    r.Batch,
                } into g
                select new Projection
                {
                    CId = g.Key.CId,
                    ProviderId = g.Key.ProviderId,
                    Batch = g.Key.Batch,

                    StatusPending = g.Sum(x => x.StatusPending),
                    StatusDone = g.Sum(x => x.StatusDone),
                    StatusFailed = g.Sum(x => x.StatusFailed),
                };
        }

        public class Projection
        {
            public string CId { get; set; }

            public string ProviderId { get; set; }

            public string Batch { get; set; }

            public int StatusPending { get; set; }

            public int StatusDone { get; set; }

            public int StatusFailed { get; set; }
        }


Antoine

ยังไม่อ่าน,
29 พ.ย. 2560 12:34:0229/11/60
ถึง RavenDB - 2nd generation document database
This issue might be related to the following ticket.

http://issues.ravendb.net/issue/RavenDB-4711  "@In queries need to un escape even when qouted"

Oren Eini (Ayende Rahien)

ยังไม่อ่าน,
30 พ.ย. 2560 03:50:2130/11/60
ถึง ravendb
IIRC, we fixed something similar recently. Can you check the latest client?

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Antoine

ยังไม่อ่าน,
4 ธ.ค. 2560 04:07:114/12/60
ถึง RavenDB - 2nd generation document database
Hello,

I installed the 3.5.5-patch-35241 client and the problem is still there.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.

Oren Eini (Ayende Rahien)

ยังไม่อ่าน,
4 ธ.ค. 2560 07:39:424/12/60
ถึง ravendb
Hi,
Please try this. Instead:

                    Batch = d.DateCreatedUtc.ToString("o"),

Do:
                    Batch = d.DateCreatedUtc,

And that should resolve it.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Antoine

ยังไม่อ่าน,
5 ธ.ค. 2560 07:06:075/12/60
ถึง RavenDB - 2nd generation document database
Hello,

For a unknown reason, your code makes the query work. However:

0. A batch in my context is a set of objects produced in a common context and at point in time.

I need something to keep those objects together. A Guid is not sortable, a DateTime("o") is perfect for me.
You noticed that I use the DateCreatedUtc field to represent the batch id. That seems logical because of the fact (0).

1. The Batch property needs to be a string.

Having a DateTime is dangerous because of error-prone conversions between the string form and the DateTime form. I want the date of my "batch" to be the unique id of this batch. In many projects, an id is always of the same form; when using ravendb, any id should be a string.
This concept looks perfectly acceptable from many point of views.

2. The map method of an index can transform fields from the document. The three status fields don't exist in the document; the map methods allows me to do whatever I want.
I think any RavenDB user knows that. I also hope I'm right.
The reduce part of this index shows me the various batches that exist, that is what I want.

3. It looks like black magic forbids me from using the field as a string.
I need to understand why I cannot map the field as a string?
Not understanding that would mean I'm using a magic tool and I can't take it.

The pseudo-trick (2) I am doing looks OK to me. The anti-trick you suggest is a problem for me because of (1).
If raven can't do this simple thing, the option I will choose will be to create a field in my document "string Batch { get { DateCreatedUtc.ToString("o") } }" but that looks silly knowing that both fields will be stored as a JSON string.

Unless there is an acceptable explanation, I believe this is a bug. Can you elaborate on that?

Thanks.

Oren Eini (Ayende Rahien)

ยังไม่อ่าน,
5 ธ.ค. 2560 07:15:105/12/60
ถึง ravendb
The actual problem is there because you are using dates in two different ways.
First, you are storing dates using .ToString("O").
This causes RavenDB to treat it as a string, so it does the usual case insensitive store.
But you are querying that using a date time, which use a case sensitive match, and fails. 

Try to make sure that both are always the same type
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
ตอบทุกคน
ตอบกลับผู้สร้าง
ส่งต่อ
ข้อความใหม่ 0 รายการ