Cassandra::Composite.new(composite, :slice => ...) should overwrite :slice #174

Closed
mcmire opened this Issue Jan 22, 2013 · 5 comments

Projects

None yet

3 participants

@mcmire
mcmire commented Jan 22, 2013

I noticed that if you do the following:

composite = Cassandra::Composite.new('foo' )
composite2 = Cassandra::Composite.new(composite, :slice => :after)

then the :slice argument is not honored.

In Cassandra::Composite there is this code:

@column_slice = options[:slice]
      raise ArgumentError if @column_slice != nil && ![:before, :after].include?(@column_slice)

      if parts.length == 1 && parts[0].instance_of?(self.class)
        @column_slice = parts[0].column_slice
        @parts = parts[0].parts

It looks like to me that it's the @column_slice = parts[0].column_slice that's doing it.

I can submit a failing test later to confirm.

@natemueller
Collaborator

I'm a little confused about your example. Are you trying to make a composite column where one element is itself a composite column? I don't think Cassandra supports that.

@mcmire
mcmire commented Jan 23, 2013

No - I'm essentially taking a Composite and cloning it with some extra options.

@mcmire
mcmire commented Jan 23, 2013

I was putting two ideas together. "Well, if I can pass a Composite to Composite.new to clone it, then I should be able to pass in some options so that they can get overridden."

On second thought I guess that isn't a common idiom anywhere. The code was a bit unclear on how it processes things (it sets @column_slice and then immediately re-sets it), and it's interesting that it even allows you to pass an options hash along with a Composite, but that's fine what it does. I'll just clone and then reset column_slice instead.

@mcmire mcmire closed this Jan 23, 2013
@psanford
Member

That sounds like a good plan.

In case anyone is wondering, the only reason that Cassandra::Composite accepts an instance of Cassandra::Composite at initialization is because of the way the library does insertions. Basically it is an artifact of being able to handle coercion correctly in all cases.

@mcmire
mcmire commented Jan 23, 2013

I see. That makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment