Search in sources :

Example 1 with Type

use of datawave.data.type.Type in project datawave by NationalSecurityAgency.

the class FunctionalSet method compareWith.

/*
     * revisit this if the incoming min/max from 4.2.0 are insufficient. It has not been used before public ValueTuple min() { ValueTuple min = null; for
     * (Iterator<T> iterator = iterator(); iterator.hasNext();) { ValueTuple next = iterator.next(); if (min == null) { min = next; } else if (compare(min,
     * next) >= 0) { min = next; } } return min; }
     * 
     * public ValueTuple max() { ValueTuple max = null; for (Iterator<T> iterator = iterator(); iterator.hasNext();) { ValueTuple next = iterator.next(); if
     * (max == null) { max = next; } else if (compare(max, next) <= 0) { max = next; } } return max; }
     * 
     * private int compare(ValueTuple left, ValueTuple right) { Object leftValue = left.getValue(); Object rightValue = right.getValue(); if (leftValue
     * instanceof String && rightValue instanceof String) { return ((String) leftValue).compareTo((String) rightValue); } if (leftValue instanceof Number &&
     * rightValue instanceof Number) { return Double.compare(((Number) leftValue).doubleValue(), ((Number) rightValue).doubleValue()); } if (leftValue
     * instanceof Date && rightValue instanceof Date) { return Long.compare(((Date) leftValue).getTime(), ((Date) rightValue).getTime()); } if (leftValue
     * instanceof Type && rightValue instanceof Type) { return ((Type) leftValue).getDelegate().compareTo(((Type) rightValue).getDelegate()); } return 0; }
     */
public Object compareWith(Object reference, String operatorString) {
    Collection<Object> values = new HashSet<>();
    for (Iterator<T> iterator = iterator(); iterator.hasNext(); ) {
        ValueTuple next = iterator.next();
        Object nextValue = next.getValue();
        if (nextValue instanceof Type) {
            Type nextType = (Type) nextValue;
            Class typeClass = nextType.getClass();
            Type referenceType = Type.Factory.createType(typeClass.getName());
            referenceType.setDelegateFromString(reference.toString());
            boolean keep = OperationEvaluator.compare(nextType.normalize(), referenceType.normalize(), operatorString);
            if (keep) {
                values.add(next);
            }
        }
    }
    log.debug("returning:" + values);
    return values;
}
Also used : NumberType(datawave.data.type.NumberType) Type(datawave.data.type.Type) ValueTuple(datawave.query.attributes.ValueTuple) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with Type

use of datawave.data.type.Type in project datawave by NationalSecurityAgency.

the class TypeAttribute method read.

@Override
public void read(Kryo kryo, Input input) {
    try {
        setDatawaveType(input.readString());
    } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
        log.warn("could not read datawateType from input: " + e);
    }
    super.readMetadata(kryo, input);
    if (datawaveType == null)
        datawaveType = (Type) new NoOpType();
    String delegateString = input.readString();
    try {
        datawaveType.setDelegateFromString(delegateString);
    } catch (Exception ex) {
        // there was some problem with setting the delegate as the declared type.
        // Instead of letting this exception fail the query, make this a NoOpType containing the string value from the input
        log.warn("Was unable to make a " + datawaveType + " to contain a delegate created from input:" + delegateString + "  Making a NoOpType instead.");
        datawaveType = (Type) new NoOpType();
        datawaveType.setDelegateFromString(delegateString);
    }
    this.toKeep = input.readBoolean();
}
Also used : NoOpType(datawave.data.type.NoOpType) OneToManyNormalizerType(datawave.data.type.OneToManyNormalizerType) Type(datawave.data.type.Type) NoOpType(datawave.data.type.NoOpType) IOException(java.io.IOException)

Example 3 with Type

use of datawave.data.type.Type in project datawave by NationalSecurityAgency.

the class XMLFieldConfigHelperTest method testMultiType.

@Test
public void testMultiType() throws Exception {
    String input = "<?xml version=\"1.0\"?>\n" + "<fieldConfig>\n" + "    <default stored=\"true\" indexed=\"false\" reverseIndexed=\"false\" tokenized=\"true\" reverseTokenized=\"true\" indexType=\"datawave.data.type.LcNoDiacriticsType\"/>\n" + "    <fieldPattern pattern=\"*J\" indexed=\"true\" indexType=\"datawave.data.type.MacAddressType\"/>\n" + "    <field name=\"H\" indexType=\"datawave.data.type.DateType,datawave.data.type.HexStringType\"/>\n" + "</fieldConfig>";
    FieldConfigHelper helper = new XMLFieldConfigHelper(new ByteArrayInputStream(input.getBytes()), ingestHelper);
    List<Type<?>> types = ingestHelper.getDataTypes("H");
    assertEquals(2, types.size());
}
Also used : NoOpType(datawave.data.type.NoOpType) HexStringType(datawave.data.type.HexStringType) LcNoDiacriticsType(datawave.data.type.LcNoDiacriticsType) Type(datawave.data.type.Type) DateType(datawave.data.type.DateType) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 4 with Type

