use of datawave.query.attributes.ValueTuple in project datawave by NationalSecurityAgency.
the class GroupingRequiredFilterFunctionsTest method makeValueTuple.
private ValueTuple makeValueTuple(String csv) {
String[] tokens = csv.split(",");
String field = tokens[0];
Type<String> type = new LcNoDiacriticsType(tokens[1]);
TypeAttribute<String> typeAttribute = new TypeAttribute<>(type, new Key(), true);
String normalized = tokens[2];
return new ValueTuple(field, type, normalized, typeAttribute);
}
use of datawave.query.attributes.ValueTuple in project datawave by NationalSecurityAgency.
the class FunctionalSet method getGroupsForValue.
public Object getGroupsForValue(int value) {
Set<String> groups = Sets.newHashSet();
for (Iterator<T> iterator = iterator(); iterator.hasNext(); ) {
ValueTuple next = iterator.next();
String field = next.first();
Object val = next.getValue();
if (val instanceof String) {
if (((String) val).equals("" + value)) {
groups.add(field.substring(field.indexOf('.') + 1));
}
} else if (val instanceof Number) {
String longValue = ((Number) val).toString();
if (longValue.equals("" + value)) {
groups.add(field.substring(field.indexOf('.') + 1));
}
} else if (val instanceof NumberType) {
String longValue = "" + ((NumberType) val).getDelegate().longValue();
if (longValue.equals("" + value)) {
groups.add(field.substring(field.indexOf('.') + 1));
}
}
}
return groups;
}
use of datawave.query.attributes.ValueTuple in project datawave by NationalSecurityAgency.
the class DatawaveArithmetic method subtract.
/**
* if either one are Dates, try to
*
* @param left
* @param right
* @return
*/
public Object subtract(Object left, Object right) {
if (left == null && right == null) {
return controlNullNullOperands();
}
if (left instanceof ValueTuple && right instanceof ValueTuple) {
Long dateDifference = subtract((ValueTuple) left, (ValueTuple) right);
if (dateDifference != null) {
return dateDifference;
}
}
// if either are floating point (double or float) use double
if (isFloatingPointNumber(left) || isFloatingPointNumber(right)) {
double l = toDouble(left);
double r = toDouble(right);
return new Double(l - r);
}
// if either are bigdecimal use that type
if (left instanceof BigDecimal || right instanceof BigDecimal) {
BigDecimal l = toBigDecimal(left);
BigDecimal r = toBigDecimal(right);
BigDecimal result = l.subtract(r, getMathContext());
return narrowBigDecimal(left, right, result);
}
// otherwise treat as integers
BigInteger l = toBigInteger(left);
BigInteger r = toBigInteger(right);
BigInteger result = l.subtract(r);
return narrowBigInteger(left, right, result);
}
use of datawave.query.attributes.ValueTuple in project datawave by NationalSecurityAgency.
the class DatawaveInterpreter method addHitsForFunction.
/**
* Add a fielded phrase to the HIT_TERM
*
* @param field
* the phrase function hit on this field
* @param node
* an ASTFunctionNode
* @param hitListArithmetic
* a JexlArithmetic that supports hit lists
*/
private void addHitsForFunction(String field, ASTFunctionNode node, HitListArithmetic hitListArithmetic) {
ColumnVisibility cv;
// aggregate individual hits for the content function
Collection<ColumnVisibility> cvs = new HashSet<>();
Attributes source = new Attributes(true);
ContentFunctionsDescriptor.ContentJexlArgumentDescriptor jexlArgDescriptor = new ContentFunctionsDescriptor().getArgumentDescriptor(node);
Set<String> values = jexlArgDescriptor.getHitTermValues();
FunctionalSet<?> set = (FunctionalSet<?>) this.context.get(field);
if (set != null) {
for (ValueTuple tuple : set) {
if (values.contains(tuple.getNormalizedValue())) {
Attribute<?> attr = tuple.getSource();
source.add(attr);
cvs.add(attr.getColumnVisibility());
}
}
}
try {
cv = MarkingFunctionsFactory.createMarkingFunctions().combine(cvs);
} catch (MarkingFunctions.Exception e) {
log.error("Failed to combine column visibilities while generating HIT_TERM for phrase function for field [" + field + "]");
log.error("msg: ", e);
return;
}
source.setColumnVisibility(cv);
// create an Attributes<?> backed ValueTuple
String phrase = jexlArgDescriptor.getHitTermValue();
ValueTuple vt = new ValueTuple(field, phrase, phrase, source);
hitListArithmetic.add(vt);
}
use of datawave.query.attributes.ValueTuple in project datawave by NationalSecurityAgency.
the class EvaluationPhaseFilterFunctionsTest method toValueTuple.
private static ValueTuple toValueTuple(String csv, Function<String, Type<String>> typeConstructor) {
String[] tokens = csv.split(",");
String field = tokens[0];
Type<String> type = typeConstructor.apply(tokens[1]);
TypeAttribute<String> typeAttribute = new TypeAttribute<>(type, new Key(), true);
String normalized = tokens[2];
return new ValueTuple(field, type, normalized, typeAttribute);
}
Aggregations