use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class HugeVertexStep method constructEdgesQuery.
protected ConditionQuery constructEdgesQuery(Traverser.Admin<Vertex> traverser) {
HugeGraph graph = TraversalUtil.getGraph(this);
// Query for edge with conditions(else conditions for vertex)
boolean withEdgeCond = this.withEdgeCondition();
boolean withVertexCond = this.withVertexCondition();
Id vertex = (Id) traverser.get().id();
Directions direction = Directions.convert(this.getDirection());
Id[] edgeLabels = graph.mapElName2Id(this.getEdgeLabels());
LOG.debug("HugeVertexStep.edges(): vertex={}, direction={}, " + "edgeLabels={}, has={}", vertex, direction, edgeLabels, this.hasContainers);
ConditionQuery query = GraphTransaction.constructEdgesQuery(vertex, direction, edgeLabels);
// Query by sort-keys
if (withEdgeCond && edgeLabels.length == 1) {
TraversalUtil.fillConditionQuery(query, this.hasContainers, graph);
if (!GraphTransaction.matchPartialEdgeSortKeys(query, graph)) {
// Can't query by sysprop and by index (HugeGraph-749)
query.resetUserpropConditions();
} else if (GraphTransaction.matchFullEdgeSortKeys(query, graph)) {
// All sysprop conditions are in sort-keys
withEdgeCond = false;
} else {
// Partial sysprop conditions are in sort-keys
assert query.userpropKeys().size() > 0;
}
}
// Query by has(id)
if (query.idsSize() > 0) {
// Ignore conditions if query by edge id in has-containers
// FIXME: should check that the edge id matches the `vertex`
query.resetConditions();
LOG.warn("It's not recommended to query by has(id)");
}
/*
* Unset limit when needed to filter property after store query
* like query: outE().has(k,v).limit(n)
* NOTE: outE().limit(m).has(k,v).limit(n) will also be unset limit,
* Can't unset limit if query by paging due to page position will be
* exceeded when reaching the limit in tinkerpop layer
*/
if (withEdgeCond || withVertexCond) {
com.baidu.hugegraph.util.E.checkArgument(!this.queryInfo().paging(), "Can't query by paging " + "and filtering");
this.queryInfo().limit(Query.NO_LIMIT);
}
query = this.injectQueryInfo(query);
return query;
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class HugeTraverser method fillFilterBySortKeys.
private void fillFilterBySortKeys(Query query, Id[] edgeLabels, Map<Id, Object> properties) {
if (properties == null || properties.isEmpty()) {
return;
}
E.checkArgument(edgeLabels.length == 1, "The properties filter condition can be set " + "only if just set one edge label");
this.fillFilterByProperties(query, properties);
ConditionQuery condQuery = (ConditionQuery) query;
if (!GraphTransaction.matchFullEdgeSortKeys(condQuery, this.graph())) {
Id label = condQuery.condition(HugeKeys.LABEL);
E.checkArgument(false, "The properties %s does not match " + "sort keys of edge label '%s'", this.graph().mapPkId2Name(properties.keySet()), this.graph().edgeLabel(label).name());
}
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class HugeVariables method createVariableQuery.
private ConditionQuery createVariableQuery(String name) {
ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
VertexLabel vl = this.variableVertexLabel();
query.eq(HugeKeys.LABEL, vl.id());
if (name != null) {
PropertyKey pkey = this.params.graph().propertyKey(Hidden.hide(VARIABLE_KEY));
query.query(Condition.eq(pkey.id(), name));
}
query.showHidden(true);
return query;
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class ScyllaDBTablesWithMV method isQueryBySpecifiedKey.
private static boolean isQueryBySpecifiedKey(Query query, HugeKeys key) {
Collection<Condition> conditions = query.conditions();
if (query instanceof ConditionQuery && !conditions.isEmpty()) {
ConditionQuery cq = (ConditionQuery) query;
Object value = cq.condition(key);
return value != null && cq.allSysprop() && conditions.size() == 1 && cq.containsRelation(key, Condition.RelationType.EQ);
}
return false;
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class MysqlTable method query2Select.
protected List<StringBuilder> query2Select(String table, Query query) {
// Build query
StringBuilder select = new StringBuilder(64);
select.append("SELECT ");
// Set aggregate
Aggregate aggregate = query.aggregate();
if (aggregate != null) {
select.append(aggregate.toString());
} else {
select.append("*");
}
// Set table
select.append(" FROM ").append(table);
// Is query by id?
List<StringBuilder> ids = this.queryId2Select(query, select);
List<StringBuilder> selections;
if (query.conditionsSize() == 0) {
// Query only by id
LOG.debug("Query only by id(s): {}", ids);
selections = ids;
} else {
ConditionQuery condQuery = (ConditionQuery) query;
if (condQuery.containsScanRelation()) {
assert ids.size() == 1;
return ImmutableList.of(queryByRange(condQuery, ids.get(0)));
}
selections = new ArrayList<>(ids.size());
for (StringBuilder selection : ids) {
// Query by condition
selections.addAll(this.queryCondition2Select(query, selection));
}
LOG.debug("Query by conditions: {}", selections);
}
// Set page, order-by and limit
for (StringBuilder selection : selections) {
boolean hasOrder = !query.orders().isEmpty();
if (hasOrder) {
this.wrapOrderBy(selection, query);
}
if (query.paging()) {
this.wrapPage(selection, query, false);
wrapLimit(selection, query);
} else {
if (aggregate == null && !hasOrder) {
select.append(this.orderByKeys());
}
if (!query.noLimit() || query.offset() > 0L) {
this.wrapOffset(selection, query);
}
}
}
return selections;
}
Aggregations