use of datawave.data.type.Type in project datawave by NationalSecurityAgency.

the class XMLFieldConfigHelperTest method setUp.

@Before
public void setUp() {
    Configuration conf = new Configuration();
    conf.set(DataTypeHelper.Properties.DATA_NAME, "test");
    conf.set("test" + DataTypeHelper.Properties.INGEST_POLICY_ENFORCER_CLASS, IngestPolicyEnforcer.NoOpIngestPolicyEnforcer.class.getName());
    conf.set("test" + BaseIngestHelper.DEFAULT_TYPE, NoOpType.class.getName());
    datawave.ingest.data.Type type = new datawave.ingest.data.Type("test", null, null, new String[] { SimpleDataTypeHandler.class.getName() }, 10, null);
    TypeRegistry.reset();
    TypeRegistry.getInstance(conf).put("test", type);
    ingestHelper.setup(conf);
}
Also used : NoOpType(datawave.data.type.NoOpType) HexStringType(datawave.data.type.HexStringType) LcNoDiacriticsType(datawave.data.type.LcNoDiacriticsType) Type(datawave.data.type.Type) DateType(datawave.data.type.DateType) Configuration(org.apache.hadoop.conf.Configuration) NoOpType(datawave.data.type.NoOpType) SimpleDataTypeHandler(datawave.ingest.mapreduce.SimpleDataTypeHandler) Before(org.junit.Before)

Example 5 with Type

use of datawave.data.type.Type in project datawave by NationalSecurityAgency.

the class DefaultExtendedEdgeQueryLogic method normalizeQualifiedSource.

protected Collection<String> normalizeQualifiedSource(String qualifiedSource) {
    int qualifierStart = qualifiedSource.lastIndexOf('<');
    String source = qualifiedSource;
    String normalizedQualifier = "";
    if (qualifierStart > 0) {
        source = qualifiedSource.substring(0, qualifierStart);
        normalizedQualifier = qualifiedSource.substring(qualifierStart).toLowerCase();
    }
    Set<String> sources = new LinkedHashSet<>();
    List<? extends Type<?>> dataTypes = getDataTypes();
    if (dataTypes == null) {
        dataTypes = Arrays.asList((Type<?>) new LcNoDiacriticsType());
    }
    for (Type<?> type : dataTypes) {
        try {
            String normalizedSource = type.normalize(source);
            if (normalizedSource == null || "".equals(normalizedSource.trim())) {
                continue;
            }
            String normalizedQualifiedSource = normalizedSource + normalizedQualifier;
            sources.add(normalizedQualifiedSource);
        } catch (Exception e) {
        // ignore -- couldn't normalize with this normalizer
        }
    }
    return sources;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) LcNoDiacriticsType(datawave.data.type.LcNoDiacriticsType) LcNoDiacriticsType(datawave.data.type.LcNoDiacriticsType) Type(datawave.data.type.Type) ParseException(org.apache.commons.jexl2.parser.ParseException) JexlException(org.apache.commons.jexl2.JexlException)

Aggregations

Type (datawave.data.type.Type)78 LcNoDiacriticsType (datawave.data.type.LcNoDiacriticsType)58 NoOpType (datawave.data.type.NoOpType)54 NumberType (datawave.data.type.NumberType)54 Test (org.junit.Test)53 ASTJexlScript (org.apache.commons.jexl2.parser.ASTJexlScript)39 ScannerFactory (datawave.query.tables.ScannerFactory)36 MockMetadataHelper (datawave.query.util.MockMetadataHelper)35 Range (org.apache.accumulo.core.data.Range)27 RangeFactoryForTests.makeTestRange (datawave.common.test.utils.query.RangeFactoryForTests.makeTestRange)25 QueryPlan (datawave.query.planner.QueryPlan)25 LcType (datawave.data.type.LcType)16 IpAddressType (datawave.data.type.IpAddressType)12 SimpleDateFormat (java.text.SimpleDateFormat)10 DatawaveFatalQueryException (datawave.query.exceptions.DatawaveFatalQueryException)7 QueryException (datawave.webservice.query.exception.QueryException)7 DateType (datawave.data.type.DateType)5 HashSet (java.util.HashSet)5 Set (java.util.Set)5 Multimap (com.google.common.collect.Multimap)4