-
Notifications
You must be signed in to change notification settings - Fork 651
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
Implement simple SQL example and write intro docs #20
Changes from all 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,7 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
from .connection import connect | ||
|
||
__all__ = ["connect"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
from ..pandas import Series, DataFrame | ||
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 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 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": | ||
self._create_table(split_query) | ||
|
||
elif " ".join(split_query[:2]) == "INSERT INTO": | ||
self._insert_into(split_query) | ||
else: | ||
raise NotImplementedError("This API is for demonstration purposes " | ||
"only. Coming Soon!") | ||
|
||
def _create_table(self, split_query): | ||
column_names = " ".join(split_query[3:]) \ | ||
.replace("(", "").replace(")", "").split(", ") | ||
columns = Series(column_names) | ||
self._tables[split_query[2]] = DataFrame(columns=columns) | ||
|
||
def _insert_into(self, split_query): | ||
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]]) | ||
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. Should this be here? 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. We want to show that it's inserting. It's only for a demonstration and will be removed in the future. |
||
|
||
|
||
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?