consistency level ALL?
I was wondering if there are users in this list using consistency level ALL and their reasons for doing so? For example, would the errors for deleting a financial transaction due to an error be reason enough to use consistency level of ALL? Are there other strategies people would use to avoid inconsistent/stale results which could contain the deleted financial transaction? Thank you, Henry
Re: Returning an UDT from a user defined function (UDF)
Whatever I wanted to do does not seem to be possible (probably a limitation or a bug)... I see a way to get the KeyspaceMetadata and from that get the UserType instance (code lines 1 & 2 below). 1.) org.apache.cassandra.schema.KeyspaceMetadata ksm = org.apache.cassandra.config.Schema.instance.getKSMetaData("test_ks"); 2.) com.datastax.driver.core.UserType myUdt = ksm.types.get("my_other_udt").get(); But this fails with the below error because Schema is not a whitelisted package. It probably should not be whitelisted but there should be a way to create and return a user defined type. :88:InvalidRequest: code=2200 [Invalid query] message="Could not compile function 'test_ks.transform_udt' from Java source: org.apache.cassandra.exceptions.InvalidRequestException: Java source compilation failed: Line 4: org.apache.cassandra.schema.KeyspaceMetadata cannot be resolved to a type Line 4: org.apache.cassandra.config.Schema.instance cannot be resolved to a type " :90:InvalidRequest: code=2200 [Invalid query] message="Unknown function 'extract_text_field_sample_udt'" My updated UDF for complete context. CREATE OR REPLACE FUNCTION test_ks.transform_udt (val my_udt) RETURNS NULL ON NULL INPUT RETURNS my_other_udt LANGUAGE java AS ' String fieldA = val.getString("field_a"); org.apache.cassandra.schema.KeyspaceMetadata ksm = org.apache.cassandra.config.Schema.instance.getKSMetaData("test_ks"); com.datastax.driver.core.UserType myUdt = ksm.types.get("my_other_udt").get(); com.datastax.driver.core.UDTValue transformedValue = myUdt.newValue(); transformedValue.setUUID("id", java.util.UUID.randomUUID()); transformedValue.setString("field_a", fieldA); transformedValue.setString("field_b", "value b"); return transformedValue; '; On Thu, Apr 7, 2016 at 7:40 PM Henry M <henrymanm...@gmail.com> wrote: > I was wondering if it is possible to create an UDT and return it within a > user defined function. > > I looked at this documentation > http://docs.datastax.com/en/cql/3.3/cql/cql_using/useCreateUDF.html but > the examples are only for basic types. > > This is my pseudo code I came up with... the part I think I am missing is > how to get an instance of the UserType so that I can invoke newValue to > create a UDTValue. > > Has anyone done this and know how to get the keyspace in order to call > getUserType? Or know of an alternate approach? > > CREATE OR REPLACE FUNCTION test_ks.transform_udt (val my_udt) > RETURNS NULL ON NULL INPUT > RETURNS my_other_udt > LANGUAGE java > AS ' > String fieldA = val.getString("field_a"); > > // How do you get a reference the user type? > UserType myUdt = ?keyspace?.getUserType("my_other_udt"); > > UDTValue transformedValue = myUdt.newValue(); > > transformedValue.setUUID("id", UUID.randomUUID()); > transformedValue.setString("field_a", fieldA); > transformedValue.setString("field_b", "value b"); > > return transformedValue; > '; > > > Thank you, > Henry > > > P.S. This is the setup for my sample table and types. > > drop keyspace test_ks; > > create keyspace test_ks WITH REPLICATION = { 'class' : 'SimpleStrategy', > 'replication_factor' : 1 }; > > use test_ks; > > CREATE TYPE IF NOT EXISTS test_ks.my_udt (field_a text, field_b text); > CREATE TYPE IF NOT EXISTS test_ks.my_other_udt (id uuid, field_a text, > field_b text); > > CREATE TABLE IF NOT EXISTS test_ks.sample_table(id uuid primary key, col_a > frozen); > > INSERT INTO sample_table(id, col_a) VALUES ( now() , { field_a: 'value 1', > field_b: 'value 2'} ); > INSERT INTO sample_table(id) VALUES ( now() ); > > > > > >
Re: Mapping a continuous range to a discrete value
I had to do something similar (in my case it was an IN query)... I ended up writing hack in java to create a custom Expression and injecting into the RowFilter of a dummy secondary index (not advisable and very short term but it keeps my application code clean). I am keeping my eyes open for the evolution of SASI indexes (starting with cassandra 3.4 https://github.com/apache/cassandra/blob/trunk/doc/SASI.md) which should do what you are looking. On Thu, Apr 7, 2016 at 11:06 AM Mitch Gitmanwrote: > I just happened to run into a similar situation myself and I can see it's > through a bad schema design (and query design) on my part. What I wanted to > do was narrow down by the range on one clustering column and then by > another range on the next clustering column. Failing to adequately think > through how Cassandra stores its sorted rows on disk, I just figured, hey, > why not? > > The result? The same error message you got. But then, going back over some > old notes from a DataStax CQL webinar, I came across this (my words): > > "You can do selects with combinations of the different primary keys > including ranges on individual columns. The range will only work if you've > narrowed things down already by equality on all the prior columns. > Cassandra creates a composite type to store the column name." > > My new solution in response. Create two tables: one that's sorted by (in > my situation) a high timestamp, the other that's sorted by (in my > situation) a low timestamp. What had been two clustering columns gets > broken up into one clustering column each in two different tables. Then I > do two queries, one with the one range, the other with the other, and I > programmatically merge the results. > > The funny thing is, that was my original design which my most recent, and > failed, design is replacing. My new solution goes back to my old solution. > > On Thu, Apr 7, 2016 at 1:37 AM, Peer, Oded wrote: > >> I have a table mapping continuous ranges to discrete values. >> >> >> >> CREATE TABLE range_mapping (k int, lower int, upper int, mapped_value >> int, PRIMARY KEY (k, lower, upper)); >> >> INSERT INTO range_mapping (k, lower, upper, mapped_value) VALUES (0, 0, >> 99, 0); >> >> INSERT INTO range_mapping (k, lower, upper, mapped_value) VALUES (0, 100, >> 199, 100); >> >> INSERT INTO range_mapping (k, lower, upper, mapped_value) VALUES (0, 200, >> 299, 200); >> >> >> >> I then want to query this table to find mapping of a specific value. >> >> In SQL I would use: *select mapped_value from range_mapping where k=0 >> and ? between lower and upper* >> >> >> >> If the variable is bound to the value 150 then the mapped_value returned >> is 100. >> >> >> >> I can’t use the same type of query in CQL. >> >> Using the query “*select * from range_mapping where k = 0 and lower <= >> 150 and upper >= 150;*” returns an error "Clustering column "upper" >> cannot be restricted (preceding column "lower" is restricted by a non-EQ >> relation)" >> >> >> >> I thought of using multi-column restrictions but they don’t work as I >> expected as the following query returns two rows instead of the one I >> expected: >> >> >> >> *select * from range_mapping where k = 0 and (lower,upper) <= (150,999) >> and (lower,upper) >= (-999,150);* >> >> >> >> k | lower | upper | mapped_value >> >> ---+---+---+-- >> >> 0 | 0 |99 |0 >> >> 0 | 100 | 199 | 100 >> >> >> >> I’d appreciate any thoughts on the subject. >> >> >> > >
Returning an UDT from a user defined function (UDF)
I was wondering if it is possible to create an UDT and return it within a user defined function. I looked at this documentation http://docs.datastax.com/en/cql/3.3/cql/cql_using/useCreateUDF.html but the examples are only for basic types. This is my pseudo code I came up with... the part I think I am missing is how to get an instance of the UserType so that I can invoke newValue to create a UDTValue. Has anyone done this and know how to get the keyspace in order to call getUserType? Or know of an alternate approach? CREATE OR REPLACE FUNCTION test_ks.transform_udt (val my_udt) RETURNS NULL ON NULL INPUT RETURNS my_other_udt LANGUAGE java AS ' String fieldA = val.getString("field_a"); // How do you get a reference the user type? UserType myUdt = ?keyspace?.getUserType("my_other_udt"); UDTValue transformedValue = myUdt.newValue(); transformedValue.setUUID("id", UUID.randomUUID()); transformedValue.setString("field_a", fieldA); transformedValue.setString("field_b", "value b"); return transformedValue; '; Thank you, Henry P.S. This is the setup for my sample table and types. drop keyspace test_ks; create keyspace test_ks WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }; use test_ks; CREATE TYPE IF NOT EXISTS test_ks.my_udt (field_a text, field_b text); CREATE TYPE IF NOT EXISTS test_ks.my_other_udt (id uuid, field_a text, field_b text); CREATE TABLE IF NOT EXISTS test_ks.sample_table(id uuid primary key, col_a frozen); INSERT INTO sample_table(id, col_a) VALUES ( now() , { field_a: 'value 1', field_b: 'value 2'} ); INSERT INTO sample_table(id) VALUES ( now() );
Re: Large number of tombstones without delete or update
What is the reason for the tombstone for a brand new insert? Do the fields get written as a whole (both nulls and non-nulls? I understand the rationale for tombstones for deletes and updates but it does not make sense for an insert (I am trying to make sense of it). I understand Cassandra writes the record without first checking its existence but wouldn't the whole set of fields including values to null out be applied as one single operation? Thank you, Henry On Wed, Mar 23, 2016 at 5:47 PM, Eric Stevenswrote: > In addition to writing null values acting as tombstones, also INSERTing a > collection (or UPDATE where you set the collection rather than append to > it) are also operations which will create tombstones. > > On Wed, Mar 23, 2016 at 12:09 PM Robert Coli wrote: > >> On Wed, Mar 23, 2016 at 9:50 AM, Ralf Steppacher >> wrote: >> >>> How come I end up with that large a number of tombstones? >>> >> >> Are you inserting NULLs? >> >> =Rob >> >> >
Re: nulls in prepared statement & tombstones?
Thank you. It's probably not specific to prepared statements then and just a more general statement. That makes sense. On Tue, Mar 8, 2016 at 10:06 AM Steve Robenaltwrote: > Hi Henry, > > I would suspect that the tombstones are necessary to overwrite any > previous values in the null'd columns. Since Cassandra avoids > read-before-write, there's no way to be sure that the nulls were not > intended to remove any such previous values, so the tombstones insure that > they don't re-appear. > > Steve > > > > On Tue, Mar 8, 2016 at 9:36 AM, Henry Manasseh > wrote: > >> The following article makes the following statement which I am trying to >> understand: >> >> *"Cassandra’s storage engine is optimized to avoid storing unnecessary >> empty columns, but when using prepared statements those parameters that are >> not provided result in null values being passed to Cassandra (and thus >> tombstones being stored)." * >> http://www.datastax.com/dev/blog/4-simple-rules-when-using-the-datastax-drivers-for-cassandra >> >> I was wondering if someone could help explain why sending nulls as part >> of a prepared statement update would result in tombstones. >> >> Thank you, >> - Henry >> > > > > -- > Steve Robenalt > Software Architect > sroben...@highwire.org > (office/cell): 916-505-1785 > > HighWire Press, Inc. > 425 Broadway St, Redwood City, CA 94063 > www.highwire.org > > Technology for Scholarly Communication >