-
Notifications
You must be signed in to change notification settings - Fork 677
Implement simple SQL example and write intro docs #20
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
Changes from 7 commits
eaf51cb
168fbd6
06422a2
2c24bbc
086a362
bf77c3a
384f406
fe9d2ed
774572e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| SQL on Ray | ||
| ========== | ||
|
|
||
| **SQL on Ray is currently under development. Coming Soon!** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from __future__ import absolute_import | ||
| from __future__ import division | ||
| from __future__ import print_function | ||
|
|
||
| from .connection import connect |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| from __future__ import absolute_import | ||
| from __future__ import division | ||
| from __future__ import print_function | ||
|
|
||
| from ..pandas import Series, DataFrame | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does run, Yes
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perfect, thanks for confirming. |
||
|
|
||
|
|
||
| class Connection(object): | ||
|
|
||
| def __init__(self, name): | ||
| self._name = name | ||
| self._cursor = None | ||
|
|
||
| def cursor(self): | ||
| self._cursor = Cursor() | ||
| return self._cursor | ||
|
|
||
| def commit(self): | ||
| pass | ||
|
|
||
| def close(self): | ||
| self._cursor = None | ||
|
|
||
|
|
||
| class Cursor(object): | ||
|
|
||
| def __init__(self): | ||
| self._tables = {} | ||
|
|
||
| def execute(self, query): | ||
| split_query = query.split(" ") | ||
| if " ".join(split_query[:2]) == "CREATE TABLE": | ||
| column_names = " ".join(split_query[3:])\ | ||
| .replace("(", "").replace(")", "").split(", ") | ||
| columns = Series(column_names) | ||
| self._tables[split_query[2]] = DataFrame(columns=columns) | ||
|
|
||
| elif " ".join(split_query[:2]) == "INSERT INTO": | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we split these into helper methods? This will make development on further functionality better in the future.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure makes sense. Most likely this code will get thrown away in the future, but the skeleton might stay. |
||
| table = self._tables[split_query[2]] | ||
| values = " ".join(split_query[4:])\ | ||
| .replace("(", "").replace(")", "").split(", ") | ||
| to_append = Series([eval(i) for i in values], index=table.columns) | ||
| self._tables[split_query[2]] =\ | ||
| table.append(to_append, ignore_index=True) | ||
| print(self._tables[split_query[2]]) | ||
| else: | ||
| raise NotImplementedError("This API is for demonstration purposes " | ||
| "only. Coming Soon!") | ||
|
|
||
|
|
||
| def connect(name): | ||
| return Connection(name) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add the code example to this page too?