incubator-cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tamar Fraenkel <ta...@tok-media.com>
Subject Re: How can I implement 'LIKE operation in SQL' on values while querying a column family in Cassandra
Date Tue, 15 May 2012 10:56:03 GMT
Do you still need the sample code? I use Hector, well here is an example:
*This is the Column Family definition:*
(I have a composite, but if you like you can have only the UTF8Type).

CREATE COLUMN FAMILY title_indx
    with comparator = 'CompositeType(UTF8Type,UUIDType)'
    and default_validation_class = 'UTF8Type'
    and key_validation_class = 'LongType';

*The Query:*
    SliceQuery<Long, Composite, String> query =
            HFactory.createSliceQuery(CassandraHectorConn.getKeyspace(),
                    LongSerializer.get(),
                    CompositeSerializer.get(),
                    StringSerializer.get());
    query.setColumnFamily("title_indx");
    query.setKey(...)

    Composite start = new Composite();
    start.add(prefix);
    char c = lowerCasePrefix.charAt(lastCharIndex);
    String prefixEnd =  prefix.substring(0, lastCharIndex) + ++c;
    Composite end = new Composite();
    end.add(prefixEnd);

    ColumnSliceIterator<Long, Composite, String> iterator =
              new ColumnSliceIterator<Long, Composite, String>(
                       query, start, end, false)
    while (iterator.hasNext()) {
    ...
   }

Cheers,

*Tamar Fraenkel *
Senior Software Engineer, TOK Media

[image: Inline image 1]

tamar@tok-media.com
Tel:   +972 2 6409736
Mob:  +972 54 8356490
Fax:   +972 2 5612956





On Tue, May 15, 2012 at 1:19 PM, samal <samalgorai@gmail.com> wrote:

> You cannot extract via relative column value.
> It can only extract via value if it has secondary index but exact column
> value need to match.
>
> as tamar suggested you can put value as column "name" , UTF8 comparator.
>
> {
> 'name_abhijit'=>'abhijit'
> 'name_abhishek'=>'abhiskek'
> 'name_atul'=>'atul'
> }
>
> here you can do slice query on column name and get desired result.
>
> /samal
>
> On Tue, May 15, 2012 at 3:29 PM, selam <selamtux@gmail.com> wrote:
>
>> Mapreduce jobs may solve your problem  for batch processing
>>
>>
>> On Tue, May 15, 2012 at 12:49 PM, Abhijit Chanda <
>> abhijit.chanda0@gmail.com> wrote:
>>
>>> Tamar,
>>>
>>> Can you please illustrate little bit with some sample code. It highly
>>> appreciable.
>>>
>>> Thanks,
>>>
>>>
>>> On Tue, May 15, 2012 at 10:48 AM, Tamar Fraenkel <tamar@tok-media.com>wrote:
>>>
>>>> I don't think this is possible, the best you can do is prefix, if your
>>>> order is alphabetical. For example I have a CF with comparator UTF8Type,
>>>> and then I can do slice query and bring all columns that start with the
>>>> prefix, and end with the prefix where you replace the last char with
>>>> the next one in order (i.e. "aaa"-"aab").
>>>>
>>>> Hope that helps.
>>>>
>>>> *Tamar Fraenkel *
>>>> Senior Software Engineer, TOK Media
>>>>
>>>> [image: Inline image 1]
>>>>
>>>> tamar@tok-media.com
>>>> Tel:   +972 2 6409736
>>>> Mob:  +972 54 8356490
>>>> Fax:   +972 2 5612956
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Tue, May 15, 2012 at 7:56 AM, Abhijit Chanda <
>>>> abhijit.chanda0@gmail.com> wrote:
>>>>
>>>>> I don't know the exact value on a column, but I want to do a partial
>>>>> matching to know all available values that matches.
>>>>> I want to do similar kind of operation that LIKE operator in SQL do.
>>>>> Any help is highly appreciated.
>>>>>
>>>>> --
>>>>> Abhijit Chanda
>>>>> Software Developer
>>>>> VeHere Interactive Pvt. Ltd.
>>>>> +91-9748888395
>>>>>
>>>>>
>>>>
>>>
>>>
>>> --
>>> Abhijit Chanda
>>> Software Developer
>>> VeHere Interactive Pvt. Ltd.
>>> +91-9748888395
>>>
>>>
>>
>>
>> --
>> Saygılar && İyi Çalışmalar
>> Timu EREN ( a.k.a selam )
>>
>
>

Mime
View raw message