Return-Path: X-Original-To: apmail-cassandra-user-archive@www.apache.org Delivered-To: apmail-cassandra-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 82909102DD for ; Mon, 2 Mar 2015 07:25:04 +0000 (UTC) Received: (qmail 98013 invoked by uid 500); 2 Mar 2015 07:25:01 -0000 Delivered-To: apmail-cassandra-user-archive@cassandra.apache.org Received: (qmail 97973 invoked by uid 500); 2 Mar 2015 07:25:01 -0000 Mailing-List: contact user-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cassandra.apache.org Delivered-To: mailing list user@cassandra.apache.org Received: (qmail 97963 invoked by uid 99); 2 Mar 2015 07:25:01 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Mar 2015 07:25:01 +0000 X-ASF-Spam-Status: No, hits=1.7 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of srivastava.robin71@gmail.com designates 209.85.215.68 as permitted sender) Received: from [209.85.215.68] (HELO mail-la0-f68.google.com) (209.85.215.68) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Mar 2015 07:24:35 +0000 Received: by labgq15 with SMTP id gq15so4988547lab.0 for ; Sun, 01 Mar 2015 23:23:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=t8scZcRDomD5T/e8ajjvczm11Cm2dpe+JimpCrmpNPE=; b=X9e7Rh1OSexWpbfNHo+ijW4chuL/G02IpU9Ks4ahyLUuOYFeOQkQuFlmEb7Uzy/Vvu sG2KRFyDRa06yCO/6XnuqK8ybxcqCvzX7cfCaig3Ofe8kzdUeOhH2QZzen9LEXipvn9h 5FWFq1QFthpMgb1gi0pUhjqVojyNrPI61g5h9a4EhucPCpBJaR3AaKKin16Aovn8jvMR Yi3SutXTlAcR7qQwQzqew+xI+mgsR4QMgOUKA45yZE7wIp87+uDVP1FTsyUVthKggNYs 8X/FlHzoahsWsP0WEGJAI6hisL8o9TBFzINWBvumjJs1Ho+/wfCxUnoGqaLqbW8aMvvL QpCA== MIME-Version: 1.0 X-Received: by 10.112.53.137 with SMTP id b9mr23138136lbp.66.1425280984389; Sun, 01 Mar 2015 23:23:04 -0800 (PST) Received: by 10.152.128.202 with HTTP; Sun, 1 Mar 2015 23:23:04 -0800 (PST) In-Reply-To: References: Date: Mon, 2 Mar 2015 12:53:04 +0530 Message-ID: Subject: Re: how to make unique coloumns in cassandra From: Rahul Srivastava To: user@cassandra.apache.org Content-Type: multipart/alternative; boundary=001a11c3a2c2c79e860510491666 X-Virus-Checked: Checked by ClamAV on apache.org --001a11c3a2c2c79e860510491666 Content-Type: text/plain; charset=UTF-8 but what if i want to fetch the value using on table then this idea might fail On Mon, Mar 2, 2015 at 12:46 PM, Ajaya Agrawal wrote: > Make a table for each of the unique keys. For e.g. > > If primary key for user table is user_id and you want the phone number > column to be unique then create another table wherein the primary key is > (phone_number, user_id). Before inserting to main table try to insert to > this table first with "if not exists" clause. If it succeeds then go ahead > with your insert to the user table. Similarly while deleting a row from the > primary table delete the corresponding row in all other tables. The order > of insertion to tables matter here otherwise you would end up inducing race > conditions. > > The catch here is, you should not be updating the unique column ever. If > you do that you would have to use locks and if there are multiple nodes > running your application then you would need a distributed lock. I would > suggest not to update the unique columns. In stead force your users to > delete the entry and recreate it. If you can't do that you need to evaluate > your choice of database. Perhaps a relational database would be better > suited to your requirements. > > Hope this helps! > > -Ajaya > > Cheers, > Ajaya > > On Fri, Feb 27, 2015 at 5:26 PM, ROBIN SRIVASTAVA < > srivastava.robin71@gmail.com> wrote: > >> I want to make unique constraint in cassandra . As i want that all the >> value in my column be unique in my column family ex: name-rahul phone-123 >> address-abc >> >> now i want that in this row no values equal to rahul ,123 and abc get >> inserted again on searching on datastax i found that i can achieve it by >> doing query on partition key as IF NOT EXIST ,but not getting the solution >> for getting all the three values unique means if name- jacob phone-123 >> address-qwe >> >> this should also be not inserted into my database as my phone column has >> the same value as i have shown with name-rahul. >> > > --001a11c3a2c2c79e860510491666 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
but what if i want to fetch the value using on table then = this idea might fail

On Mon, Mar 2, 2015 at 12:46 PM, Ajaya Agrawal &= lt;ajku.agr@gmail.c= om> wrote:
Make a table for each of the unique keys. For e.g.

If primary= key for user table is user_id and you want the phone number column to be u= nique then create another table wherein the primary key is (phone_number, u= ser_id). Before inserting to main table try to insert to this table first w= ith "if not exists" clause. If it succeeds then go ahead with you= r insert to the user table. Similarly while deleting a row from the primary= table delete the corresponding row in all other tables. The order of inser= tion to tables matter here otherwise you would end up inducing race conditi= ons.

The catch here is, you should not be updating= the unique column ever. If you do that you would have to use locks and if = there are multiple nodes running your application then you would need a dis= tributed lock. I would suggest not to update the unique columns. In stead f= orce your users to delete the entry and recreate it. If you can't do th= at you need to evaluate your choice of database. Perhaps a relational datab= ase would be better suited to your requirements.

=
Hope this helps!

-Ajaya

Cheers,<= br>
Ajaya

On Fri, Feb 27, 2015 at 5:26 PM, ROBIN SRIVA= STAVA <srivastava.robin71@gmail.com> wrote:

I want to make = unique constraint in cassandra . As i want that all the value in my column = be unique in my column family ex: name-rahul phone-123 address-abc

now i want that in this row no values equal to rahul ,123 and abc = get inserted again on searching on datastax i found that i can achieve it b= y doing query on partition key as IF NOT EXIST ,but not getting the solutio= n for getting all the three values unique means if name- jacob phone-123 ad= dress-qwe

this should also be not inserted into my databas= e as my phone column has the same value as i have shown with name-rahul.



--001a11c3a2c2c79e860510491666--