Search in sources :

Example 6 with ValueTuple

use of datawave.query.attributes.ValueTuple in project datawave by NationalSecurityAgency.

the class EvaluationPhaseFilterFunctions method betweenLoadDates.

/**
 * Searches for a load date between start and end (inclusively)
 *
 * @param fieldValue
 *            An iterable of field value as "time since epoch" longs: should be LOAD_DATE
 * @param start
 *            A start date in the supplied rangePattern format
 * @param end
 *            An end date in the supplied rangePattern format
 * @param rangePattern
 *            A date format to be supplied to java.text.SimpleDateFormat
 * @return True if the datetime occurs between the provided datetime values
 */
public static FunctionalSet<ValueTuple> betweenLoadDates(Iterable<?> fieldValue, String start, String end, String rangePattern) {
    FunctionalSet<ValueTuple> matches = FunctionalSet.emptySet();
    if (fieldValue != null) {
        try {
            DateFormat rangeFormat = newSimpleDateFormat(rangePattern);
            int granularity = getGranularity(rangePattern);
            long lStart = getTime(start, rangeFormat);
            long lEnd = getNextTime(end, rangeFormat, granularity) - 1;
            for (Object o : fieldValue) {
                if (betweenInclusive(Long.parseLong(ValueTuple.getStringValue(o)), lStart, lEnd)) {
                    matches = FunctionalSet.singleton(getHitTerm(o));
                    break;
                }
            }
        } catch (ParseException pe) {
            log.error(pe.getMessage());
        } catch (NumberFormatException nfe) {
            log.error("Unable to numeric argument " + start + " or " + end + ": " + nfe.getMessage());
        }
    }
    return matches;
}
Also used : ValueTuple(datawave.query.attributes.ValueTuple) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ParseException(java.text.ParseException)

Example 7 with ValueTuple

use of datawave.query.attributes.ValueTuple in project datawave by NationalSecurityAgency.

the class EvaluationPhaseFilterFunctions method getSizeOf.

private static int getSizeOf(Iterable<?> iterable) {
    if (iterable != null) {
        int sourcedFromEvent = 0;
        int sourcedFromIndex = 0;
        int nonValueTuples = 0;
        for (Object o : iterable) {
            if (o instanceof ValueTuple) {
                ValueTuple valueTuple = (ValueTuple) o;
                Attribute<?> attribute = valueTuple.getSource();
                // Count which fields were found from the events vs. the index.
                if (attribute.isFromIndex()) {
                    sourcedFromIndex++;
                } else {
                    sourcedFromEvent++;
                }
            } else {
                nonValueTuples++;
            }
        }
        // If any of the fields were found in the events, only return the number of fields found in the events.
        if (sourcedFromEvent > 0) {
            return sourcedFromEvent;
        } else if (sourcedFromIndex > 0) {
            // If the field was index-only, return the number of fields found in the index.
            return sourcedFromIndex;
        } else {
            // If we found no value tuples, return the number of objects we saw.
            return nonValueTuples;
        }
    }
    return 0;
}
Also used : ValueTuple(datawave.query.attributes.ValueTuple)

Example 8 with ValueTuple

use of datawave.query.attributes.ValueTuple in project datawave by NationalSecurityAgency.

the class EvaluationPhaseFilterFunctions method betweenDates.

/**
 * Searches for a date between start and end (inclusively)
 *
 * @param fieldValue
 *            A field value in the supplied format
 * @param pattern
 *            A date format to be supplied to java.text.SimpleDateFormat
 * @param start
 *            A start date in the supplied rangePattern format
 * @param end
 *            An end date in the supplied rangePattern format
 * @param rangePattern
 *            A date format to be supplied to java.text.SimpleDateFormat
 * @return True if the datetime occurs between the provided datetime values
 */
public static FunctionalSet<ValueTuple> betweenDates(Object fieldValue, String pattern, String start, String end, String rangePattern) {
    FunctionalSet<ValueTuple> matches = FunctionalSet.emptySet();
    if (fieldValue != null) {
        try {
            DateFormat format = newSimpleDateFormat(pattern);
            DateFormat rangeFormat = newSimpleDateFormat(rangePattern);
            int granularity = getGranularity(rangePattern);
            if (betweenInclusive(getTime(fieldValue, format), getTime(start, rangeFormat), getNextTime(end, rangeFormat, granularity) - 1)) {
                matches = FunctionalSet.singleton(getHitTerm(fieldValue));
            }
        } catch (ParseException pe) {
            log.error(pe.getMessage());
        }
    }
    return matches;
}
Also used : ValueTuple(datawave.query.attributes.ValueTuple) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ParseException(java.text.ParseException)

