Search in sources :

Example 26 with DataType

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)));
    }
}
Also used : FunctionIdent(io.crate.metadata.FunctionIdent) FunctionInfo(io.crate.metadata.FunctionInfo) DataType(io.crate.types.DataType)

Example 27 with DataType

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);
}
Also used : DataType(io.crate.types.DataType)

Example 28 with DataType

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;
}
Also used : Function(io.crate.analyze.symbol.Function) Input(io.crate.data.Input) Symbol(io.crate.analyze.symbol.Symbol) DataType(io.crate.types.DataType)

Example 29 with DataType

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();
}
Also used : ArrayType(io.crate.types.ArrayType) Input(io.crate.data.Input) ArrayList(java.util.ArrayList) DataType(io.crate.types.DataType)

Example 30 with DataType

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();
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType)

Aggregations

DataType (io.crate.types.DataType)64 ArrayType (io.crate.types.ArrayType)30 Test (org.junit.Test)30 CrateUnitTest (io.crate.test.integration.CrateUnitTest)28 FunctionIdent (io.crate.metadata.FunctionIdent)8 FunctionInfo (io.crate.metadata.FunctionInfo)7 WhereClause (io.crate.analyze.WhereClause)6 Symbol (io.crate.analyze.symbol.Symbol)4 Function (io.crate.analyze.symbol.Function)3 Input (io.crate.data.Input)3 Map (java.util.Map)3 ColumnUnknownException (io.crate.exceptions.ColumnUnknownException)2 ColumnIdent (io.crate.metadata.ColumnIdent)2 Reference (io.crate.metadata.Reference)2 DocTableInfo (io.crate.metadata.doc.DocTableInfo)2 TableInfo (io.crate.metadata.table.TableInfo)2 SubscriptFunction (io.crate.operation.scalar.SubscriptFunction)2 AddFunction (io.crate.operation.scalar.arithmetic.AddFunction)2 DistanceFunction (io.crate.operation.scalar.geo.DistanceFunction)2 MatchesFunction (io.crate.operation.scalar.regex.MatchesFunction)2