I was reading the following link, which provides an introduction to composite columns and I had few doubts, specially regarding the usage of ComponentEquality.EQUAL and ComponentEquality.GREATER_THAN_EQUAL.
In the following example:
Composite start = compositeFrom(startArg, Composite.ComponentEquality.EQUAL);
Composite end = compositeFrom(startArg, Composite.ComponentEquality.GREATER_THAN_EQUAL);
start.addComponent(1,"CA",Composite.ComponentEquality.EQUAL);
end.addComponent(1,"CA",Composite.ComponentEquality.GREATER_THAN_EQUAL);
I'm unable to comprehend why the end component needs GREATER_THAN_EQUAL as equality component. An explanation with example would be really helpful
The way a slice query works in cassandra is that you specify a start column and an end column(limit/isDescending flag too but that is irrelevant here). One way of querying for your use case would be to pass the complete (Composite)column name for the first composite column that starts with US:CA and the last composite column that starts with US:CA. However, you do not know this in advance.
The good thing about slice queries is that the start and end columns do not need to be actual column names. Since column names are always sorted, if the start column in the slice query does not exist, cassandra will start from the next column greater than the start column provided.
So, we need to construct a start column and an end column for your query. As described in the link, a composite object has an e-o-c bit. This bit is used by slice queries.
A composite column has several components. Each component has the e-o-c bit. When a component has this bit set to Equal, Cassandra moves on to look at the next component. When a component has this bit set to GREATER_THAN_EQUAL, Cassandra will keep on looking at columns, until it finds something whose respective component is not equal to the component we are looking for.
So, now consider the example in the link: We want to do a slice query on a column family which has a composite comparator with three components. We want to get all columns where the first component is US and the second component equal to CA.
We have to create a start column and an end column. The start column will have two components(both with EQUAL as e-o-c) and the end column will have first component as EQUAL and the second component as GREATER_THAN_EQUAL. This will match all the columns whose first component is US and second component is CA.
If you set this bit to EQUAL, a slice query will match the first column it finds with start component is equal to 'CA'. This is fine but Cassandra also needs to know the end column for the slice query. For this, it will look at the end composite you provided.
Hope this helped.
EDIT: To make explanation better