GithubHelp home page GithubHelp logo

Comments (2)

wesm avatar wesm commented on May 17, 2024

Comment by wesm
Monday Jan 05, 2015 at 22:26 GMT


Looked at how sqlalchemy handles this:

http://docs.sqlalchemy.org/en/rel_0_8/orm/relationships.html#self-referential-query-strategies

punchline:

from sqlalchemy.orm import aliased

nodealias = aliased(Node)
SQLsession.query(Node).filter(Node.data=='subchild1').\
                join(nodealias, Node.parent).\
                filter(nodealias.data=="child2").\
                all()

This suggests that having a "view" API (name can change) is a reasonable solution

from ibis.

wesm avatar wesm commented on May 17, 2024

Comment by wesm
Tuesday Jan 06, 2015 at 17:40 GMT


Closing this. Here's an example of performing an aggregation on a self-joined table:

left = table
right = table.view()

metric = (left['a'] - right['b']).mean().name('metric')
joined = left.inner_join(right, [right['g'] == left['g']])
aggregated = joined.aggregate([metric], by=[left['g']])

The IR for the aggregation (console repr still a little messy, can't tell the parts of the aggregation apart yet) looks like:

ref_0
  TableView[table]
  a : int8
  b : int16
  c : int32
  d : int64
  e : float
  f : double
  g : string
  h : boolean

ref_1
SelfReference[table]
  Table: ref_0

Aggregation[table]
  InnerJoin[table]
    Table: ref_0
    Table: ref_1
    Equals[array(boolean)]
      Column[string] 'g' from table ref_1
      Column[string] 'g' from table ref_0
  Mean[double]
    Subtract[array(int32)]
      Column[int8] 'a' from table ref_0
      Column[int16] 'b' from table ref_1
  Column[string] 'g' from table ref_0

from ibis.

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.