Giter Club home page Giter Club logo

Comments (2)

deontologician avatar deontologician commented on May 18, 2024

I think ReqlExpr is the right place to define them, that's basically what
the other drivers do

On Tue, Nov 3, 2015, 09:38 Brian Chavez [email protected] wrote:

In Josh's talk about the Java driver, there's a mention that Java doesn't
support operator overloading.
https://www.youtube.com/watch?v=emjzNpKoNkM#t=16m53s

C# can support method overloading, seems like there's a lot we can do here
with C#'s method overloads.

Some inspection on the Python driver:

class RqlQuery(object):
....
# The following are all operators and methods that operate on
# Rql queries to build up more complex operations

# Comparison operators
def __eq__(self, other):
    return Eq(self, other)

def __ne__(self, other):
    return Ne(self, other)

def __lt__(self, other):
    return Lt(self, other)

def __le__(self, other):
    return Le(self, other)

def __gt__(self, other):
    return Gt(self, other)

def __ge__(self, other):
    return Ge(self, other)
# Numeric operators
....

Looks like a whole new area we can improve on... we should be able to pull
off a lot of operator overloads for C#. This is pretty cool.

In particular, with getField, the query in Josh's talk:

python: some_object["field"]["subfield"]
JavaScript: someObject("field")("subfield")
java: someObject.getField("field").getField("subfield")

and in C# it may be possible do this type of query:

C#: r.db("mydb").table("users").get("id")["field"]["subfield"]

Looks legit.

My questions would be:

  1. What is the mapping between Python's class RqlQuery and Java's
    AST? ReqlExpr or ReqlAst?
  • In other words, I'm trying to understand where the correct mounting
    point for the operator overloads would go in the AST ReqlExpr or
    ReqlAst. My gut feeling here, operator overloads would go into ReqlExpr.
    Terms like Db inherit from ReqlAst, and doesn't make sense for
    operator overloads to live in ReqlAst super class because operator
    overloads would be available on the Db term. ReqlExpr seems like the
    best place.
  1. In particular with .getField, is there a strict subset of terms
    that can have .getField() called on? With .optArg there was a
    distinction between terms with and without .optArg() calls. I'm just
    wondering if the same could be true with .getField() if Java
    supported operator overloading.

@deontologician https://github.com/deontologician

Thanks for your insight [image: 👍]


Reply to this email directly or view it on GitHub
#9.

from rethinkdb.driver.

bchavez avatar bchavez commented on May 18, 2024

Just finished operator overloading .. it's crazy insane:

new Foo {id = "a", Baz = 1, Bar = 1}
new Foo {id = "b", Baz = 2, Bar = 2}
new Foo {id = "c", Baz = 3, Bar = 3}

var expA = r.db(DbName).table(TableName).get("a")["Baz"];
var expB = r.db(DbName).table(TableName).get("b")["Bar"];

int add = (expA + expB).run<int>(conn);
add.Should().Be(3);

AND IT WORKS! 💥 Thanks again Josh for all the help! :)

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.