EzDevInfo.com

cequel

Ruby ORM for Cassandra with CQL3

Querying Cassandra in Rails by Cequel

I am using Cequel in Rails. I would like to query something like

Event.where("started_at >?", Time.now) 

in ActiveRecord. But I don't know how to do that in cequel.


Source: (StackOverflow)

Create Nested Type in cequel (Rails - cassandra)

I am trying to create a type like this

tags set< frozen< map<text, int> > >.

How do I create nested type like set< frozen< map<text, int> > > using cequel.

I checked this doc. But I can't find any nested type.


Source: (StackOverflow)

Advertisements

How to generate a delete statement with Cequel (Rails)

I want to generate a DELETE statement with Cequel:

DELETE FROM users where pk = 'jsmith' and cc < 100;

Let's say my user model looks like this

class Users
    include Cequel::Record

    key :pk, :bigint, { partition: true } # partition key
    key :cc, :timestamp, { order: :desc } # clustering column

end

Right now, I am iterating through the rows using a simple where clause and destroy them one by one, I know this is not the right way to do it, but I can't find a way to generate the correct statement to delete them all at once.

How can I use my Users model to generate the above CQL statement.

EDIT: also posted here


Source: (StackOverflow)

Cassandra - Rails custom routing using string as key

I am trying to route to other pages using string as key. I am facing the problem exactly as described here, but I am using cequel.

My model looks like:

class App 
   include Cequel::Record
   key :name, :text
end

The def to_param solution from this stackoverflow is not working in my case. I'm guessing that was because my model does NOT extends ActiveRecord::Base

I tried friendly_id and it didn't help

class App
   include Cequel::Record
   extend FriendlyId
   friendly_id :name, use: :slugged
   key :name, :text
end

Is there some other gem to accomplish custom routing via string key using cequel (cassandra - Rails)


Source: (StackOverflow)

Rails, Cequel - Don't know how to cast to a UUID

I'm following this tutorial (https://medium.com/@olance/rails-4-user-authentication-with-cequel-and-devise-86e1c9ccbcd0), but I'm having problems with the login. When I receive the following error:


ArgumentError in HomeController#index

Don't know how to cast {"n"=>242893962554067921677178635377202198460} to a UUID

