use of com.baidu.hugegraph.exception.NotSupportException in project incubator-hugegraph by apache.
the class TraversalUtil method parsePredicate.
public static P<Object> parsePredicate(String predicate) {
/*
* Extract P from json string like {"properties": {"age": "P.gt(18)"}}
* the `predicate` may actually be like "P.gt(18)"
*/
Pattern pattern = Pattern.compile("^P\\.([a-z]+)\\(([\\S ]*)\\)$");
Matcher matcher = pattern.matcher(predicate);
if (!matcher.find()) {
throw new HugeException("Invalid predicate: %s", predicate);
}
String method = matcher.group(1);
String value = matcher.group(2);
switch(method) {
case "eq":
return P.eq(predicateNumber(value));
case "neq":
return P.neq(predicateNumber(value));
case "lt":
return P.lt(predicateNumber(value));
case "lte":
return P.lte(predicateNumber(value));
case "gt":
return P.gt(predicateNumber(value));
case "gte":
return P.gte(predicateNumber(value));
case "between":
Number[] params = predicateNumbers(value, 2);
return P.between(params[0], params[1]);
case "inside":
params = predicateNumbers(value, 2);
return P.inside(params[0], params[1]);
case "outside":
params = predicateNumbers(value, 2);
return P.outside(params[0], params[1]);
case "within":
return P.within(predicateArgs(value));
case "textcontains":
return ConditionP.textContains(predicateArg(value));
case "contains":
// Just for inner use case like auth filter
return ConditionP.contains(predicateArg(value));
default:
throw new NotSupportException("predicate '%s'", method);
}
}
use of com.baidu.hugegraph.exception.NotSupportException in project incubator-hugegraph by apache.
the class TraversalUtil method parsePredicate.
public static Condition parsePredicate(PropertyKey pk, String predicate) {
Pattern pattern = Pattern.compile("^P\\.([a-z]+)\\(([\\S ]*)\\)$");
Matcher matcher = pattern.matcher(predicate);
if (!matcher.find()) {
throw new HugeException("Invalid predicate: %s", predicate);
}
String method = matcher.group(1);
String value = matcher.group(2);
Object validValue;
switch(method) {
case "eq":
validValue = validPropertyValue(predicateNumber(value), pk);
return Condition.eq(pk.id(), validValue);
case "neq":
validValue = validPropertyValue(predicateNumber(value), pk);
return Condition.neq(pk.id(), validValue);
case "lt":
validValue = validPropertyValue(predicateNumber(value), pk);
return Condition.lt(pk.id(), validValue);
case "lte":
validValue = validPropertyValue(predicateNumber(value), pk);
return Condition.lte(pk.id(), validValue);
case "gt":
validValue = validPropertyValue(predicateNumber(value), pk);
return Condition.gt(pk.id(), validValue);
case "gte":
validValue = validPropertyValue(predicateNumber(value), pk);
return Condition.gte(pk.id(), validValue);
case "between":
Number[] params = predicateNumbers(value, 2);
Object v1 = validPropertyValue(params[0], pk);
Object v2 = validPropertyValue(params[1], pk);
return Condition.and(Condition.gte(pk.id(), v1), Condition.lt(pk.id(), v2));
case "inside":
params = predicateNumbers(value, 2);
v1 = validPropertyValue(params[0], pk);
v2 = validPropertyValue(params[1], pk);
return Condition.and(Condition.gt(pk.id(), v1), Condition.lt(pk.id(), v2));
case "outside":
params = predicateNumbers(value, 2);
v1 = validPropertyValue(params[0], pk);
v2 = validPropertyValue(params[1], pk);
return Condition.and(Condition.lt(pk.id(), v1), Condition.gt(pk.id(), v2));
case "within":
List<T> values = predicateArgs(value);
List<T> validValues = new ArrayList<>(values.size());
for (T v : values) {
validValues.add(validPropertyValue(v, pk));
}
return Condition.in(pk.id(), validValues);
case "textcontains":
validValue = validPropertyValue(value, pk);
return Condition.textContains(pk.id(), (String) validValue);
case "contains":
validValue = validPropertyValue(value, pk);
return Condition.contains(pk.id(), validValue);
default:
throw new NotSupportException("predicate '%s'", method);
}
}
use of com.baidu.hugegraph.exception.NotSupportException 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);
}
use of com.baidu.hugegraph.exception.NotSupportException in project incubator-hugegraph by apache.
the class Reflection method registerFieldsToFilter.
public static void registerFieldsToFilter(Class<?> containingClass, String... fieldNames) {
if (REGISTER_FILEDS_TO_FILTER_METHOD == null) {
throw new NotSupportException("Reflection.registerFieldsToFilter()");
}
try {
REGISTER_FILEDS_TO_FILTER_METHOD.setAccessible(true);
REGISTER_FILEDS_TO_FILTER_METHOD.invoke(REFLECTION_CLAZZ, containingClass, fieldNames);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new HugeException("Failed to register class '%s' fields to filter: %s", containingClass, Arrays.toString(fieldNames));
}
}
use of com.baidu.hugegraph.exception.NotSupportException in project incubator-hugegraph by apache.
the class GraphIndexTransaction method queryByUserprop.
@Watched(prefix = "index")
private IdHolderList queryByUserprop(ConditionQuery query) {
// related index labels
if (!this.graph().readMode().showOlap()) {
for (Id pkId : query.userpropKeys()) {
PropertyKey propertyKey = this.graph().propertyKey(pkId);
if (propertyKey.olap()) {
throw new NotAllowException("Not allowed to query by olap property key '%s'" + " when graph-read-mode is '%s'", propertyKey, this.graph().readMode());
}
}
}
Set<MatchedIndex> indexes = this.collectMatchedIndexes(query);
if (indexes.isEmpty()) {
Id label = query.condition(HugeKeys.LABEL);
throw noIndexException(this.graph(), query, label);
}
// Value type of Condition not matched
boolean paging = query.paging();
if (!validQueryConditionValues(this.graph(), query)) {
return IdHolderList.empty(paging);
}
// Do index query
IdHolderList holders = new IdHolderList(paging);
for (MatchedIndex index : indexes) {
for (IndexLabel il : index.indexLabels()) {
validateIndexLabel(il);
}
if (paging && index.indexLabels().size() > 1) {
throw new NotSupportException("joint index query in paging");
}
if (index.containsSearchIndex()) {
// Do search-index query
holders.addAll(this.doSearchIndex(query, index));
} else {
// Do secondary-index, range-index or shard-index query
IndexQueries queries = index.constructIndexQueries(query);
assert !paging || queries.size() <= 1;
IdHolder holder = this.doSingleOrJointIndex(queries);
holders.add(holder);
}
/*
* NOTE: need to skip the offset if offset > 0, but can't handle
* it here because the query may a sub-query after flatten,
* so the offset will be handle in QueryList.IndexQuery
*
* TODO: finish early here if records exceeds required limit with
* FixedIdHolder.
*/
}
return holders;
}
Aggregations