Example 9 with ValueTuple

use of datawave.query.attributes.ValueTuple in project datawave by NationalSecurityAgency.

the class EvaluationPhaseFilterFunctions method compareMinToMaxNormalizedValue.

/**
 * Return the result of comparing the normalized value of the minimum element in {@code set1} to the normalized value of the maximum element in {@code set2}
 * .
 *
 * @param set1
 *            the first set
 * @param set2
 *            the second set
 * @return the comparison result
 */
private static int compareMinToMaxNormalizedValue(FunctionalSet<ValueTuple> set1, FunctionalSet<ValueTuple> set2) {
    ValueTuple min = (ValueTuple) set1.min();
    ValueTuple max = (ValueTuple) set2.max();
    // noinspection unchecked
    return ((Comparable<Object>) min.getNormalizedValue()).compareTo(max.getNormalizedValue());
}
Also used : ValueTuple(datawave.query.attributes.ValueTuple)

Example 10 with ValueTuple

use of datawave.query.attributes.ValueTuple in project datawave by NationalSecurityAgency.

the class GroupingRequiredFilterFunctions method matchesInGroup.

/**
 * <pre>
 * 'args' will be either a matched set of field/regex pairs, or a matched set of field/regex pairs followed by an index integer,
 * in which case the integer is a zero based value to determine where to split off the 'group'.
 * FOO.1 with a index of '0' will split off '1'
 * FOO.BLAH.ZIP.0 with an index of '2' will split off 'BLAH.ZIP.0'
 * If no index is supplied, the default is 0
 * </pre>
 *
 * @param args
 *            suuplies field/regex pairs with an optional index as the last arg
 * @return a collection of matches
 */
public static Collection<?> matchesInGroup(Object... args) {
    // this is either '0', or it is the integer value of the last argument
    // when the argumentCount is odd
    int positionFromRight = 0;
    if (args.length % 2 != 0) {
        // it's odd
        Object lastArgument = args[args.length - 1];
        positionFromRight = Integer.parseInt(lastArgument.toString());
    }
    Collection<ValueTuple> leftSideMatches;
    Collection<ValueTuple> allMatches = new HashSet<>();
    Object fieldValue1 = args[0];
    String regex = args[1].toString();
    if (fieldValue1 instanceof Iterable) {
        // cast as Iterable in order to call the right getAllMatches method
        leftSideMatches = EvaluationPhaseFilterFunctions.getAllMatches((Iterable) fieldValue1, regex);
    } else {
        leftSideMatches = EvaluationPhaseFilterFunctions.getAllMatches(fieldValue1, regex);
    }
    for (ValueTuple currentMatch : leftSideMatches) {
        String matchFieldName = ValueTuple.getFieldName(currentMatch);
        // my fieldValue2 will be a collection that looks like [ AGE.FOO.7.1:1, GENDER.BAZ.7.2:2, NAME.FO.7.3:1 ]
        // I am only interested in a match on the one that ends with the 'tail' (.2) that I found above
        String context = EvaluationPhaseFilterFunctions.getMatchToRightOfPeriod(matchFieldName, positionFromRight);
        for (int i = 2; i < args.length; i += 2) {
            if (args[i] instanceof Iterable) {
                for (Object fv : (Iterable) args[i]) {
                    manageMatchesInGroupRemainingArgs(fv, args[i + 1].toString(), context, allMatches, currentMatch);
                }
            } else if (args[i] instanceof ValueTuple) {
                manageMatchesInGroupRemainingArgs(args[i], args[i + 1].toString(), context, allMatches, currentMatch);
            }
        }
    }
    // number of field/regex pairs
    if (allMatches.size() < args.length / 2) {
        // truncated in case args.length was odd
        allMatches.clear();
    }
    return Collections.unmodifiableCollection(allMatches);
}
Also used : ValueTuple(datawave.query.attributes.ValueTuple) HashSet(java.util.HashSet)

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