Search in sources :

Example 61 with StringSink

use of io.questdb.std.str.StringSink in project questdb by questdb.

the class SqlOptimiser method doReplaceLiteral0.

private ExpressionNode doReplaceLiteral0(ExpressionNode node, QueryModel translatingModel, @Nullable QueryModel innerModel, QueryModel validatingModel) throws SqlException {
    final LowerCaseCharSequenceObjHashMap<CharSequence> map = translatingModel.getColumnNameToAliasMap();
    int index = map.keyIndex(node.token);
    if (index > -1) {
        // there is a possibility that column references join table, but in a different way
        // for example. main column could be tab1.y and the "missing" one just "y"
        // which is the same thing.
        // To disambiguate this situation we need to go over all join tables and see if the
        // column matches any of join tables unambiguously.
        final int joinCount = validatingModel.getJoinModels().size();
        if (joinCount > 1) {
            boolean found = false;
            final StringSink sink = Misc.getThreadLocalBuilder();
            sink.clear();
            for (int i = 0; i < joinCount; i++) {
                final QueryModel jm = validatingModel.getJoinModels().getQuick(i);
                if (jm.getAliasToColumnMap().keyIndex(node.token) < 0) {
                    if (found) {
                        throw SqlException.ambiguousColumn(node.position);
                    }
                    if (jm.getAlias() != null) {
                        sink.put(jm.getAlias().token);
                    } else {
                        sink.put(jm.getTableName().token);
                    }
                    sink.put('.');
                    sink.put(node.token);
                    if ((index = map.keyIndex(sink)) < 0) {
                        found = true;
                    }
                }
            }
            if (found) {
                return nextLiteral(map.valueAtQuick(index), node.position);
            }
        }
        // this is the first time we see this column and must create alias
        CharSequence alias = createColumnAlias(node, translatingModel);
        QueryColumn column = queryColumnPool.next().of(alias, node);
        // add column to both models
        addColumnToTranslatingModel(column, translatingModel, validatingModel);
        if (innerModel != null) {
            innerModel.addBottomUpColumn(column);
        }
        return nextLiteral(alias, node.position);
    }
    return nextLiteral(map.valueAtQuick(index), node.position);
}
Also used : FlyweightCharSequence(io.questdb.std.str.FlyweightCharSequence) StringSink(io.questdb.std.str.StringSink)

Example 62 with StringSink

use of io.questdb.std.str.StringSink in project questdb by questdb.

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 63 with StringSink

use of io.questdb.std.str.StringSink in project questdb by questdb.

the class CastDoubleToSymbolFunctionFactory method newInstance.

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

Example 64 with StringSink

use of io.questdb.std.str.StringSink in project questdb by questdb.

the class CastTimestampToSymbolFunctionFactory method newInstance.

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

Example 65 with StringSink

use of io.questdb.std.str.StringSink in project questdb by questdb.

the class CastShortToStrFunctionFactory 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.getShort(null));
        return new StrConstant(Chars.toString(sink));
    }
    return new Func(args.getQuick(0));
}
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)

Aggregations

StringSink (io.questdb.std.str.StringSink)304 Test (org.junit.Test)173 Function (io.questdb.cairo.sql.Function)38 BaseConnection (org.postgresql.core.BaseConnection)38 UnaryFunction (io.questdb.griffin.engine.functions.UnaryFunction)28 StrConstant (io.questdb.griffin.engine.functions.constants.StrConstant)22 StrFunction (io.questdb.griffin.engine.functions.StrFunction)20 Path (io.questdb.std.str.Path)18 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 CyclicBarrier (java.util.concurrent.CyclicBarrier)15 Record (io.questdb.cairo.sql.Record)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 SqlCompiler (io.questdb.griffin.SqlCompiler)12 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 SqlException (io.questdb.griffin.SqlException)9 Metrics (io.questdb.Metrics)8 io.questdb.cairo (io.questdb.cairo)8 AllowAllCairoSecurityContext (io.questdb.cairo.security.AllowAllCairoSecurityContext)8