Search in sources :

Example 1 with Term

use of org.apache.cassandra.cql3.Term in project cassandra by apache.

the class SingleColumnRelation method newINRestriction.

@Override
protected Restriction newINRestriction(TableMetadata table, VariableSpecifications boundNames) {
    ColumnMetadata columnDef = entity.prepare(table);
    List<? extends ColumnSpecification> receivers = toReceivers(columnDef);
    List<Term> terms = toTerms(receivers, inValues, table.keyspace, boundNames);
    if (terms == null) {
        Term term = toTerm(receivers, value, table.keyspace, boundNames);
        return new SingleColumnRestriction.InRestrictionWithMarker(columnDef, (Lists.Marker) term);
    }
    // An IN restrictions with only one element is the same than an EQ restriction
    if (terms.size() == 1)
        return new SingleColumnRestriction.EQRestriction(columnDef, terms.get(0));
    return new SingleColumnRestriction.InRestrictionWithValues(columnDef, terms);
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) SingleColumnRestriction(org.apache.cassandra.cql3.restrictions.SingleColumnRestriction)

Example 2 with Term

use of org.apache.cassandra.cql3.Term in project cassandra by apache.

the class SetType method fromJSONObject.

@Override
public Term fromJSONObject(Object parsed) throws MarshalException {
    if (parsed instanceof String)
        parsed = Json.decodeJson((String) parsed);
    if (!(parsed instanceof List))
        throw new MarshalException(String.format("Expected a list (representing a set), but got a %s: %s", parsed.getClass().getSimpleName(), parsed));
    List list = (List) parsed;
    Set<Term> terms = new HashSet<>(list.size());
    for (Object element : list) {
        if (element == null)
            throw new MarshalException("Invalid null element in set");
        terms.add(elements.fromJSONObject(element));
    }
    return new Sets.DelayedValue(elements, terms);
}
Also used : MarshalException(org.apache.cassandra.serializers.MarshalException) Term(org.apache.cassandra.cql3.Term)

Example 3 with Term

use of org.apache.cassandra.cql3.Term in project cassandra by apache.

the class ListType method fromJSONObject.

@Override
public Term fromJSONObject(Object parsed) throws MarshalException {
    if (parsed instanceof String)
        parsed = Json.decodeJson((String) parsed);
    if (!(parsed instanceof List))
        throw new MarshalException(String.format("Expected a list, but got a %s: %s", parsed.getClass().getSimpleName(), parsed));
    List list = (List) parsed;
    List<Term> terms = new ArrayList<>(list.size());
    for (Object element : list) {
        if (element == null)
            throw new MarshalException("Invalid null element in list");
        terms.add(elements.fromJSONObject(element));
    }
    return new Lists.DelayedValue(terms);
}
Also used : MarshalException(org.apache.cassandra.serializers.MarshalException) Term(org.apache.cassandra.cql3.Term)

Example 4 with Term

use of org.apache.cassandra.cql3.Term in project cassandra by apache.

the class MapType method fromJSONObject.

@Override
public Term fromJSONObject(Object parsed) throws MarshalException {
    if (parsed instanceof String)
        parsed = Json.decodeJson((String) parsed);
    if (!(parsed instanceof Map))
        throw new MarshalException(String.format("Expected a map, but got a %s: %s", parsed.getClass().getSimpleName(), parsed));
    Map<Object, Object> map = (Map<Object, Object>) parsed;
    Map<Term, Term> terms = new HashMap<>(map.size());
    for (Map.Entry<Object, Object> entry : map.entrySet()) {
        if (entry.getKey() == null)
            throw new MarshalException("Invalid null key in map");
        if (entry.getValue() == null)
            throw new MarshalException("Invalid null value in map");
        terms.put(keys.fromJSONObject(entry.getKey()), values.fromJSONObject(entry.getValue()));
    }
    return new Maps.DelayedValue(keys, terms);
}
Also used : MarshalException(org.apache.cassandra.serializers.MarshalException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Term(org.apache.cassandra.cql3.Term) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Aggregations

Term (org.apache.cassandra.cql3.Term)3 MarshalException (org.apache.cassandra.serializers.MarshalException)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 SingleColumnRestriction (org.apache.cassandra.cql3.restrictions.SingleColumnRestriction)1 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)1