Extracted source (around line #423):

      Cql::Uuid.new(value)
    else
      fail ArgumentError,
           "Don't know how to cast #{value.inspect} to a UUID" # Line 423
    end
  end

The model used by devise is:

class User
  include Cequel::Record

  devise :database_authenticatable, :registerable

  key :id, :uuid, auto => true
  column :username, :varchar, :index => true
  column :name, :varchar
  column :lastname, :varchar
  column :email, :varchar, :index => true
  column :encrypted_password, :varchar
  timestamps
end

If I change the key to a varchar it works, but I wan't to use a UUID, so that the user can change the email or its username.

How can it be corrected?


Source: (StackOverflow)

How to create Cassandra tables with cequel (without using rails)

I am using Cequel as ORM for Cassandra without rails.
I have a problem when trying to create a simple list of projects. First I defined the model with three columns which should belong to a compound key.

class Project
  include Cequel::Record

  key :client, :text, { partition: true }
  key :type, :text, { partition: true }
  key :dep, :text, { partition: true }

end

Later when I try to create the Project via

project = Project.create!({client: "test", type: "test", dep: "test"})

I get an error that the table does not exist. The tables are not created automatically with Project.create! but I have to create the table manually first:

  connection.schema.create_table(:projects) do 
    partition_key :client, :text
    partition_key :type, :text
    partition_key :dept, :text
  end

But this syntax is different from the documented Record definition and I only found it by sifting through the source code. But this creates two problems.

  • Code overhead
  • I don't know the syntax for has_many and belongs_to so I cannot create the table correctly if the Record includes this

Am I overlooking a method to create the table automatically from the Project class definition?


Source: (StackOverflow)

Cannot find to_s method for #{Set}, Cequel set model attribute with Rails

In Cequel this is my model for RoR,

class Fileinfo
  include Cequel::Record

  key :fileid, :timeuuid, auto: true
  column :filepath, :text, :index => true
  set :test, :int

  timestamps
end

Rails scaffold generates the form which is used for new,create apis() like this

 <div class="field">
    <%= f.label :fileid %><br>
    <%= f.text_field :fileid %>
  </div>
  <div class="field">
    <%= f.label :filepath %><br>
    <%= f.text_field :filepath %>
  </div>

  <div class="field">
    <%= f.label :test %><br>
    <%= f.text_field :test %>
  </div>

When i start the rails4 server, I get a error for the test(Set Datatype) field undefined method to_s for #{Set } at this line in the rails form <%= f.text_field :test %>.

Even if i define the method to_s the issue persists. Any idea where and how the to_s method needs to be defined here.


Source: (StackOverflow)

rake cequel:migrate command not working in rails

I have created the models using "rails generate cequel ..."
but when I run the "rake cequel:keyspace:create" and "rake cequel:migrate" commands, Nothing happens.

The port in my cequel.yml is set to 9160 and the host is 127.0.0.1

I'm currently using Datastax 2.0.9
My cequel version is 1.5.0


Source: (StackOverflow)

Defining table compound primary keys in rails for Cassandra

Given the following pseudo-cql table structure:

CREATE TABLE searches (
  category text, 
  timestamp timestamp, 
  no_of_searches int, 
  avg_searches double, 
  PRIMARY KEY((category, timestamp), no_of_searches)
);

and the following Rails Cequel model:

class Search
  include Cequel::Record

  # Table columns
  key :category,        :text
  key :timestamp,       :timestamp 
  key :no_of_searches,  :int
  column :avg_searches, :double
end

when I try to synchronise the model using:

rake cequel:migrate

the following rake error is thrown:

rake aborted!
Cequel::InvalidSchemaMigration: Existing partition keys category,timestamp differ from specified partition keys timestamp

I'm trying to get the above rails model to synchronise with the above table using the partition keys, although it's stating that the two sets of keys are different. I've tried defining the keys in the same order, but has not worked.

My objective is to get the pre-defined database table with partition keys working with the rails model. Any help would be grateful!


Source: (StackOverflow)

Getting an error when trying to save a table entry

I have a problem when trying to create a simple list of projects. First I defined the model with three columns which should belong to a compound key.

class Project
  include Cequel::Record

  key :client, :text, { partition: true }
  key :type, :text, { partition: true }
  key :dep, :text, { partition: true }

end

Later when I try to create the Project via

project = Project.create!({client: "test", type: "test", dep: "test"})

I get the following error:

/usr/local/rvm/gems/ruby-2.1.5/gems/cequel-1.6.1/lib/cequel/record/callbacks.rb:34:in `save': undefined method `batch' for nil:NilClass (NoMethodError)

The error message is not very descriptive. Can someone help here?

---edit----

I have found the problem. After connecting, I have to set set class member of Cequel::Record.

connection = Cequel::connect(config);
Cequel::Record.connection = connection

This is probably because I don't use rails but only normal ruby.
Now I ran into another problem. The tables are not created automatically with Project.create! but I have to create the table manually first:

  connection.schema.create_table(:projects) do 
    partition_key :client, :text
    partition_key :type, :text
    partition_key :dept, :text
  end

But this syntax is different from the documented Record definition and I only found it by sifting through the source code. But this creates two problems.

  • Code overhead
  • I don't know the syntax for has_many and belongs_to so I cannot create the table correctly if the Record includes this

Am I overlooking a method to create the table automatically from the Project class definition?


Source: (StackOverflow)

rails 4 app with 2 databases: MySQL and Cassandra - where to begin?

Hi have an existing rails 4 app which is using a MySQL database.

I now need to add code that creates dynamically a new table for every object and its attributes.

I decided to use a No SQL solution for this. Initially I wanted to use Mongo DB since I was familair with this. However, my company supports only Cassandra/redis/solr. So I have to pick one of these.

I chose Cassandra but Im not finding any tutorials or examples on how to use it with an existing rails app with a MySQL DB.

I found this ORM for rails-Cassandra but no idea how to make it work with an existing Active record - mysql system.

Any ideas would be very appreciated.

Apologize this post has no code. But I couldnt find any answers for this issue on SO so please excuse if any mistakes.

thanks


Source: (StackOverflow)