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);
}
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());
}
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());
}
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);
}
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));
}
Aggregations