February 23, 2018


An angry forge.

February 13, 2018


There's really no point to this blog anymore.

February 11, 2018


This is a terrible photo but boy is he vicious.

February 9, 2018


Yes, David Lynch did just make me watch more than sixty seconds of someone sweeping a floor while Booker T played Green Onions. Sigh.

February 8, 2018


The school bus driver union is on strike so taxis are lined up in the bus lane at the high school by my apartment.

February 7, 2018


Boy I love the top of the fold headlines in Seattle.

February 6, 2018


The Alaska Way Viaduct, before it is torn down.

When using Cassandra you quickly learn that preparing queries is the way to go. It makes them about a billion times faster. But sometimes you need to do fancy things to your queries like set up a specific retry policy or set up a specific consistency policy that is active for just that query. I found few examples of how to do this in the documentation or on the internet. So, in Python, here's how to do both.

__queries = {
    "select": None,  # store the prepared select query
}

def select_data(foo):
    if (__queries["select"] is None):
        __queries["select"] = session.prepare("""
            SELECT col1, col2
            FROM mykeyspace.mytable
            WHERE col3 = :foo
        """)
        __queries["select"].retry_policy = cassandra.policies.DowngradingConsistencyRetryPolicy()
    query = __queries["select"]

    bound = query.bind({"foo": foo})
    bound.consistency_level = cassandra.ConsistencyLevel.QUORUM

    rows = session.execute(bound)
    for row in rows:
        pass

Tada.

About

Location Seattle, WA
First post September 6, 2004
Total posts 5,961

Tags

  1. 1,799
  2. 695
  3. 633
  4. 585
  5. 554
  6. 497
  7. 268
  8. 193
  9. 193
  10. 139
  11. 131
  12. 106
  13. 104
  14. 86
  15. 78
  16. 70
  17. 58
  18. 57
  19. 41
  20. 26
  21. 1
Load the RSS feed for entries or for comments.