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

Implement simple SQL example and write intro docs #20

Merged
merged 9 commits into from
Jul 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ Pandas on Ray

**Pandas on Ray is currently for experimental use only. Requests and contributions are welcome!**

SQL on Ray
----------

*SQL on Ray is currently under development. Coming Soon!*

**We have implemented a simple example that can be found below. Feedback welcome!**

.. code-block:: python

>>> import modin.sql as sql
>>>
>>> conn = sql.connect("db_name")
>>> c = conn.cursor()
>>> c.execute("CREATE TABLE example (col1, col2, column 3, col4)")
>>> c.execute("INSERT INTO example VALUES ('1', 2.0, 'A String of information', True)")
col1 col2 column 3 col4
0 1 2.0 A String of information True

>>> c.execute("INSERT INTO example VALUES ('6', 17.0, 'A String of different information', False)")
col1 col2 column 3 col4
0 1 2.0 A String of information True
1 6 17.0 A String of different information False

More information and Getting Involved
-------------------------------------

Expand Down
29 changes: 29 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@ Pandas on Ray

**Pandas on Ray is currently for experimental use only. Requests and contributions are welcome!**

SQL on Ray
----------

*SQL on Ray is currently under development. Coming Soon!*

**We have implemented a simple example that can be found below. Feedback welcome!**

.. code-block:: python

>>> import modin.sql as sql
>>>
>>> conn = sql.connect("db_name")
>>> c = conn.cursor()
>>> c.execute("CREATE TABLE example (col1, col2, column 3, col4)")
>>> c.execute("INSERT INTO example VALUES ('1', 2.0, 'A String of information', True)")
col1 col2 column 3 col4
0 1 2.0 A String of information True

>>> c.execute("INSERT INTO example VALUES ('6', 17.0, 'A String of different information', False)")
col1 col2 column 3 col4
0 1 2.0 A String of information True
1 6 17.0 A String of different information False

.. toctree::
:maxdepth: 1
:caption: Installation
Expand All @@ -45,3 +68,9 @@ Pandas on Ray

pandas_on_ray.rst
pandas_supported.rst

.. toctree::
:maxdepth: 1
:caption: SQL on Ray

sql_on_ray.rst
5 changes: 5 additions & 0 deletions docs/sql_on_ray.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SQL on Ray
Copy link
Collaborator

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?

==========

**SQL on Ray is currently under development. Coming Soon!**

7 changes: 7 additions & 0 deletions modin/sql/__init__.py
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"]
58 changes: 58 additions & 0 deletions modin/sql/connection.py
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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will the ray.init call run if DataFrame is imported relatively?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It does run, Yes

Copy link
Collaborator

Choose a reason for hiding this comment

The 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]])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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)