Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operator Overload .getField("abc") with Expr["abc"] #9

Closed
bchavez opened this issue Nov 3, 2015 · 2 comments
Closed

Operator Overload .getField("abc") with Expr["abc"] #9

bchavez opened this issue Nov 3, 2015 · 2 comments

Comments

@bchavez
Copy link
Owner

bchavez commented Nov 3, 2015

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 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.

_2. 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

Thanks for your insight 👍

bchavez added a commit that referenced this issue Nov 3, 2015
@deontologician
Copy link

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 notifications@github.com 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.

@bchavez
Copy link
Owner Author

bchavez commented Nov 3, 2015

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! :)

@bchavez bchavez closed this as completed Nov 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants