Search in sources :

Example 11 with ValueTuple

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);
}
Also used : LcNoDiacriticsType(datawave.data.type.LcNoDiacriticsType) TypeAttribute(datawave.query.attributes.TypeAttribute) ValueTuple(datawave.query.attributes.ValueTuple) Key(org.apache.accumulo.core.data.Key)

Example 12 with ValueTuple

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;
}
Also used : NumberType(datawave.data.type.NumberType) ValueTuple(datawave.query.attributes.ValueTuple)

Example 13 with ValueTuple

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);
}
Also used : ValueTuple(datawave.query.attributes.ValueTuple) BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal)

Example 14 with ValueTuple

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);
}
Also used : FunctionalSet(datawave.query.collections.FunctionalSet) Attributes(datawave.query.attributes.Attributes) MarkingFunctions(datawave.marking.MarkingFunctions) ValueTuple(datawave.query.attributes.ValueTuple) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) ContentFunctionsDescriptor(datawave.query.jexl.functions.ContentFunctionsDescriptor) HashSet(java.util.HashSet)

Example 15 with ValueTuple

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);
}
Also used : TypeAttribute(datawave.query.attributes.TypeAttribute) ValueTuple(datawave.query.attributes.ValueTuple) Key(org.apache.accumulo.core.data.Key)

Aggregations

ValueTuple (datawave.query.attributes.ValueTuple)26 DateFormat (java.text.DateFormat)10 ParseException (java.text.ParseException)10 SimpleDateFormat (java.text.SimpleDateFormat)10 HashSet (java.util.HashSet)5 NumberType (datawave.data.type.NumberType)3 Attributes (datawave.query.attributes.Attributes)2 TypeAttribute (datawave.query.attributes.TypeAttribute)2 FunctionalSet (datawave.query.collections.FunctionalSet)2 Key (org.apache.accumulo.core.data.Key)2 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)2 GeoNormalizer (datawave.data.normalizer.GeoNormalizer)1 AbstractGeometryType (datawave.data.type.AbstractGeometryType)1 GeoType (datawave.data.type.GeoType)1 LcNoDiacriticsType (datawave.data.type.LcNoDiacriticsType)1 Type (datawave.data.type.Type)1 AbstractGeometry (datawave.data.type.util.AbstractGeometry)1 MarkingFunctions (datawave.marking.MarkingFunctions)1 Content (datawave.query.attributes.Content)1 Document (datawave.query.attributes.Document)1