/** * Returns a weighted set datatype, where the elements are of the given type * * @param type the type to create a weighted set of * @return the weighted set data type */ public static WeightedSetDataType getWeightedSet(DataType type) { return getWeightedSet(type, false, false); }
@Override protected void doVerify(VerificationContext context) { context.setValue(DataType.getWeightedSet(context.getValue(), createIfNonExistent, removeIfZero)); }
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(); WeightedSetDataType outputType = DataType.getWeightedSet(inputType, createIfNonExistent, removeIfZero); WeightedSet output = outputType.createFieldValue(); output.add(input); ctx.setValue(output); }
@SuppressWarnings({ "unchecked", "rawtypes" }) private FieldValue convertWset(WeightedSet val) { Map<FieldValue, Integer> next = new LinkedHashMap<FieldValue, Integer>(); DataType nextType = null; for (Iterator<FieldValue> it = val.fieldValueIterator(); it.hasNext();) { FieldValue prevKey = it.next(); Integer prevVal = val.get(prevKey); FieldValue nextKey = convert(prevKey); if (nextKey == null) { continue; } if (nextType == null) { nextType = nextKey.getDataType(); } else if (!nextType.isValueCompatible(nextKey)) { throw new IllegalArgumentException("Expected " + nextType.getName() + ", got " + nextKey.getDataType().getName() + "."); } next.put(nextKey, prevVal); } if (nextType == null) { return null; } WeightedSet ret = DataType.getWeightedSet(nextType, val.getDataType().createIfNonExistent(), val.getDataType().removeIfZero()).createFieldValue(); for (Map.Entry<FieldValue, Integer> entry : next.entrySet()) { ret.put(entry.getKey(), entry.getValue()); } return ret; }
public void apply(SDField field) { WeightedSetDataType ctype = (WeightedSetDataType) field.getDataType(); if (createIfNonExistent != null) { field.setDataType(DataType.getWeightedSet(ctype.getNestedType(), createIfNonExistent, ctype.removeIfZero())); } ctype = (WeightedSetDataType) field.getDataType(); if (removeIfZero != null) { field.setDataType(DataType.getWeightedSet(ctype.getNestedType(), ctype.createIfNonExistent(), removeIfZero)); } ctype = (WeightedSetDataType) field.getDataType(); for (Object o : field.getAttributes().values()) { Attribute attribute = (Attribute) o; attribute.setRemoveIfZero(ctype.removeIfZero()); attribute.setCreateIfNonExistent(ctype.createIfNonExistent()); } }
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 implementTagType(SDField field) { field.setDataType(DataType.getWeightedSet(DataType.STRING, true, true)); // Don't set matching and ranking if this field is not attribute nor index if (!field.doesIndexing() && !field.doesAttributing()) return; Matching m = field.getMatching(); if ( ! m.isTypeUserSet()) m.setType(Matching.Type.WORD); if (field.getRankType() == null || field.getRankType() == RankType.DEFAULT) field.setRankType((RankType.TAGS)); }
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; } } }
@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() + "."); } }
wsetType = dataType(); jj_consume_token(GREATERTHAN); {if ("" != null) return DataType.getWeightedSet(wsetType);} } else if (jj_2_3(2147483647)) { mapType = mapDataType();