diff --git a/README.rst b/README.rst index 22e5deebe0b..857915439cf 100644 --- a/README.rst +++ b/README.rst @@ -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 ------------------------------------- diff --git a/docs/index.rst b/docs/index.rst index 1eb5cb42a89..0b7ea0fccb4 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -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 @@ -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 diff --git a/docs/sql_on_ray.rst b/docs/sql_on_ray.rst new file mode 100644 index 00000000000..6285ed5f0cd --- /dev/null +++ b/docs/sql_on_ray.rst @@ -0,0 +1,5 @@ +SQL on Ray +========== + +**SQL on Ray is currently under development. Coming Soon!** + diff --git a/modin/sql/__init__.py b/modin/sql/__init__.py new file mode 100644 index 00000000000..1de78687bd1 --- /dev/null +++ b/modin/sql/__init__.py @@ -0,0 +1,7 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +from .connection import connect + +__all__ = ["connect"] diff --git a/modin/sql/connection.py b/modin/sql/connection.py new file mode 100644 index 00000000000..bf16edb267f --- /dev/null +++ b/modin/sql/connection.py @@ -0,0 +1,58 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +from ..pandas import Series, DataFrame + + +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]]) + + +def connect(name): + return Connection(name)