@Override public DataType createdOutputType() { return DataType.getArray(DataType.STRING); }
private static DataType makeZCurveDataType(DataType dataType) { return dataType instanceof ArrayDataType ? DataType.getArray(DataType.LONG) : DataType.LONG; }
@Override protected void doVerify(VerificationContext context) { context.setValue(DataType.getArray(context.getValue())); }
private static boolean isPositionArrayField(ImmutableSDField field) { return field.getDataType().equals(DataType.getArray(PositionDataType.INSTANCE)); }
private static boolean isPositionDataType(DataType dataType) { return dataType.equals(PositionDataType.INSTANCE) || dataType.equals(DataType.getArray(PositionDataType.INSTANCE)); }
@Override protected void doExecute(ExecutionContext ctx) { String input = String.valueOf(ctx.getValue()); Array<StringFieldValue> output = new Array<>(DataType.getArray(DataType.STRING)); if (!input.isEmpty()) { String[] splits = splitPattern.split(input); for (String split : splits) { output.add(new StringFieldValue(split)); } } ctx.setValue(output); }
public DataType getDataType() { DataType dataType = toDataType(type); if (collectionType.equals(Attribute.CollectionType.ARRAY)) { return DataType.getArray(dataType); } else if (collectionType.equals(Attribute.CollectionType.WEIGHTEDSET)) { return DataType.getWeightedSet(dataType, createIfNonExistent, removeIfZero); } else { return dataType; } }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override protected void doExecute(ExecutionContext ctx) { FieldValue input = ctx.getValue(); DataType inputType = input.getDataType(); ArrayDataType outputType = DataType.getArray(inputType); Array output = outputType.createFieldValue(); output.add(input); ctx.setValue(output); }
@SuppressWarnings({ "unchecked", "rawtypes" }) private FieldValue convertArray(Array val) { List<FieldValue> next = new LinkedList<FieldValue>(); DataType nextType = null; for (Iterator<FieldValue> it = val.fieldValueIterator(); it.hasNext();) { FieldValue prevVal = it.next(); FieldValue nextVal = convert(prevVal); if (nextVal == null) { continue; } if (nextType == null) { nextType = nextVal.getDataType(); } else if (!nextType.isValueCompatible(nextVal)) { throw new IllegalArgumentException("Expected " + nextType.getName() + ", got " + nextVal.getDataType().getName() + "."); } next.add(nextVal); } if (nextType == null) { return null; } Array ret = DataType.getArray(nextType).createFieldValue(); for (FieldValue nextVal : next) { ret.add(nextVal); } return ret; }
private static boolean isSupportedComplexField(ImmutableSDField field) { return (ComplexAttributeFieldUtils.isSupportedComplexField(field) || field.getDataType().equals(PositionDataType.INSTANCE) || field.getDataType().equals(DataType.getArray(PositionDataType.INSTANCE))); }
private static boolean unsupportedFieldType(ImmutableSDField field) { return (field.usesStructOrMap() && !isSupportedComplexField(field) && !field.getDataType().equals(PositionDataType.INSTANCE) && !field.getDataType().equals(DataType.getArray(PositionDataType.INSTANCE))); }
private void adjustPositionField(DocumentSummary summary, SummaryField summaryField, Source source) { summaryField.setTransform(SummaryTransform.GEOPOS); summaryField.getSources().clear(); summaryField.addSource(source); ensureSummaryField(summary, PositionDataType.getPositionSummaryFieldName(summaryField.getName()), DataType.getArray(DataType.STRING), source, SummaryTransform.POSITIONS); ensureSummaryField(summary, PositionDataType.getDistanceSummaryFieldName(summaryField.getName()), DataType.INT, source, SummaryTransform.DISTANCE); }
private boolean isTypeOrNested(ImmutableSDField field, DataType type) { return field.getDataType().equals(type) || field.getDataType().equals(DataType.getArray(type)) || field.getDataType().equals(DataType.getWeightedSet(type)); }
private void addSdField(Search search, SDDocumentType document, SDField field, boolean validate) { if (field.getIndexToCount() == 0 && field.getAttributes().isEmpty()) { return; } for (Attribute atr : field.getAttributes().values()) { // TODO Vespa 8 or before: Check if this sould be removed or changed to _zcurve. if (atr.getName().equals(field.getName() + "_position")) { DataType type = PositionDataType.INSTANCE; if (atr.getCollectionType().equals(Attribute.CollectionType.ARRAY)) { type = DataType.getArray(type); } addField(search, document, new SDField(document, atr.getName(), type), validate); } else if (!atr.getName().equals(field.getName())) { addField(search, document, new SDField(document, atr.getName(), atr.getDataType()), validate); } } addField(search, document, field, validate); }
@Override protected void derive(ImmutableSDField field, Search search) { if (field.isImportedField()) { return; } if (field.hasFullIndexingDocprocRights()) { docFields.add(field.getName()); } if (field.usesStructOrMap() && !field.getDataType().equals(PositionDataType.INSTANCE) && !field.getDataType().equals(DataType.getArray(PositionDataType.INSTANCE))) { return; // unsupported } ScriptExpression script = field.getIndexingScript(); if (!script.isEmpty()) { expressions.add(new StatementExpression(new ClearStateExpression(), new GuardExpression(script))); } }
private static DataType createCompatType(DataType origType) { if (origType instanceof ArrayDataType) { return DataType.getArray(createCompatType(((ArrayDataType)origType).getNestedType())); } else if (origType instanceof MapDataType) { MapDataType mapType = (MapDataType)origType; return DataType.getMap(createCompatType(mapType.getKeyType()), createCompatType(mapType.getValueType())); } else if (origType instanceof WeightedSetDataType) { return DataType.getWeightedSet(createCompatType(((WeightedSetDataType)origType).getNestedType())); } else if (origType == PositionDataType.INSTANCE) { return DataType.LONG; } else { return origType; } } }
private void resolveImportedField(TemporaryImportedField importedField, boolean validate) { DocumentReference reference = validateDocumentReference(importedField); ImmutableSDField targetField = getTargetField(importedField, reference); if (targetField.getDataType().equals(PositionDataType.INSTANCE) || targetField.getDataType().equals(DataType.getArray(PositionDataType.INSTANCE))) { resolveImportedPositionField(importedField, reference, targetField, validate); } else if (isArrayOfSimpleStruct(targetField)) { resolveImportedArrayOfStructField(importedField, reference, targetField, validate); } else if (isMapOfSimpleStruct(targetField)) { resolveImportedMapOfStructField(importedField, reference, targetField, validate); } else if (isMapOfPrimitiveType(targetField)) { resolveImportedMapOfPrimitiveField(importedField, reference, targetField, validate); } else { resolveImportedNormalField(importedField, reference, targetField, validate); } }
private static void considerComplexField(ImportedFieldsConfig.Builder builder, ImportedComplexField field) { ImmutableSDField targetField = field.targetField(); if (targetField.getDataType().equals(PositionDataType.INSTANCE) || targetField.getDataType().equals(DataType.getArray(PositionDataType.INSTANCE))) { } else if (isArrayOfSimpleStruct(targetField)) { considerNestedFields(builder, field); } else if (isMapOfSimpleStruct(targetField)) { considerSimpleField(builder, field.getNestedField("key")); considerNestedFields(builder, field.getNestedField("value")); } else if (isMapOfPrimitiveType(targetField)) { considerSimpleField(builder, field.getNestedField("key")); considerSimpleField(builder, field.getNestedField("value")); } }
private SDField createZCurveField(SDField inputField, String fieldName, boolean validate) { if (validate && search.getConcreteField(fieldName) != null || search.getAttribute(fieldName) != null) { throw newProcessException(search, null, "Incompatible position attribute '" + fieldName + "' already created."); } boolean isArray = inputField.getDataType() instanceof ArrayDataType; SDField field = new SDField(fieldName, isArray ? DataType.getArray(DataType.LONG) : DataType.LONG); Attribute attribute = new Attribute(fieldName, Attribute.Type.LONG, isArray ? Attribute.CollectionType.ARRAY : Attribute.CollectionType.SINGLE); attribute.setPosition(true); attribute.setFastSearch(true); field.addAttribute(attribute); ScriptExpression script = inputField.getIndexingScript(); script = (ScriptExpression)new RemoveSummary(inputField.getName()).convert(script); script = (ScriptExpression)new PerformZCurve(field, fieldName).convert(script); field.setIndexingScript(script); return field; }
@Override protected void doVerify(VerificationContext context) { DataType input = context.getValue(); if (input instanceof ArrayDataType || input instanceof WeightedSetDataType) { context.setValue(((CollectionDataType)input).getNestedType()).execute(exp); if (input instanceof ArrayDataType) { context.setValue(DataType.getArray(context.getValue())); } else { WeightedSetDataType wset = (WeightedSetDataType)input; context.setValue(DataType.getWeightedSet(context.getValue(), wset.createIfNonExistent(), wset.removeIfZero())); } } else if (input instanceof StructDataType) { for (Field field : ((StructDataType)input).getFields()) { DataType fieldType = field.getDataType(); DataType valueType = context.setValue(fieldType).execute(exp).getValue(); if (!fieldType.isAssignableFrom(valueType)) { throw new VerificationException(this, "Expected " + fieldType.getName() + " output, got " + valueType.getName() + "."); } } context.setValue(input); } else { throw new VerificationException(this, "Expected Array, Struct or WeightedSet input, got " + input.getName() + "."); } }