Skip to content

Commit

Permalink
README updated; Initial changes to use execute method.
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab committed Apr 8, 2018
1 parent 8c8df6d commit f381223
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 14 deletions.
29 changes: 29 additions & 0 deletions ibis/mapd/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ database.
The main classes are:

- `MapDClient`
- `MapDQuery`
- `MapDDataType`

`MapDDataType` class is used to translate data type from `ibis` and to `ibis`.
Expand Down Expand Up @@ -105,6 +106,34 @@ expression. Its main methods are:
- get_schema
- version

`MapDQuery` class should be used redefine at least `_fetch` method. If `Query`
class is used instead, when `MapDClient.execute` method is called, a exception
is raised.

compiler
--------

@TODO

operations
----------

`Node` subclasses make up the core set of operations of ibis.
Each node corresponds to a particular operation.
Most nodes are defined in the `operations` module.
(http://docs.ibis-project.org/design.html#the-node-class).


identifiers
-----------

`identifiers` module keep a set of identifiers (`_identifiers`) to be used
inside `quote_identifier` function (inside the same module). `_identifiers` is
a set of reserved words from `MapD` language.

`quote_identifiers` is used to put quotes around the string sent if the string
match to specific criteria.

References
----------

Expand Down
53 changes: 43 additions & 10 deletions ibis/mapd/client.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from ibis.compat import parse_version
from ibis.client import Database, SQLClient
from ibis.client import Database, Query, SQLClient
from ibis.mapd import compiler as comp
from ibis.util import log
from pymapd.cursor import Cursor

import regex as re
import pandas as pd
import pymapd

import ibis.common as com
Expand Down Expand Up @@ -74,11 +76,33 @@ def from_ibis(cls, dtype, nullable=None):
return cls(typename, nullable=nullable)


class MapDQuery(Query):
"""
"""
def execute(self):
cursor = self.client._execute(
self.compiled_ddl
)
result = self._fetch(cursor)
return self._wrap_result(result)

def _fetch(self, cursor):
# check if cursor is a pymapd cursor.Cursor
if isinstance(cursor, Cursor):
col_names = [c.name for c in cursor.description]
result = pd.DataFrame(cursor.fetchall(), columns=col_names)
else:
result = cursor
return self.schema().apply_to(result)


class MapDClient(SQLClient):
"""
"""
database_class = Database
sync_query = MapDQuery
dialect = comp.MapDDialect

def __init__(
Expand Down Expand Up @@ -145,16 +169,25 @@ def _get_table_schema(self, table_name):
database, table_name = table_name_
return self.get_schema(table_name, database)

def _execute(self, query):
with self.con as conn:
if self.execution_type == 1:
stmt_exec = conn.select_ipc_gpu
elif self.execution_type == 2:
self.stmt_exec = conn.select_ipc
else:
self.stmt_exec = conn.execute
def _execute(self, query, results=True):
"""
return stmt_exec(query)
:param query:
:return:
"""
if self.execution_type == 1:
stmt_exec = self.con.select_ipc_gpu
elif self.execution_type == 2:
stmt_exec = self.con.select_ipc
else:
stmt_exec = self.con.cursor().execute

result = stmt_exec(query)

if results:
return result
else:
return

def database(self, name=None):
"""Connect to a database called `name`.
Expand Down
2 changes: 1 addition & 1 deletion ibis/mapd/identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
})


def quote_identifier(name, quotechar='`', force=False):
def quote_identifier(name, quotechar='"', force=False):
if force or name.count(' ') or name in _identifiers:
return '{0}{1}{0}'.format(quotechar, name)
else:
Expand Down
3 changes: 0 additions & 3 deletions ibis/mapd/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,6 @@ def _string_like(translator, expr):
)


# TODO: mapd uses different string functions
# for ascii and utf-8 encodings,

_binary_infix_ops = {
# Binary operations
ops.Add: binary_infix_op('+'),
Expand Down

0 comments on commit f381223

Please sign in to comment.