Code Monkey home page Code Monkey logo

Comments (9)

bchavez avatar bchavez commented on July 19, 2024

Hello @matija92 , nice to meet you.

Thanks very much for your question. Since we are almost a 1-to-1 port of the Java driver you can use the Java driver's ReQL query documentation as a substitute. In particular, Java's orderBy documentation is here. The only major difference you should notice is lower camelCase vs PascalCase. You'll have to rely on the Java documentation as a substitute for official ReQL Query documentation. I don't personally have enough resources to maintain the driver code and the entire set of ReQL Query documentation at the moment.

The C# Wiki documentation exists here only to highlight differences, offer usage guidance, and detail extended features that go above and beyond the Java driver. Perhaps someday our driver will be adopted as an official driver but until then (if ever) this is just the current state and nature of things.

So, finally, to answer your question:

In JS:

r.table('sometable').orderBy({index:'someindex'})

In C#:

r.Table("sometable").OrderBy().OptArg("index", "someindex")

Should produce the same result. =)

I hope you don't mind, I'm going to close this issue. I would like to keep all the issues related to code changes and/or feature requests. The best place (and fastest way) to get help with ReQL queries is the RethinkDB slack channel here: http://slack.rethinkdb.com. Sign up and ask away! If you don't get an invite quickly, check the spam folder. Also, if nobody can answer your ReQL question you can tag me in your question with "@bchavez" and I'll try to answer it as best as I can when I'm around.

I hope this answers your question. 😎

Thanks,
Brian

from rethinkdb.driver.

matija92 avatar matija92 commented on July 19, 2024

Hello @bchavez ,

Thank you so much for the detailed answer! I didn't know the Java documentation can be used, so this helped me a lot.

Will apply to the slack channel for sure :)

Best regards!
Matija

from rethinkdb.driver.

matija92 avatar matija92 commented on July 19, 2024

Hey @bchavez ,

I have one more short question if you have time. Sorry for asking a lot

So in JS I made this query:
r.db("somedb").table("sometable") .filter(r.row("finishTime").gt(r.time(2016,4,23, 'Z')))

it returned the reults I expected (count: 12691)

In c# I am trying to make the same query:
r.Db("somedb").Table("sometable") .Filter(row => row.G("finishTime").Gt(r.Time(2016, 4, 23, "Z"))).Run<MyModel.Model>(conn);

I am getting only count 8

If I just run

r.Db("builddb").Table("allBuilds") .Filter(row => row["finishTime"].Gt(r.Time(2016, 4, 23, "Z"))).Count().Run(conn);

I get exact number 12691

Do you see any semantic problem here?

Also this instruction returns 16000 which is the exact number of rows in table

r.Db("builddb").Table("allBuilds").Count().Run(conn);

and when I try to fetch them with

r.Db("builddb").Table("allBuilds").Run(conn);

I just get 162 items

Best regards,
Matija

from rethinkdb.driver.

bchavez avatar bchavez commented on July 19, 2024

Hi @matija92 ,

I wish I could help more but it's really hard to understand and explain exactly what's going on without more context information available.

  • What do the C# models look like?
  • What does the surrounding code around the query look like?
  • How are the results used?
  • What does the JSON data look like?
  • What do the protocol traces look like?

All I can say so far is to be somewhat careful with .G and .Bracket -> [""]. I think they have some subtle differences that may be impacting the result count. Second, examine the type returned by .Run more closely. IIRC, the return type for Run is dynamic but what is the real underlying type? Cursor<T>? If it is Cursor<T> you'll want to be careful using any LINQ operation on a Cursor<T>'s IEnumerable since LINQ will automatically call .Dispose after the LINQ operation is done.

Unfortunately, that's about as much as I can glean from your queries. If you'd like more help, you'll need to provide a unit test that can reproduce the problem... or send me the data to run the queries against. If you need to encrypt the data, my GPG key here: bchavez-public.txt

There is always the possibility of a bug 🪲 somewhere but I wont be able to make any fixes until I have a concrete understanding of what's going under the hood and able to reproduce the issue.

Hope this helps,
Brian

from rethinkdb.driver.

matija92 avatar matija92 commented on July 19, 2024

Hey @bchavez ,

Sorry for answering a bit late.

Interestingly I resolved the issue by just going in a forEach loop. So when I get the results back the count is 162, but when I go in a forEach loop it actually goes through all results with the correct number of items. So actually I resolved the issue just by copying the results in a new List from the loop.

Also, I am currently fiddling with the changes() function, and it seems to me it's only feeding me the actual inserts while the replaced items are not pushed to the feed. Is there an additional parameter I should add when creating the change feed so that I also receive the replaced items? I always get an object with a old_value set to null even though the actual insert triggers replace sometimes.

Best regards,
Matija

from rethinkdb.driver.

bchavez avatar bchavez commented on July 19, 2024

Hi @matija92 ,

Re: Cursor

Yeah, that behavior sounds about right. You'll want to be especially careful with the Cursor object and how you count cursor items. Just remember, a Cursor is a cursor into your data. The smaller number you were seeing was probably the current number of buffered items inside the Cursor. Imagine a world without Cursor and a query that returned 15 million items all at once. 💥 We'd probably have the GC explode, OutOfMemoryExceptions, and severe performance issues 😎.

