Search in sources :

Example 1 with StrConstant

use of io.questdb.griffin.engine.functions.constants.StrConstant in project questdb by bluestreak01.

the class CastDoubleToStrFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) {
    Function intFunc = args.getQuick(0);
    if (intFunc.isConstant()) {
        final StringSink sink = Misc.getThreadLocalBuilder();
        sink.put(intFunc.getDouble(null), configuration.getDoubleToStrCastScale());
        return new StrConstant(Chars.toString(sink));
    }
    return new Func(args.getQuick(0), configuration.getDoubleToStrCastScale());
}
Also used : UnaryFunction(io.questdb.griffin.engine.functions.UnaryFunction) Function(io.questdb.cairo.sql.Function) StrFunction(io.questdb.griffin.engine.functions.StrFunction) StringSink(io.questdb.std.str.StringSink) StrConstant(io.questdb.griffin.engine.functions.constants.StrConstant)

Example 2 with StrConstant

use of io.questdb.griffin.engine.functions.constants.StrConstant in project questdb by bluestreak01.

the class CastCharToStrFunctionFactory method newInstance.

public Function newInstance(Function func) {
    if (func.isConstant()) {
        final char value = func.getChar(null);
        if (value == 0) {
            return new StrConstant(null);
        }
        final StringSink sink = Misc.getThreadLocalBuilder();
        sink.put(value);
        return new StrConstant(Chars.toString(sink));
    }
    return new Func(func);
}
Also used : StringSink(io.questdb.std.str.StringSink) StrConstant(io.questdb.griffin.engine.functions.constants.StrConstant)

Example 3 with StrConstant

use of io.questdb.griffin.engine.functions.constants.StrConstant in project questdb by bluestreak01.

the class BuildFunctionFactory method createInstance.

private StrFunction createInstance(final CairoConfiguration configuration) {
    final BuildInformation buildInformation = configuration.getBuildInformation();
    final CharSequence information = "Build Information: QuestDB " + buildInformation.getQuestDbVersion() + ", JDK " + buildInformation.getJdkVersion() + ", Commit Hash " + buildInformation.getCommitHash();
    return new StrConstant(information);
}
Also used : BuildInformation(io.questdb.BuildInformation) StrConstant(io.questdb.griffin.engine.functions.constants.StrConstant)

Example 4 with StrConstant

use of io.questdb.griffin.engine.functions.constants.StrConstant in project questdb by bluestreak01.

the class ToStrDateFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
    Function fmt = args.getQuick(1);
    CharSequence format = fmt.getStr(null);
    if (format == null) {
        throw SqlException.$(argPositions.getQuick(1), "format must not be null");
    }
    DateFormat dateFormat = tlCompiler.get().compile(fmt.getStr(null));
    Function var = args.getQuick(0);
    if (var.isConstant()) {
        long value = var.getDate(null);
        if (value == Numbers.LONG_NaN) {
            return StrConstant.NULL;
        }
        StringSink sink = tlSink.get();
        sink.clear();
        dateFormat.format(value, configuration.getDefaultDateLocale(), "Z", sink);
        return new StrConstant(sink);
    }
    return new ToCharDateVCFFunc(args.getQuick(0), tlCompiler.get().compile(format), configuration.getDefaultDateLocale());
}
Also used : UnaryFunction(io.questdb.griffin.engine.functions.UnaryFunction) Function(io.questdb.cairo.sql.Function) StrFunction(io.questdb.griffin.engine.functions.StrFunction) DateFormat(io.questdb.std.datetime.DateFormat) StringSink(io.questdb.std.str.StringSink) StrConstant(io.questdb.griffin.engine.functions.constants.StrConstant)

Example 5 with StrConstant

use of io.questdb.griffin.engine.functions.constants.StrConstant in project questdb by bluestreak01.

the class ToStrTimestampFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
    Function fmt = args.getQuick(1);
    CharSequence format = fmt.getStr(null);
    if (format == null) {
        throw SqlException.$(argPositions.getQuick(1), "format must not be null");
    }
    DateFormat timestampFormat = tlCompiler.get().compile(fmt.getStr(null));
    Function var = args.getQuick(0);
    if (var.isConstant()) {
        long value = var.getTimestamp(null);
        if (value == Numbers.LONG_NaN) {
            return StrConstant.NULL;
        }
        StringSink sink = tlSink.get();
        sink.clear();
        timestampFormat.format(value, configuration.getDefaultDateLocale(), "Z", sink);
        return new StrConstant(sink);
    }
    return new ToCharDateFFunc(args.getQuick(0), timestampFormat, configuration.getDefaultDateLocale());
}
Also used : UnaryFunction(io.questdb.griffin.engine.functions.UnaryFunction) Function(io.questdb.cairo.sql.Function) StrFunction(io.questdb.griffin.engine.functions.StrFunction) DateFormat(io.questdb.std.datetime.DateFormat) StringSink(io.questdb.std.str.StringSink) StrConstant(io.questdb.griffin.engine.functions.constants.StrConstant)

Aggregations

StrConstant (io.questdb.griffin.engine.functions.constants.StrConstant)12 StringSink (io.questdb.std.str.StringSink)11 Function (io.questdb.cairo.sql.Function)10 StrFunction (io.questdb.griffin.engine.functions.StrFunction)10 UnaryFunction (io.questdb.griffin.engine.functions.UnaryFunction)10 DateFormat (io.questdb.std.datetime.DateFormat)2 BuildInformation (io.questdb.BuildInformation)1