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;
}
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();
}
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());
}
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);
}
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;
}
Aggregations