use of io.crate.types.DataType in project crate by crate.
the class PercentileAggregation method register.
public static void register(AggregationImplModule mod) {
for (DataType<?> t : DataTypes.NUMERIC_PRIMITIVE_TYPES) {
mod.register(new PercentileAggregation(new FunctionInfo(new FunctionIdent(NAME, ImmutableList.<DataType>of(t, DataTypes.DOUBLE)), DataTypes.DOUBLE, FunctionInfo.Type.AGGREGATE)));
mod.register(new PercentileAggregation(new FunctionInfo(new FunctionIdent(NAME, ImmutableList.of(t, DataTypes.DOUBLE_ARRAY)), DataTypes.DOUBLE_ARRAY, FunctionInfo.Type.AGGREGATE)));
}
}
use of io.crate.types.DataType in project crate by crate.
the class IfFunction method createInfo.
private static FunctionInfo createInfo(List<DataType> dataTypes) {
DataType valueType = dataTypes.get(1);
DataType returnType = valueType;
if (dataTypes.size() == 3) {
returnType = dataTypes.get(2);
if (returnType.id() != valueType.id()) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "%s type of default result argument %s does not match type of results argument %s", NAME, returnType, valueType));
}
}
return new FunctionInfo(new FunctionIdent(NAME, dataTypes), returnType, FunctionInfo.Type.SCALAR);
}
use of io.crate.types.DataType in project crate by crate.
the class DistanceFunction method normalizeSymbol.
@Override
public Symbol normalizeSymbol(Function symbol, TransactionContext transactionContext) {
Symbol arg1 = symbol.arguments().get(0);
Symbol arg2 = symbol.arguments().get(1);
DataType arg1Type = arg1.valueType();
DataType arg2Type = arg2.valueType();
boolean arg1IsReference = true;
boolean literalConverted = false;
short numLiterals = 0;
if (arg1.symbolType().isValueSymbol()) {
numLiterals++;
arg1IsReference = false;
if (!arg1Type.equals(DataTypes.GEO_POINT)) {
literalConverted = true;
arg1 = Literal.convert(arg1, DataTypes.GEO_POINT);
}
} else {
validateType(arg1, arg1Type);
}
if (arg2.symbolType().isValueSymbol()) {
numLiterals++;
if (!arg2Type.equals(DataTypes.GEO_POINT)) {
literalConverted = true;
arg2 = Literal.convert(arg2, DataTypes.GEO_POINT);
}
} else {
validateType(arg2, arg2Type);
}
if (numLiterals == 2) {
return Literal.of(evaluate((Input) arg1, (Input) arg2));
}
// ensure reference is the first argument.
if (!arg1IsReference) {
return new Function(geoPointInfo, Arrays.asList(arg2, arg1));
}
if (literalConverted) {
return new Function(geoPointInfo, Arrays.asList(arg1, arg2));
}
return symbol;
}
use of io.crate.types.DataType in project crate by crate.
the class ArrayCatFunction method evaluate.
@Override
public Object[] evaluate(Input[] args) {
DataType innerType = ((ArrayType) this.info().returnType()).innerType();
List<Object> resultList = new ArrayList<>();
for (Input array : args) {
Object arrayValue = array.value();
if (arrayValue == null) {
continue;
}
Object[] arg = (Object[]) arrayValue;
for (Object element : arg) {
resultList.add(innerType.value(element));
}
}
return resultList.toArray();
}
use of io.crate.types.DataType in project crate by crate.
the class ArrayDifferenceFunction method evaluate.
@Override
public Object[] evaluate(Input[] args) {
Object[] originalArray = (Object[]) args[0].value();
if (originalArray == null) {
return null;
}
DataType innerType = ((ArrayType) this.info().returnType()).innerType();
Set<Object> localSubtractSet;
if (!optionalSubtractSet.isPresent()) {
localSubtractSet = new HashSet<>();
for (int i = 1; i < args.length; i++) {
Object argValue = args[i].value();
if (argValue == null) {
continue;
}
Object[] array = (Object[]) argValue;
for (Object element : array) {
localSubtractSet.add(innerType.value(element));
}
}
} else {
localSubtractSet = optionalSubtractSet.get();
}
List<Object> resultList = new ArrayList<>(originalArray.length);
for (Object anOriginalArray : originalArray) {
Object element = innerType.value(anOriginalArray);
if (!localSubtractSet.contains(element)) {
resultList.add(element);
}
}
return resultList.toArray();
}
Aggregations