Search in sources :

Example 1 with ConnectiveP

use of org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP in project unipop by unipop-graph.

the class FilterHelper method createFilter.

public static QueryBuilder createFilter(HasContainer container) {
    String key = container.getKey();
    P predicate = container.getPredicate();
    Object value = predicate.getValue();
    BiPredicate<?, ?> biPredicate = predicate.getBiPredicate();
    if (key.equals("_id"))
        return getIdsFilter(value);
    else if (key.equals("_type"))
        return getTypeFilter(container);
    else if (predicate instanceof ConnectiveP) {
        return handleConnectiveP(key, (ConnectiveP) predicate);
    } else if (biPredicate != null) {
        return predicateToQuery(key, value, biPredicate);
    } else if (predicate instanceof ExistsP)
        return QueryBuilders.existsQuery(key);
    else
        throw new IllegalArgumentException("HasContainer not supported by unipop");
}
Also used : AndP(org.apache.tinkerpop.gremlin.process.traversal.util.AndP) ExistsP(org.unipop.process.predicate.ExistsP) OrP(org.apache.tinkerpop.gremlin.process.traversal.util.OrP) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) P(org.apache.tinkerpop.gremlin.process.traversal.P) ExistsP(org.unipop.process.predicate.ExistsP) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP)

Example 2 with ConnectiveP

use of org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP in project unipop by unipop-graph.

the class JdbcPredicatesTranslator method extractCondition.

private Condition extractCondition(HasContainer hasContainer) {
    String key = hasContainer.getKey();
    P predicate = hasContainer.getPredicate();
    Object value = predicate.getValue();
    BiPredicate<?, ?> biPredicate = predicate.getBiPredicate();
    Field<Object> field = field(key);
    if (predicate instanceof ConnectiveP) {
        return handleConnectiveP(key, (ConnectiveP) predicate);
    } else if (predicate instanceof ExistsP) {
        return field.isNotNull();
    } else
        return predicateToQuery(key, value, biPredicate);
}
Also used : AndP(org.apache.tinkerpop.gremlin.process.traversal.util.AndP) ExistsP(org.unipop.process.predicate.ExistsP) OrP(org.apache.tinkerpop.gremlin.process.traversal.util.OrP) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) P(org.apache.tinkerpop.gremlin.process.traversal.P) ExistsP(org.unipop.process.predicate.ExistsP) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP)

Example 3 with ConnectiveP

use of org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP in project unipop by unipop-graph.

the class JdbcPredicatesTranslator method handleConnectiveP.

private Condition handleConnectiveP(String key, ConnectiveP predicate) {
    List<P> predicates = predicate.getPredicates();
    List<Condition> queries = predicates.stream().map(p -> {
        if (p instanceof ConnectiveP)
            return handleConnectiveP(key, (ConnectiveP) p);
        Object pValue = p.getValue();
        BiPredicate pBiPredicate = p.getBiPredicate();
        return predicateToQuery(key, pValue, pBiPredicate);
    }).collect(Collectors.toList());
    Condition condition = queries.get(0);
    if (predicate instanceof AndP) {
        for (int i = 1; i < queries.size(); i++) {
            condition = condition.and(queries.get(i));
        }
    } else if (predicate instanceof OrP) {
        for (int i = 1; i < queries.size(); i++) {
            condition = condition.or(queries.get(i));
        }
    } else
        throw new IllegalArgumentException("Connective predicate not supported by unipop");
    return condition;
}
Also used : AndP(org.apache.tinkerpop.gremlin.process.traversal.util.AndP) ExistsP(org.unipop.process.predicate.ExistsP) OrP(org.apache.tinkerpop.gremlin.process.traversal.util.OrP) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) P(org.apache.tinkerpop.gremlin.process.traversal.P) Condition(org.jooq.Condition) AndP(org.apache.tinkerpop.gremlin.process.traversal.util.AndP) MultiDateFormat(org.unipop.util.MultiDateFormat) java.util(java.util) DSL(org.jooq.impl.DSL) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) ExistsP(org.unipop.process.predicate.ExistsP) DSL.field(org.jooq.impl.DSL.field) Field(org.jooq.Field) Contains(org.apache.tinkerpop.gremlin.process.traversal.Contains) Collectors(java.util.stream.Collectors) Condition(org.jooq.Condition) Compare(org.apache.tinkerpop.gremlin.process.traversal.Compare) BiPredicate(java.util.function.BiPredicate) OrP(org.apache.tinkerpop.gremlin.process.traversal.util.OrP) PredicatesTranslator(org.unipop.common.util.PredicatesTranslator) Date(org.unipop.process.predicate.Date) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) ParseException(java.text.ParseException) P(org.apache.tinkerpop.gremlin.process.traversal.P) Text(org.unipop.process.predicate.Text) AndP(org.apache.tinkerpop.gremlin.process.traversal.util.AndP) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) OrP(org.apache.tinkerpop.gremlin.process.traversal.util.OrP) BiPredicate(java.util.function.BiPredicate)

Example 4 with ConnectiveP

use of org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP in project unipop by unipop-graph.

the class DateFieldPropertySchema method toPredicate.

@Override
public PredicatesHolder toPredicate(HasContainer has) {
    if (has.getPredicate() instanceof ConnectiveP) {
        List<P> predicates = ((ConnectiveP) has.getPredicate()).getPredicates();
        predicates.forEach(p -> {
            Object dateValue = p.getValue();
            Date parsedDate = fromDisplay(dateValue.toString());
            String formattedDate = toSource(parsedDate);
            p.setValue(formattedDate);
        });
        return PredicatesHolderFactory.predicate(new HasContainer(this.field, has.getPredicate()));
    }
    Object dateValue = has.getValue();
    Date parsedDate = fromDisplay(dateValue.toString());
    String formattedDate = toSource(parsedDate);
    P predicated = has.getPredicate().clone();
    predicated.setValue(formattedDate);
    return PredicatesHolderFactory.predicate(new HasContainer(this.field, predicated));
}
Also used : AndP(org.apache.tinkerpop.gremlin.process.traversal.util.AndP) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) P(org.apache.tinkerpop.gremlin.process.traversal.P) ConnectiveP(org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) JSONObject(org.json.JSONObject)

Aggregations

P (org.apache.tinkerpop.gremlin.process.traversal.P)4 AndP (org.apache.tinkerpop.gremlin.process.traversal.util.AndP)4 ConnectiveP (org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP)4 OrP (org.apache.tinkerpop.gremlin.process.traversal.util.OrP)3 ExistsP (org.unipop.process.predicate.ExistsP)3 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)2 ParseException (java.text.ParseException)1 java.util (java.util)1 BiPredicate (java.util.function.BiPredicate)1 Collectors (java.util.stream.Collectors)1 Compare (org.apache.tinkerpop.gremlin.process.traversal.Compare)1 Contains (org.apache.tinkerpop.gremlin.process.traversal.Contains)1 Condition (org.jooq.Condition)1 Field (org.jooq.Field)1 DSL (org.jooq.impl.DSL)1 DSL.field (org.jooq.impl.DSL.field)1 JSONObject (org.json.JSONObject)1 PredicatesTranslator (org.unipop.common.util.PredicatesTranslator)1 Date (org.unipop.process.predicate.Date)1 Text (org.unipop.process.predicate.Text)1