Search in sources :

Example 91 with Function

use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.

the class CastStrToGeoHashFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
    Function value = args.getQuick(0);
    int argPosition = argPositions.getQuick(0);
    int geoType = args.getQuick(1).getType();
    return newInstance(argPosition, geoType, value);
}
Also used : GeoByteFunction(io.questdb.griffin.engine.functions.GeoByteFunction) UnaryFunction(io.questdb.griffin.engine.functions.UnaryFunction) Function(io.questdb.cairo.sql.Function)

Example 92 with Function

use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.

the class CaseCommon method getCastFunction.

static Function getCastFunction(Function arg, int argPosition, int toType, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
    if (ColumnType.isNull(arg.getType())) {
        return Constants.getNullConstant(toType);
    }
    final int keyIndex = castFactories.keyIndex(Numbers.encodeLowHighInts(arg.getType(), toType));
    if (keyIndex < 0) {
        FunctionFactory fact = castFactories.valueAt(keyIndex);
        ObjList<Function> args = tlArgs.get();
        args.clear();
        args.add(arg);
        IntList argPositions = tlArgPositions.get();
        argPositions.clear();
        argPositions.add(argPosition);
        return fact.newInstance(0, args, argPositions, configuration, sqlExecutionContext);
    }
    return arg;
}
Also used : Function(io.questdb.cairo.sql.Function) FunctionFactory(io.questdb.griffin.FunctionFactory)

Example 93 with Function

use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.

the class TimestampCeilFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
    final Function kind = args.getQuick(0);
    final char c = kind.getChar(null);
    switch(c) {
        case 'd':
            return new TimestampCeilDDFunction(args.getQuick(1));
        case 'M':
            return new TimestampCeilMMFunction(args.getQuick(1));
        case 'y':
            return new TimestampCeilYYYYFunction(args.getQuick(1));
        case 'h':
            return new TimestampCeilHHFunction(args.getQuick(1));
        case 'm':
            return new TimestampCeilMIFunction(args.getQuick(1));
        case 's':
            return new TimestampCeilSSFunction(args.getQuick(1));
        case 'T':
            return new TimestampCeilMSFunction(args.getQuick(1));
        case 0:
            throw SqlException.position(argPositions.getQuick(0)).put("invalid kind 'null'");
        default:
            throw SqlException.position(argPositions.getQuick(0)).put("invalid kind '").put(c).put('\'');
    }
}
Also used : TimestampFunction(io.questdb.griffin.engine.functions.TimestampFunction) Function(io.questdb.cairo.sql.Function) UnaryFunction(io.questdb.griffin.engine.functions.UnaryFunction)

Example 94 with Function

use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.

the class CursorDereferenceFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
    Function cursorFunction = args.getQuick(0);
    Function columnNameFunction = args.getQuick(1);
    RecordMetadata metadata = cursorFunction.getMetadata();
    // name is always constant
    final CharSequence columnName = columnNameFunction.getStr(null);
    final int columnIndex = metadata.getColumnIndexQuiet(columnName);
    if (columnIndex == -1) {
        throw SqlException.invalidColumn(argPositions.getQuick(1), columnName);
    }
    final int columnType = metadata.getColumnType(columnIndex);
    if (ColumnType.isInt(columnType)) {
        return new IntColumnFunction(cursorFunction, columnNameFunction, columnIndex);
    }
    throw SqlException.$(argPositions.getQuick(1), "unsupported column type: ").put(ColumnType.nameOf(columnType));
}
Also used : RecordMetadata(io.questdb.cairo.sql.RecordMetadata) BinaryFunction(io.questdb.griffin.engine.functions.BinaryFunction) Function(io.questdb.cairo.sql.Function) IntFunction(io.questdb.griffin.engine.functions.IntFunction)

Example 95 with Function

use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.

the class ClassResolveFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
    final Function nameFunction = args.getQuick(0);
    final CharSequence type = args.getQuick(1).getStr(null);
    if (SqlKeywords.isRegclassKeyword(type)) {
        final IntConstant func = map.get(nameFunction.getStr(null));
        if (func != null) {
            return func;
        }
        throw SqlException.$(argPositions.getQuick(0), "unsupported class");
    }
    if (SqlKeywords.isRegprocKeyword(type) || SqlKeywords.isRegprocedureKeyword(type)) {
        // return fake OID
        return new IntConstant(289208840);
    }
    if (SqlKeywords.isTimestampKeyword(type)) {
        return new ToTimestampFunctionFactory.ToTimestampFunction(nameFunction);
    }
    if (SqlKeywords.isDateKeyword(type)) {
        return new ToPgDateFunctionFactory.ToPgDateFunction(nameFunction);
    }
    if (SqlKeywords.isTextArrayKeyword(type)) {
        return new StringToStringArrayFunction(argPositions.getQuick(0), nameFunction.getStr(null));
    }
    throw SqlException.$(argPositions.getQuick(1), "unsupported type");
}
Also used : Function(io.questdb.cairo.sql.Function) IntConstant(io.questdb.griffin.engine.functions.constants.IntConstant)

Aggregations

Function (io.questdb.cairo.sql.Function)204 Test (org.junit.Test)101 UnaryFunction (io.questdb.griffin.engine.functions.UnaryFunction)39 IntList (io.questdb.std.IntList)33 Record (io.questdb.cairo.sql.Record)28 ToStrTimestampFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory)28 ToStrDateFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory)27 NotFunctionFactory (io.questdb.griffin.engine.functions.bool.NotFunctionFactory)26 InStrFunctionFactory (io.questdb.griffin.engine.functions.bool.InStrFunctionFactory)25 EqDoubleFunctionFactory (io.questdb.griffin.engine.functions.eq.EqDoubleFunctionFactory)25 EqIntFunctionFactory (io.questdb.griffin.engine.functions.eq.EqIntFunctionFactory)25 EqLongFunctionFactory (io.questdb.griffin.engine.functions.eq.EqLongFunctionFactory)25 OrFunctionFactory (io.questdb.griffin.engine.functions.bool.OrFunctionFactory)24 CastStrToGeoHashFunctionFactory (io.questdb.griffin.engine.functions.cast.CastStrToGeoHashFunctionFactory)23 CursorDereferenceFunctionFactory (io.questdb.griffin.engine.functions.catalogue.CursorDereferenceFunctionFactory)23 SysdateFunctionFactory (io.questdb.griffin.engine.functions.date.SysdateFunctionFactory)23 LengthStrFunctionFactory (io.questdb.griffin.engine.functions.str.LengthStrFunctionFactory)23 LengthSymbolFunctionFactory (io.questdb.griffin.engine.functions.str.LengthSymbolFunctionFactory)23 ToCharBinFunctionFactory (io.questdb.griffin.engine.functions.str.ToCharBinFunctionFactory)23 SwitchFunctionFactory (io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory)22