Created
October 26, 2019 05:52
-
-
Save kmuthukk/679fb30fd6e85a042a12a6f1801ec31e to your computer and use it in GitHub Desktop.
Issue With Invalid/NULL Range Column
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install yb-cassandra-driver | |
from cassandra.cluster import Cluster | |
from cassandra.query import UNSET_VALUE | |
import time | |
import random | |
import os | |
from multiprocessing.dummy import Pool as ThreadPool | |
# Load Phase params | |
num_users=2 | |
cluster = Cluster(['127.0.0.1']) | |
session = cluster.connect() | |
def create_table(): | |
start_time = time.time() | |
session.execute("""CREATE KEYSPACE IF NOT EXISTS k"""); | |
session.execute("""USE k"""); | |
session.execute("""DROP TABLE IF EXISTS users"""); | |
now_time = time.time() | |
print("Dropped (if exists): users table") | |
print("Time: %s ms" % ((now_time - start_time) * 1000)) | |
print("====================") | |
start_time = time.time() | |
session.execute(""" | |
CREATE TABLE IF NOT EXISTS users( | |
id text, | |
name text, | |
age int, | |
info text, | |
PRIMARY KEY((id), name) | |
); | |
""") | |
now_time = time.time() | |
print("Created users table") | |
print("Time: %s ms" % ((now_time - start_time) * 1000)) | |
def load_data(): | |
prepared = session.prepare("""INSERT INTO users (id, name, age, info) VALUES (?, ?, ?, ?)"""); | |
for idx in range(num_users): | |
input_data = "I am a test " + str(idx); | |
session.execute(prepared, | |
("id-"+str(idx), UNSET_VALUE, | |
20 + (idx % 50), | |
input_data)) | |
def select_data(): | |
results = session.execute("SELECT * FROM users LIMIT 10") | |
for row in results: | |
print('id='+row.id) | |
print('name='+row.name) | |
print('age='+str(row.age)) | |
print('info='+row.info) | |
# Main | |
create_table() | |
load_data() | |
select_data() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment