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);
}
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);
}
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);
}
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);
}
Aggregations