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

[wip] new FP-like intermediate representation #10

Open
wants to merge 89 commits into
base: master
Choose a base branch
from
Open

[wip] new FP-like intermediate representation #10

wants to merge 89 commits into from

Conversation

vilterp
Copy link
Owner

@vilterp vilterp commented Mar 28, 2018

Queries are planned into expressions in a small functional programming language,

e.g. the TreeSQL query

MANY blog_posts {
  id,
  comments: MANY comments {
    id,
    blog_post_id
  }
}

becomes

map(
  scan(tables.blog_posts.id),
  (row1) => {
    id: row1.id
    comments: map(
      filter(
        scan(tables.comments.id),
        (row2) => strEq(row2.blog_post_id, row1.id)
      ),
      (row2) => {
        blog_post_id: row2.blog_post_id,
        id: row2.id
      }
    ),
  }
)

…which is then executed to generate the result. Hopefully this will serve as a basis for expanding the set of queries TreeSQL can execute, and be a good place to do index selection, etc.

Still working on the language basics and figuring out how to incrementalize this XD

@vilterp vilterp changed the title new FP-like intermediate representation [wip] new FP-like intermediate representation Mar 28, 2018
Pete Vilter added 28 commits April 19, 2019 04:21
I don't set out to write a code generator in the Format function of
PlanNode, but it appears that's what's happened.

Next step? Transform this into another intermediate representation which
is executed by a VM?
there's about to be a lot of stuff to pretty print y'all
check in basic types, values, and expressions
not actually deserializing and returning an object yet
- add concept of type vars
- new function for matching types

There are a few panics though, so I'm afraid it's fragile.
once we have a parser, can just parse these
Pete Vilter added 27 commits April 19, 2019 04:21
i.e. still return usable traces even in the presence of errors
also add support to the test harness for Map nodes in the trace tree
plus clean up shell's use of channels a bit
by namespacing tables under a "tables" record
need to do this when I'm less sleep-deprived.
closures not working.
they still don't execute correctly because we don't create a new
iterator for each scan yet.
now, a lambda which does a scan can be invoked multiple times, and the
scan will start from the beginning each time.

case incomingMsg := <-conn.IncomingMessages:
channel := conn.Channels[incomingMsg.StatementID]
conn.webSocketConn.WriteMessage(websocket.TextMessage, []byte(request.Statement))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error return value of conn.webSocketConn.WriteMessage is not checked (from errcheck)

err := conn.WebSocketConn.ReadJSON(&parsedMessage)
parsedMessage := &BasicChannelMessage{}
_, rawMsg, err := conn.webSocketConn.ReadMessage()
json.Unmarshal(rawMsg, parsedMessage)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error return value of json.Unmarshal is not checked (from errcheck)

fc.funcName, idx, argType.Format(), param.Typ.Format(),
)
}
bindings.extend(argBindings)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error return value of bindings.extend is not checked (from errcheck)

if !matches {
return false, nil
}
bindings.extend(paramBindings)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error return value of bindings.extend is not checked (from errcheck)

if !paramsMatch {
return false, nil
}
bindings.extend(paramBindings)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error return value of bindings.extend is not checked (from errcheck)


// schema columns iterator

type SchemaColumnsIterator struct {
type schemaColumnsIterator struct {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

U1000: type schemaColumnsIterator is unused (from unused)

for _, table := range db.Schema.Tables {
for _, column := range table.Columns {
columnDoc := column.ToRecord(table.Name, db)
func newColumnsIterator(db *Database) (*schemaColumnsIterator, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

U1000: func newColumnsIterator is unused (from unused)


// record listeners iterator

type RecordListenersIterator struct {
type recordListenersIterator struct {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

U1000: type recordListenersIterator is unused (from unused)

func newRecordListenersIterator(db *Database) (*RecordListenersIterator, error) {
listenersTable := db.Schema.Tables["__record_listeners__"]
listeners := make([]*Record, 0)
func newRecordListenersIterator(db *Database) (*recordListenersIterator, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

U1000: func newRecordListenersIterator is unused (from unused)

var o1 interface{}
var o2 interface{}

var err error

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S1021: should merge variable declaration with assignment on next line (from gosimple)

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

Successfully merging this pull request may close these issues.

2 participants