1

I am using cassandra python driver. Version details :

[cassandra-driver (3.25.0)] 
[cqlsh 6.8.0 | Cassandra 4.0.4 | CQL spec 3.4.5 | Native protocol v4]

I am querying Cassandra database where I have created few columns which have empty space and special characters such as '%' I manage to do by supplying those columns in double quotes( ex "Mem Util %")

    desc my_keyspace.memutils;
    
    CREATE TABLE my_keyspace.memutils (
        time text PRIMARY KEY,
        "Mem Util %" text,
...

When I query those column via CQL, I supply the column name with double quotes and I get proper data as well as my result columns are as it is, example :

select "Mem Util %" from my_keyspace.memutils;

 Mem Util %
----------------------
          9.177055477
          83.85167852

But when I use Cassandra-python driver, the query is able to get the proper data but it replaces spaces in the column's name with underscore in the result data(ResponseFeature)

Code snippet

from cassandra.cluster import Cluster
from cassandra.policies import DCAwareRoundRobinPolicy
from cassandra.auth import PlainTextAuthProvider
...

print("Select query--> ", fetch_query)
response_future = self.session.execute(fetch_query);
...
print('response_future  --> ', response_future[0])

Output

Select query-->  select Time, "Mem Util %" from my_keyspace.memutils;
response_future-->  Row(time='631', Mem_Util='9.177055477')

The result data set also doesn't' have "%" in the column.

Question :

  1. Is there any option in session.execute(), to disable above behavior ?

I saw doc

Beatdown
  • 187
  • 2
  • 7
  • 20
sandejai
  • 931
  • 1
  • 15
  • 22
  • 1
    IT could be because you are using default named_tuple_factory as a row_factory. Attributes of a named tuple must be valid Python identifiers, so column names get transformed. You can try dict_factory, maybe that will use original column name. – Andy S Jan 18 '23 at 23:52

0 Answers0