cz.jirutka.rsql.parser.ast.RSQLOperators Java Examples
The following examples show how to use
cz.jirutka.rsql.parser.ast.RSQLOperators.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SearchFilterToQueryConverter.java From dremio-oss with Apache License 2.0 | 6 votes |
private SearchQuery createEqualsQuery(final Class<?> cls, final String name, final Object value, final Map<String, SearchQuery> reservedValues) { if (cls.equals(String.class)) { final String strValue = (String)value; if (reservedValues != null && reservedValues.containsKey(strValue)) { return reservedValues.get(strValue); } if (!strValue.contains("*")) { return SearchQueryUtils.newTermQuery(name, strValue); } else { return SearchQueryUtils.newWildcardQuery(name, strValue); } } else if (cls.equals(Boolean.class)) { return createBooleanFieldQuery(name, value); } else { return createRangeQuery(cls, name, value, RSQLOperators.EQUAL); } }
Example #2
Source File: SearchFilterToQueryConverter.java From dremio-oss with Apache License 2.0 | 6 votes |
private SearchQuery createRangeQuery(Class<?> cls, String name, Object value, ComparisonOperator type) { boolean minInclusive = type == RSQLOperators.GREATER_THAN_OR_EQUAL || type == RSQLOperators.EQUAL; boolean maxInclusive = type == RSQLOperators.LESS_THAN_OR_EQUAL || type == RSQLOperators.EQUAL; if (Number.class.isAssignableFrom(cls)) { if (Double.class.isAssignableFrom(cls)) { return createDoubleRangeQuery(name, value, type, minInclusive, maxInclusive); } else if (Float.class.isAssignableFrom(cls)) { return createFloatRangeQuery(name, value, type, minInclusive, maxInclusive); } else if (Long.class.isAssignableFrom(cls)) { return createLongRangeQuery(name, value, type, minInclusive, maxInclusive); } else { return createIntRangeQuery(name, value, type, minInclusive, maxInclusive); } } else if (String.class.isAssignableFrom(cls)) { return createStringRangeQuery(name, value, type, minInclusive, maxInclusive); } else { throw new IllegalArgumentException(format("%s: Can not do range query on field %s of type %s" + "only long, int, double, float types are supported", visitorName, name, cls.getName())); } }
Example #3
Source File: SearchFilterToQueryConverter.java From dremio-oss with Apache License 2.0 | 5 votes |
private SearchQuery buildLeafNodeQuery(final ComparisonNode node) throws IllegalArgumentException { final IndexKey indexKey = mapping.getKey(node.getSelector()); final String name = indexKey != null ? indexKey.getIndexFieldName() : null; final Class<?> clazz = indexKey != null ? indexKey.getValueType() : null; final List<Object> processedArgs = validate(node, name, clazz); if (node.getOperator().equals(RSQLOperators.EQUAL)) { return createEqualsQuery(clazz, name, processedArgs.get(0),indexKey.getReservedValues()); } else if (node.getOperator().equals(RSQLOperators.NOT_EQUAL)) { return SearchQueryUtils.not(createEqualsQuery(clazz, name, processedArgs.get(0), null)); } else if (node.getOperator().equals(RSQLOperators.LESS_THAN)) { return createRangeQuery(clazz, name, processedArgs.get(0), RSQLOperators.LESS_THAN); } else if (node.getOperator().equals(RSQLOperators.LESS_THAN_OR_EQUAL)) { return createRangeQuery(clazz, name, processedArgs.get(0), RSQLOperators.LESS_THAN_OR_EQUAL); } else if (node.getOperator().equals(RSQLOperators.GREATER_THAN)) { return createRangeQuery(clazz, name, processedArgs.get(0), RSQLOperators.GREATER_THAN); } else if (node.getOperator().equals(RSQLOperators.GREATER_THAN_OR_EQUAL)) { return createRangeQuery(clazz, name, processedArgs.get(0), RSQLOperators.GREATER_THAN_OR_EQUAL); } else if (node.getOperator().equals(RSQLOperators.IN)) { throw new IllegalArgumentException("IN operator not yet supported"); } else if (node.getOperator().equals(RSQLOperators.NOT_IN)) { throw new IllegalArgumentException("NOT_IN operator not yet supported"); } else if (node.getOperator().equals(CONTAINS)) { return createMatchAllFieldsQuery((String)processedArgs.get(0), mapping); } else { throw new IllegalArgumentException(format("%s: Invalid search operator %s", visitorName, node.toString())); } }
Example #4
Source File: SearchFilterToQueryConverter.java From dremio-oss with Apache License 2.0 | 5 votes |
private SearchQuery createIntRangeQuery(final String name, final Object value, final ComparisonOperator type, final boolean minInclusive, final boolean maxInclusive) { final Integer intValue = (Integer) value; final Integer minValue = (type != RSQLOperators.LESS_THAN && type != RSQLOperators.LESS_THAN_OR_EQUAL) ? intValue : null; final Integer maxValue = (type != RSQLOperators.GREATER_THAN && type != RSQLOperators.GREATER_THAN_OR_EQUAL) ? intValue : null; return SearchQueryUtils.newRangeInt(name, minValue, maxValue, minInclusive, maxInclusive); }
Example #5
Source File: SearchFilterToQueryConverter.java From dremio-oss with Apache License 2.0 | 5 votes |
private SearchQuery createLongRangeQuery(final String name, final Object value, final ComparisonOperator type, final boolean minInclusive, final boolean maxInclusive) { final Long longValue = (Long) value; final Long minValue = (type != RSQLOperators.LESS_THAN && type != RSQLOperators.LESS_THAN_OR_EQUAL) ? longValue : null; final Long maxValue = (type != RSQLOperators.GREATER_THAN && type != RSQLOperators.GREATER_THAN_OR_EQUAL) ? longValue : null; return SearchQueryUtils.newRangeLong(name, minValue, maxValue, minInclusive, maxInclusive); }
Example #6
Source File: SearchFilterToQueryConverter.java From dremio-oss with Apache License 2.0 | 5 votes |
private SearchQuery createDoubleRangeQuery(final String name, final Object value, final ComparisonOperator type, final boolean minInclusive, final boolean maxInclusive) { final Double doubleValue = (Double) value; final Double minValue = (type != RSQLOperators.LESS_THAN && type != RSQLOperators.LESS_THAN_OR_EQUAL) ? doubleValue : null; final Double maxValue = (type != RSQLOperators.GREATER_THAN && type != RSQLOperators.GREATER_THAN_OR_EQUAL) ? doubleValue : null; return SearchQueryUtils.newRangeDouble(name, minValue, maxValue, minInclusive, maxInclusive); }
Example #7
Source File: SearchFilterToQueryConverter.java From dremio-oss with Apache License 2.0 | 5 votes |
private SearchQuery createFloatRangeQuery(final String name, final Object value, final ComparisonOperator type, final boolean minInclusive, final boolean maxInclusive) { final Float floatValue = (Float) value; final Float minValue = (type != RSQLOperators.LESS_THAN && type != RSQLOperators.LESS_THAN_OR_EQUAL) ? floatValue : null; final Float maxValue = (type != RSQLOperators.GREATER_THAN && type != RSQLOperators.GREATER_THAN_OR_EQUAL) ? floatValue : null; return SearchQueryUtils.newRangeFloat(name, minValue, maxValue, minInclusive, maxInclusive); }
Example #8
Source File: SearchFilterToQueryConverter.java From dremio-oss with Apache License 2.0 | 5 votes |
private SearchQuery createStringRangeQuery(final String name, final Object value, final ComparisonOperator type, final boolean minInclusive, final boolean maxInclusive) { final String stringValue = (String)value; final String minValue = (type != RSQLOperators.LESS_THAN && type != RSQLOperators.LESS_THAN_OR_EQUAL) ? stringValue : null; final String maxValue = (type != RSQLOperators.GREATER_THAN && type != RSQLOperators.GREATER_THAN_OR_EQUAL) ? stringValue : null; return SearchQueryUtils.newRangeTerm(name, minValue, maxValue, minInclusive, maxInclusive); }
Example #9
Source File: RSQLProducerImpl.java From pnc with Apache License 2.0 | 5 votes |
public RSQLProducerImpl() { Set<ComparisonOperator> predicateOperators = RSQLOperators.defaultOperators(); predicateOperators.add(LIKE); predicateOperators.add(NOT_LIKE); predicateOperators.add(IS_NULL); predicateParser = new RSQLParser(predicateOperators); Set<ComparisonOperator> sortOperators = new HashSet<>(); sortOperators.add(ASC); sortOperators.add(DESC); sortParser = new RSQLParser(sortOperators); }
Example #10
Source File: ApiConfig.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
private RSQLParser rsqlParser() { Set<ComparisonOperator> operators = new HashSet<>(RSQLOperators.defaultOperators()); operators.add(new ComparisonOperator("=q=", false)); operators.add(new ComparisonOperator("=sq=", false)); operators.add(new ComparisonOperator("=like=", false)); operators.add(new ComparisonOperator("=notlike=", false)); return new RSQLParser(operators); }
Example #11
Source File: RsqlConfig.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Bean public RSQLParser rsqlParser() { Set<ComparisonOperator> operators = RSQLOperators.defaultOperators(); operators.add(new ComparisonOperator("=q=", false)); operators.add(new ComparisonOperator("=sq=", false)); operators.add(new ComparisonOperator("=notlike=", false)); operators.add(new ComparisonOperator("=rng=", true)); operators.add(new ComparisonOperator("=like=", false)); return new RSQLParser(operators); }