def panda_factory(self, colnames, rows): """ Returns Rows in a Panda DataFrame :param rows: values selected in Select statement :param colnames: column names selected :return: Panda DataFrame """ if len(rows) == 0: return CassandraFrame(session=self.session) return CassandraFrame(rows, columns=colnames, session=self.session)
def setUp(self): super(TestQuery, self).setUp() self.frame = CassandraFrame([["VIN1", "ford", "black", "frank"], ["VIN2", "cyrsler", "blue", "chris"], ["VIN3", "honda", "red", "harry"]], columns=self.cols, session=self.session, table="tester") self.frame.create_cql_insert()
class query(unittest.TestCase): def setUp(self): self.tmp = CassandraFrame([["VIN1", "ford", "black", "frank"], ["VIN2", "cyrsler", "blue", "chris"], ["VIN3", "honda", "red", "harry"]], columns = cols, session=session, table="tester") self.tmp.create_cql_insert def test_all_attributes(self): self.tmp.insert_async() self.cf = session.execute("SELECT * FROM tester") self.assertEqual(len(self.cf), 3) self.assertIsInstance(self.cf, CassandraFrame) self.assertEqual(self.tmp.session, self.cf.session) # self.assertEqual(self.tmp.table, self.cf.table) # self.assertEqual(self.tmp.__prepared_columns__, self.cf.__prepared_columns__) # self.assertEqual(self.tmp.cql_columns, self.cf.cql_columns)
class TestQuery(BaseTestInput): def setUp(self): super(TestQuery, self).setUp() self.frame = CassandraFrame([["VIN1", "ford", "black", "frank"], ["VIN2", "cyrsler", "blue", "chris"], ["VIN3", "honda", "red", "harry"]], columns=self.cols, session=self.session, table="tester") self.frame.create_cql_insert() def test_all_attributes(self): self.frame.insert_async() result_set = self.session.execute("SELECT * FROM tester") self.cf = result_set._current_rows self.assertEqual(len(self.cf), 3) self.assertIsInstance(self.cf, CassandraFrame) self.assertEqual(self.frame.session, self.cf.session)
color text, owner text, passengers set<text>, data blob );""") cols = ["id", "car", "color", "owner"] session = cl.connect("tests") #df = pd.DataFrame(range(1,5), columns=["a"]) #tmp = CassandraFrame(np.random.randn(10, 2), columns=["id",""], session = session, table="albums") tmp = CassandraFrame( [["VIN1", "ford", "black", "frank"], ["VIN2", "cyrsler", "blue", "chris"], ["VIN3", "honda", "red", "harry"]], columns=cols, session=session, table="albums") tmp.create_cql_insert() tmp.insert_async() print "Now see that the data was inserted" session.execute("""SELECT id, car, color, owner FROM tests.albums""") print "The description of tests.albumns:" print cl.keyspaces["tests"].tables["albums"] print "As opposed to this:" print cl.metadata.keyspaces["tests"].tables["albums"].export_as_string() print "Another comparison" print cl.keyspaces["tests"].tables["sold_cars"]
id text PRIMARY KEY, car text, color text, owner text, passengers set<text>, data blob );""") cols = ["id","car","color","owner"] session = cl.connect("tests") #df = pd.DataFrame(range(1,5), columns=["a"]) #tmp = CassandraFrame(np.random.randn(10, 2), columns=["id",""], session = session, table="albums") tmp = CassandraFrame([["VIN1", "ford", "black", "frank"], ["VIN2", "cyrsler", "blue", "chris"], ["VIN3", "honda", "red", "harry"]], columns = cols, session=session, table="albums") tmp.create_cql_insert() tmp.insert_async() print "Now see that the data was inserted" session.execute("""SELECT id, car, color, owner FROM tests.albums""") print "The description of tests.albumns:" print cl.keyspaces["tests"].tables["albums"].describe() print "As opposed to this:" print cl.metadata.keyspaces["tests"].tables["albums"].export_as_string() print "Another comparison" print cl.keyspaces["tests"].tables["sold_cars"].describe() print "As opposed to this:" print cl.metadata.keyspaces["tests"].tables["sold_cars"].export_as_string()
def setUp(self): self.tmp = CassandraFrame([["VIN1", "ford", "black", "frank"], ["VIN2", "cyrsler", "blue", "chris"], ["VIN3", "honda", "red", "harry"]], columns = cols, session=session, table="tester") self.tmp.create_cql_insert
cl = Cluster() session = cl.connect() session.execute("""CREATE KEYSPACE IF NOT EXISTS tests WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };""") session.set_keyspace("tests") session.execute("""CREATE TABLE IF NOT EXISTS albums( id text PRIMARY KEY, car text, color text, owner text, passengers set<text>, data blob );""") cols = ["id","car","color","owner"] #df = DataFrame(range(1,5), columns=["a"]) #tmp = CassandraFrame(np.random.randn(10, 2), columns=["id",""], session = session, table="albums") tmp = CassandraFrame([["VIN1", "ford", "black", "frank"], ["VIN2", "cyrsler", "blue", "chris"], ["VIN3", "honda", "red", "harry"]], columns = cols, session=session, table="albums") tmp.create_cql_insert print tmp.insert_async() cl.shutdown() #session.execute("DROP TABLE albums;")