cassandra - The same query work with cql but not with python driver
Asked Answered
D

0

2

I have a strange problem here. I have a cassandra table called events_prime and I want to request the DB to get elements from this table with a WHERE clause.

I am using the python cassandra-driver and this is my request:

prep_stment = session.prepare("""
    SELECT * FROM events_prime WHERE "websiteId" = '%s-%s' AND churner=True AND "currentTime" > '%s' AND "currentTime" < '%s' LIMIT 20000;
    """%(platform,client,time_2,time_1))
    print prep_stment
    print "Request DB..."
    frames = []
    for res in session.execute(prep_stment):
        frames.append(pd.DataFrame(res))
    df = pd.concat(frames)
    print df.shape

The output:

Out[1]: Request cassandra...
Out[2]: <PreparedStatement query="
    SELECT * FROM events_prime WHERE "websiteId" = 'sd-8231' AND churner=True AND "currentTime" > '2016-03-08 21:32:14' AND "currentTime" < '2016-03-08 23:32:14' LIMIT 20000;
    ", consistency=Not Set>
Out[3]: Request DB...

Out[4]: (0, 31)

That means that there is no data with the given constraints!

BUT when I run SELECT * FROM events_prime WHERE "websiteId" = 'sd-8231' AND churner=True AND "currentTime" > '2016-03-08 21:32:14' AND "currentTime" < '2016-03-08 23:32:14' LIMIT 20000; (which is the same query in python driver ) directly in cql I get 100 rows?

Any explanation? Thanks in advance

Deliciadelicious answered 8/3, 2016 at 23:41 Comment(3)
have you tried just printing out the results from the python driver instead of adding them to the dataframe? To check whether or not you are actually getting things through the python driver.Liveried
maybe your "session" is not properly instantiated, check it outMuggins
Could you show us more of your Python code, i.e. how session is created/set up?Holmium

© 2022 - 2024 — McMap. All rights reserved.