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 1B73B10C01 for ; Mon, 2 Mar 2015 11:46:11 +0000 (UTC) Received: (qmail 3859 invoked by uid 500); 2 Mar 2015 11:46:03 -0000 Delivered-To: apmail-cassandra-user-archive@cassandra.apache.org Received: (qmail 3834 invoked by uid 500); 2 Mar 2015 11:46:02 -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 3823 invoked by uid 99); 2 Mar 2015 11:46:02 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Mar 2015 11:46:02 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,MIME_QP_LONG_LINE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of woolfel@gmail.com designates 209.85.216.44 as permitted sender) Received: from [209.85.216.44] (HELO mail-qa0-f44.google.com) (209.85.216.44) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Mar 2015 11:45:56 +0000 Received: by mail-qa0-f44.google.com with SMTP id n8so22251563qaq.3 for ; Mon, 02 Mar 2015 03:45:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:references:from:content-type:in-reply-to:message-id:date:to :content-transfer-encoding:mime-version; bh=RmmPAe+EKcF1RHcjcFLqRZLmhOzSHskgmccybcmUtLA=; b=jpjHFZDS2NKbyJighLuuhKkojFxc3GvZTJy0wyhIj6zEw6r7XhG4SWfmsweU1lbhEO Hf2e8aX7bl3grGkiWMvRCEUmFQAuURq5/FKpbwrF6Vtom4UzJCNrcmPNQqSU8h3EjHkV 9/YzO9KnLaQLeOJQsxPb1hv/H6zkVKq0Y6IHJTD05peiKD+GSJ5u0g345K1VgOnJ68Zk xlye/eqi5SrpN02AxT//VVzgq63FvwTRlKLcGMD0Blx2gR0Ck42n/xO3x9UTTXOVOaOK XTIoqPGdd0dh8KHdBAHVeqEQbGJSl7SYwzgOf+J061doeY8v+gC7dE03EU2KOlNVbZMk 84Aw== X-Received: by 10.140.96.165 with SMTP id k34mr26607067qge.79.1425296735661; Mon, 02 Mar 2015 03:45:35 -0800 (PST) Received: from [10.101.134.230] (mobile-166-171-187-209.mycingular.net. [166.171.187.209]) by mx.google.com with ESMTPSA id t16sm8242770qac.23.2015.03.02.03.45.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 02 Mar 2015 03:45:34 -0800 (PST) Subject: Re: how to make unique coloumns in cassandra References: From: Peter Lin Content-Type: multipart/alternative; boundary=Apple-Mail-6D24E267-4513-46DC-BA8D-620870B73CCF X-Mailer: iPhone Mail (12B466) In-Reply-To: Message-Id: Date: Mon, 2 Mar 2015 06:45:32 -0500 To: "user@cassandra.apache.org" Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (1.0) X-Virus-Checked: Checked by ClamAV on apache.org --Apple-Mail-6D24E267-4513-46DC-BA8D-620870B73CCF Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Use a RDBMS=20 There is a reason constraints were created and why Cassandra doesn't have it= Sent from my iPhone > On Mar 2, 2015, at 2:23 AM, Rahul Srivastava wrote: >=20 > but what if i want to fetch the value using on table then this idea might f= ail >=20 >> On Mon, Mar 2, 2015 at 12:46 PM, Ajaya Agrawal wrote= : >> Make a table for each of the unique keys. For e.g. >>=20 >> If primary key for user table is user_id and you want the phone number co= lumn to be unique then create another table wherein the primary key is (phon= e_number, user_id). Before inserting to main table try to insert to this tab= le 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 t= able delete the corresponding row in all other tables. The order of insertio= n to tables matter here otherwise you would end up inducing race conditions.= >>=20 >> The catch here is, you should not be updating the unique column ever. If y= ou do that you would have to use locks and if there are multiple nodes runni= ng your application then you would need a distributed lock. I would suggest n= ot to update the unique columns. In stead force your users to delete the ent= ry 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 requ= irements. >>=20 >> Hope this helps! >>=20 >> -Ajaya >>=20 >> Cheers, >> Ajaya >>=20 >>> On Fri, Feb 27, 2015 at 5:26 PM, ROBIN SRIVASTAVA wrote: >>> I want to make unique constraint in cassandra . As i want that all the v= alue in my column be unique in my column family ex: name-rahul phone-123 add= ress-abc >>>=20 >>> now i want that in this row no values equal to rahul ,123 and abc get in= serted 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 ge= tting all the three values unique means if name- jacob phone-123 address-qwe= >>>=20 >>> this should also be not inserted into my database as my phone column has= the same value as i have shown with name-rahul. >>>=20 >=20 --Apple-Mail-6D24E267-4513-46DC-BA8D-620870B73CCF Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Use a RDBMS 

=
There is a reason constraints were created and why Cassandra doesn't ha= ve it

Sent from my iPhone

On Mar 2, 2015, at 2:23 AM, R= ahul Srivastava <srivasta= va.robin71@gmail.com> wrote:

<= div>
but what if i want to fetch the value using on table th= en this idea might fail

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

If primary ke= y for user table is user_id and you want the phone number column to be uniqu= e then create another table wherein the primary key is (phone_number, user_i= d). Before inserting to main table try to insert to this table first with "i= f not exists" clause. If it succeeds then go ahead with your insert to the u= ser table. Similarly while deleting a row from the primary table delete the c= orresponding row in all other tables. The order of insertion to tables matte= r here otherwise you would end up inducing race conditions.

The catch here is, you should not be updating the unique column eve= r. If you do that you would have to use locks and if there are multiple node= s running your application then you would need a distributed lock. I would s= uggest 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 c= hoice of database. Perhaps a relational database would be better suited to y= our requirements.

Hope this helps!
=
-Ajaya

Cheers,
Ajaya

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

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

now i want that in t= his row no values equal to rahul ,123 and abc get inserted again on searchin= g on datastax i found that i can achieve it by doing query on partition key a= s IF NOT EXIST ,but not getting the solution for getting all the three value= s unique means if name- jacob phone-123 address-qwe

this should also b= e not inserted into my database as my phone column has the same value as i h= ave shown with name-rahul.



= --Apple-Mail-6D24E267-4513-46DC-BA8D-620870B73CCF--