If you are using the synchronous API, you should be able to do .ToList() on a strongly typed Cursor<T> instead of individually adding items to a list in a foreach loop. Just remember, that once .ToList() is done, the Cursor object cannot be reused to reiterate over the items already iterated over.

Re: Changes()

As far as I know, you should be able to get changes on updated items too. But again, I would need context in order to offer more help regarding the Changes() query. The query itself, the data, the data models, the surrounding code, and the protocol traces. Or a unit test I can run that can reproduce the issue you're seeing. Without contextual information there isn't much I can do. 🐰

Hope this helps,
Brian

from rethinkdb.driver.

matija92 avatar matija92 commented on July 19, 2024

Hey @bchavez ,

Well the Cursor story perfectly makes sense :) Thanks for helping me out with that.

As for the changes I will try to give you the necessary information here, and if you can make out something of it great, if not no worries! 💃

So the idea is I have a table with some build information, and I am querying the builds that finished in the last day, by using the Changes() function. I also have the model of the data as a POCO.

The model class looks like this:

public class Drop
        {
            public string location { get; set; }
            public string type { get; set; }
            public string url { get; set; }
            public string downloadUrl { get; set; }
        }

        public class Log
        {
            public string type { get; set; }
            public string url { get; set; }
            public string downloadUrl { get; set; }
        }

        public class LastChangedBy
        {
            public string id { get; set; }
            public string displayName { get; set; }
            public string uniqueName { get; set; }
            public string url { get; set; }
            public string imageUrl { get; set; }
        }

        public class Definition
        {
            public string definitionType { get; set; }
            public int id { get; set; }
            public string name { get; set; }
            public string url { get; set; }
        }

        public class Queue
        {
            public string queueType { get; set; }
            public int id { get; set; }
            public string name { get; set; }
            public string url { get; set; }
        }

        public class RequestedFor
        {
            public string id { get; set; }
            public string displayName { get; set; }
            public string uniqueName { get; set; }
            public string url { get; set; }
            public string imageUrl { get; set; }
            public bool? isContainer { get; set; }
        }

        public class Request
        {
            public int id { get; set; }
            public string url { get; set; }
            public RequestedFor requestedFor { get; set; }
        }

        public class Value
        {
            public string uri { get; set; }
            public int id { get; set; }
            public string buildNumber { get; set; }
            public string url { get; set; }
            public DateTimeOffset startTime { get; set; }
            public DateTimeOffset finishTime { get; set; }
            public string reason { get; set; }
            public string status { get; set; }
            public string dropLocation { get; set; }
            public Drop drop { get; set; }
            public Log log { get; set; }
            public string sourceGetVersion { get; set; }
            public LastChangedBy lastChangedBy { get; set; }
            public bool retainIndefinitely { get; set; }
            public bool hasDiagnostics { get; set; }
            public Definition definition { get; set; }
            public Queue queue { get; set; }
            public List<Request> requests { get; set; }
        }

The inserting of the data is done by this function:

var stats = r.Db("builddb")
.Table("allBuilds")
.Insert(root.value.ToList<RecentBuildsModel.Value>()[new { conflict = "update"}]
.Run(conn);

I get good response from the insert query, usually it says it replaces and inserts as it should.

Now this is the function with which I am listening for changes:

var feed = r.Db("builddb")
 .Table("allBuilds")
 .Filter(row => row["finishTime"].Gt(r.Time(daysAgo.Year, daysAgo.Month, daysAgo.Day, "Z")))
 .Changes().RunChangesAsync<RecentBuildsModel.Value>(conn);

foreach (var build in await feed)
       hub.Clients.All.updateRecentData(build);

I am actually using signalR to broadcast to all clients. So the problem is the build object from the feed is returned with the old_val = null even though the insert query generates some replaces.

I hope this is enough info for you, just to get a sense of what's going on :)

Best regards,
Matija

from rethinkdb.driver.

matija92 avatar matija92 commented on July 19, 2024

@bchavez I managed to fix the issue, it was a mistake I overlooked.

The builds that can be updated will always have finishTime 01.01.0001 01:01 because they have not finished yet. Because of this my Change() query is actually never getting these entries (I am only querying for the dates larger then some date). Since all the other builds have a normal finishTime these entries will never be updated because they are finished

Thanks for all the help :D

from rethinkdb.driver.

bchavez avatar bchavez commented on July 19, 2024

@matija92 I'm glad you found the problem. 👍

Only one suggestion. To me it seems a bit awkward to await in foreach( var build in await feed). IIRC, the compiler indeed does the right thing and seems semantically okay on the surface. However, technically, the CLR is actually _blocking_ on .MoveNext in the Cursor<T> enumeration, not necessarily awaiting on the feed. The await is really awaiting on the construction of the Cursor<T> object, not necessarily each item in the feed itself. So, the following would be slightly better in showing the real mechanics of what's happening:

var query = r.Db("builddb")
 .Table("allBuilds")
 .Filter(....)
 .Changes();

var feed = await query.RunChangesAsync<RecentBuildsModel.Value>(conn);

foreach( var change in feed ){
    hub.Clients.All.updateRecentData(change);
}

I know the RethinkDB team used foreach(var change in await feed) like this in their introductory blog post about the driver. Unfortunately, I asked for the corrections but the update never happened. Maybe it's just me but it makes me cringe just a little bit every time I see it.

Reference:
C# Driver Wiki: Consuming Changefeeds

from rethinkdb.driver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.