com.aerospike.jdbc.predicate.QueryPredicateRange Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aerospike-jdbc Show documentation
Show all versions of aerospike-jdbc Show documentation
A JDBC driver for the Aerospike database
package com.aerospike.jdbc.predicate;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.query.Filter;
import com.google.common.base.Preconditions;
import java.util.Optional;
public class QueryPredicateRange extends QueryPredicateBase {
private final Object lowValue;
private final Object highValue;
public QueryPredicateRange(
String binName,
Object lowValue,
Object highValue
) {
super(binName, getValueType(lowValue));
Preconditions.checkState(getValueType(lowValue) == getValueType(highValue));
this.lowValue = lowValue;
this.highValue = highValue;
}
@Override
public Exp toFilterExpression(boolean withPrimaryKey) {
// ANSI SQL defines the BETWEEN operator to be inclusive,
// so both boundary values are included in the range.
return Exp.and(
Exp.ge(buildLeftExp(), getValueExp(lowValue)),
Exp.le(buildLeftExp(), getValueExp(highValue))
);
}
@Override
public Optional toFilter(String binName) {
if (binName.equals(this.binName) && valueType == Exp.Type.INT) {
return Optional.of(Filter.range(binName, (long) lowValue, (long) highValue));
}
return Optional.empty();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy