use of com.baidu.hugegraph.backend.query.Condition.Relation in project incubator-hugegraph by apache.
the class CassandraTable method relation2Cql.
protected Clause relation2Cql(Relation relation) {
String key = relation.serialKey().toString();
Object value = relation.serialValue();
switch(relation.relation()) {
case EQ:
return QueryBuilder.eq(key, value);
case GT:
return QueryBuilder.gt(key, value);
case GTE:
return QueryBuilder.gte(key, value);
case LT:
return QueryBuilder.lt(key, value);
case LTE:
return QueryBuilder.lte(key, value);
case IN:
return Clauses.in(key, (List<?>) value);
case CONTAINS_VALUE:
return QueryBuilder.contains(key, value);
case CONTAINS_KEY:
return QueryBuilder.containsKey(key, value);
case SCAN:
String[] col = pkColumnName().stream().map(pk -> formatKey(pk)).toArray(String[]::new);
Shard shard = (Shard) value;
Object start = QueryBuilder.raw(shard.start());
Object end = QueryBuilder.raw(shard.end());
return Clauses.and(QueryBuilder.gte(QueryBuilder.token(col), start), QueryBuilder.lt(QueryBuilder.token(col), end));
// return QueryBuilder.like(key, value);
case NEQ:
default:
throw new NotSupportException("relation '%s'", relation);
}
}
use of com.baidu.hugegraph.backend.query.Condition.Relation in project incubator-hugegraph by apache.
the class ConditionQuery method query.
public ConditionQuery query(Condition condition) {
// Query by id (HugeGraph-259)
if (condition instanceof Relation) {
Relation relation = (Relation) condition;
if (relation.key().equals(HugeKeys.ID) && relation.relation() == RelationType.EQ) {
E.checkArgument(relation.value() instanceof Id, "Invalid id value '%s'", relation.value());
super.query((Id) relation.value());
return this;
}
}
if (this.conditions == EMPTY_CONDITIONS) {
this.conditions = InsertionOrderUtil.newList();
}
this.conditions.add(condition);
return this;
}
use of com.baidu.hugegraph.backend.query.Condition.Relation in project incubator-hugegraph by apache.
the class ConditionQuery method userpropKeys.
public Set<Id> userpropKeys() {
Set<Id> keys = new LinkedHashSet<>();
for (Relation r : this.relations()) {
if (!r.isSysprop()) {
Condition.UserpropRelation ur = (Condition.UserpropRelation) r;
keys.add(ur.key());
}
}
return keys;
}
use of com.baidu.hugegraph.backend.query.Condition.Relation in project incubator-hugegraph by apache.
the class ConditionQuery method userpropValuesString.
/**
* This method is only used for secondary index scenario,
* its relation must be EQ
* @param fields the user property fields
* @return the corresponding user property serial values of fields
*/
public String userpropValuesString(List<Id> fields) {
List<Object> values = new ArrayList<>(fields.size());
for (Id field : fields) {
boolean got = false;
for (Relation r : this.userpropRelations()) {
if (r.key().equals(field) && !r.isSysprop()) {
E.checkState(r.relation == RelationType.EQ || r.relation == RelationType.CONTAINS, "Method userpropValues(List<String>) only " + "used for secondary index, " + "relation must be EQ or CONTAINS, but got %s", r.relation());
values.add(r.serialValue());
got = true;
}
}
if (!got) {
throw new BackendException("No such userprop named '%s' in the query '%s'", field, this);
}
}
return concatValues(values);
}
use of com.baidu.hugegraph.backend.query.Condition.Relation in project incubator-hugegraph by apache.
the class HbaseTable method queryByCond.
protected <R> R queryByCond(HbaseSession<R> session, ConditionQuery query) {
if (query.containsScanRelation()) {
E.checkArgument(query.relations().size() == 1, "Invalid scan with multi conditions: %s", query);
Relation scan = query.relations().iterator().next();
Shard shard = (Shard) scan.value();
return this.queryByRange(session, shard, query.page());
}
throw new NotSupportException("query: %s", query);
}
Aggregations