diff --git a/SampleCode/MapDExample.py b/SampleCode/MapDExample.py deleted file mode 100644 index fcc1796654..0000000000 --- a/SampleCode/MapDExample.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env python - -from thrift.protocol import TBinaryProtocol -from thrift.protocol import TJSONProtocol -from thrift.transport import TSocket -from thrift.transport import THttpClient -from thrift.transport import TTransport -from mapd import MapD -from mapd import ttypes -import time - -''' -Contact support@mapd.com with any questions - -Python 3.x instructions (manual build of latest Thrift) -sudo apt-get install build-essential -git clone https://git-wip-us.apache.org/repos/asf/thrift.git -cd thrift/lib/py -pip install . -thrift -gen py mapd.thrift -export PYTHONPATH=/path/to/mapd2-1.x-gen-py:$PYTHONPATH - -Example: -python MapDExample.py - -Connection samples: -HTTP client - get_client('http://test.mapd.com:6274', portno, True) -Binary protocol - get_client('locahost', 6274, False) -''' - - -def get_client(host_or_uri, port, http): - if http: - transport = THttpClient.THttpClient(host_or_uri) - protocol = TJSONProtocol.TJSONProtocol(transport) - else: - socket = TSocket.TSocket(host_or_uri, port) - transport = TTransport.TBufferedTransport(socket) - protocol = TBinaryProtocol.TBinaryProtocol(transport) - - client = MapD.Client(protocol) - transport.open() - return client - - -def main(): - - db_name = 'mapd' - user_name = 'mapd' - passwd = 'HyperInteractive' - hostname = 'test.mapd.com' - portno = 6274 - - client = get_client(hostname, portno, False) - session = client.connect(user_name, passwd, db_name) - print('Connection complete') - query = 'select a,b from table1 limit 25;' - print('Query is : ' + query) - - # always use True for is columnar - results = client.sql_execute(session, query, True, None, -1, -1) - dates = ['TIME', 'TIMESTAMP', 'DATE'] - - if results.row_set.is_columnar == True: - number_of_rows = list(range(0, len(results.row_set.columns[0].nulls))) - number_of_columns = list(range(0, len(results.row_set.row_desc))) - for n in number_of_rows: - for i in number_of_columns: - column_type = ttypes.TDatumType._VALUES_TO_NAMES[ - results.row_set.row_desc[i].col_type.type] - column_name = results.row_set.row_desc[i].col_name - column_array = results.row_set.row_desc[i].col_type.is_array - if not column_array: - if column_type in ['SMALLINT', 'INT', 'BIGINT', 'TIME', 'TIMESTAMP', 'DATE', 'BOOL']: - column_value = results.row_set.columns[i].data.int_col[n] - if column_type in ['FLOAT', 'DECIMAL', 'DOUBLE']: - column_value = results.row_set.columns[i].data.real_col[n] - if column_type in ['STR']: - column_value = results.row_set.columns[i].data.str_col[n] - else: - column_value = results.row_set.columns[i].data.arr_col[n].data.str_col - print(column_name) - if column_type in dates: - print(time.strftime('%Y-%m-%d %H:%M:%S', - time.localtime(column_value))) - else: - print(column_value) - - else: - print('Please use columns not rows in query execution') - client.disconnect(session) - quit() - - client.disconnect(session) - - -if __name__ == '__main__': - main() diff --git a/SampleCode/mapd_jdbc.py b/SampleCode/mapd_jdbc.py deleted file mode 100644 index 2cb7ffb2fd..0000000000 --- a/SampleCode/mapd_jdbc.py +++ /dev/null @@ -1,15 +0,0 @@ -# !/usr/bin/env python - -import jaydebeapi - - -def connect(dbname, user, host, password): - jar = './mapdjdbc-1.0-SNAPSHOT-jar-with-dependencies.jar' # may want to parametrize - try: - return jaydebeapi.connect('com.mapd.jdbc.MapDDriver', - 'jdbc:mapd:{}:{}:'.format(host, dbname), - {'user': user, 'password': password}, - jar) - except Exception as e: - print('Error: {}'.format(str(e))) - raise e diff --git a/SampleCode/mapd_jdbc_example.py b/SampleCode/mapd_jdbc_example.py deleted file mode 100644 index 2c655d28cd..0000000000 --- a/SampleCode/mapd_jdbc_example.py +++ /dev/null @@ -1,40 +0,0 @@ -# Note: The following example should be run in the same directory as -# map_jdbc.py and mapdjdbc-1.0-SNAPSHOT-jar-with-dependencies.jar - -import mapd_jdbc -import pandas -import matplotlib.pyplot as plt - -dbname = 'mapd' -user = 'mapd' -host = 'localhost:6274' -password = 'HyperInteractive' - -# Connect to the db - -mapd_con = mapd_jdbc.connect( - dbname=dbname, user=user, host=host, password=password) - -# Get a db cursor - -mapd_cursor = mapd_con.cursor() - -# Query the db - -query = "select carrier_name, avg(depdelay) as x, avg(arrdelay) as y from flights_2008 group by carrier_name" - -mapd_cursor.execute(query) - -# Get the results - -results = mapd_cursor.fetchall() - -# Make the results a Pandas DataFrame - -df = pandas.DataFrame(results) - -# Make a scatterplot of the results - -plt.scatter(df[1], df[2]) - -plt.show() diff --git a/SampleCode/stream_insert.py b/SampleCode/stream_insert.py deleted file mode 100644 index 27b0fda2ed..0000000000 --- a/SampleCode/stream_insert.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/ usr / bin / env python - -from thrift.protocol import TBinaryProtocol -from thrift.transport import TSocket -from thrift.transport import TTransport - -from mapd import MapD - - -def get_client(host, port): - socket = TSocket.TSocket(host, port) - transport = TTransport.TBufferedTransport(socket) - protocol = TBinaryProtocol.TBinaryProtocol(transport) - client = MapD.Client(protocol) - transport.open() - return client - - -def import_some_rows(session, table_name, client): - input_rows = [] - for i in xrange(0, 100): - input_row = MapD.TStringRow() - input_row.cols = [ - MapD.TStringValue(str(i)), - MapD.TStringValue('str%d' % i), - MapD.TStringValue('real_str%d' % i) - ] - input_rows.append(input_row) - client.load_table(session, table_name, input_rows) - - -def main(): -#Import rows to a table created by the following statement: -#CREATE TABLE foo(x int, str text encoding dict, real_str text); - -#How to run: -# -#thrift - gen py ~ / mapd2 / mapd.thrift -#PYTHONPATH =`pwd`/ gen - py python./ stream_insert.py - - table_name = 'foo' - db_name = 'omnisci' - user_name = 'admin' - passwd = 'HyperInteractive' - hostname = 'localhost' - portno = 6274 - - client = get_client(hostname, portno) - session = client.connect(user_name, passwd, db_name) - import_some_rows(session, table_name, client) - client.disconnect(session) - - - -if __name__ == "__main__": - main()