use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class EqDoubleFunctionFactory method newInstance.
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) {
// this is probably a special case factory
// NaN is always a double, so this could lead comparisons of all primitive types
// to NaN route to this factory. Obviously comparing naively will not work
// We have to check arg types and when NaN is present we would generate special case
// functions for NaN checks.
Function left = args.getQuick(0);
Function right = args.getQuick(1);
if (left.isConstant() && ColumnType.isDouble(left.getType()) && Double.isNaN(left.getDouble(null))) {
switch(ColumnType.tagOf(right.getType())) {
case ColumnType.INT:
return new FuncIntIsNaN(right);
case ColumnType.LONG:
return new FuncLongIsNaN(right);
case ColumnType.DATE:
return new FuncDateIsNaN(right);
case ColumnType.TIMESTAMP:
return new FuncTimestampIsNaN(right);
case ColumnType.FLOAT:
return new FuncFloatIsNaN(right);
default:
// double
return new FuncDoubleIsNaN(right);
}
} else if (right.isConstant() && ColumnType.isDouble(right.getType()) && Double.isNaN(right.getDouble(null))) {
switch(ColumnType.tagOf(left.getType())) {
case ColumnType.INT:
return new FuncIntIsNaN(left);
case ColumnType.LONG:
return new FuncLongIsNaN(left);
case ColumnType.DATE:
return new FuncDateIsNaN(left);
case ColumnType.TIMESTAMP:
return new FuncTimestampIsNaN(left);
case ColumnType.FLOAT:
return new FuncFloatIsNaN(left);
default:
// double
return new FuncDoubleIsNaN(left);
}
}
return new Func(args.getQuick(0), args.getQuick(1));
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class EqSymCharFunctionFactory method newInstance.
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) {
// there are optimisation opportunities
// 1. when one of args is constant null comparison can boil down to checking
// length of non-constant (must be -1)
// 2. when one of arguments is constant, save method call and use a field
SymbolFunction symFunc = (SymbolFunction) args.getQuick(0);
Function chrFunc = args.getQuick(1);
if (chrFunc.isConstant()) {
final char constValue = chrFunc.getChar(null);
if (symFunc.getStaticSymbolTable() != null) {
return new ConstCheckColumnFunc(symFunc, constValue);
} else {
return new ConstCheckFunc(symFunc, constValue);
}
}
return new Func(symFunc, chrFunc);
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class NotMatchStrFunctionFactory method newInstance.
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
Function value = args.getQuick(0);
CharSequence regex = args.getQuick(1).getStr(null);
if (regex == null) {
throw SqlException.$(argPositions.getQuick(1), "NULL regex");
}
try {
Matcher matcher = Pattern.compile(Chars.toString(regex)).matcher("");
return new MatchFunction(value, matcher);
} catch (PatternSyntaxException e) {
throw SqlException.$(argPositions.getQuick(1) + e.getIndex() + 1, e.getMessage());
}
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class LongSequenceFunctionFactory method newInstance.
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
Function countFunc;
final Function seedLoFunc;
final Function seedHiFunc;
if (args != null) {
final int argCount = args.size();
if (argCount == 1 && SqlCompiler.isAssignableFrom(ColumnType.LONG, (countFunc = args.getQuick(0)).getType())) {
return new CursorFunction(new LongSequenceCursorFactory(METADATA, countFunc.getLong(null)));
}
if (argCount > 2 && SqlCompiler.isAssignableFrom(ColumnType.LONG, (countFunc = args.getQuick(0)).getType()) && SqlCompiler.isAssignableFrom(ColumnType.LONG, (seedLoFunc = args.getQuick(1)).getType()) && SqlCompiler.isAssignableFrom(ColumnType.LONG, (seedHiFunc = args.getQuick(2)).getType())) {
return new CursorFunction(new SeedingLongSequenceCursorFactory(METADATA, countFunc.getLong(null), seedLoFunc.getLong(null), seedHiFunc.getLong(null)));
}
}
throw SqlException.position(position).put("invalid arguments");
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class AbstractLikeStrFunctionFactory method newInstance.
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
final Function value = args.getQuick(0);
final Function pattern = args.getQuick(1);
if (pattern.isConstant()) {
final CharSequence likeString = pattern.getStr(null);
if (likeString != null && likeString.length() > 0) {
String p = escapeSpecialChars(likeString, null);
assert p != null;
return new ConstLikeStrFunction(value, Pattern.compile(p, Pattern.DOTALL).matcher(""));
}
return BooleanConstant.FALSE;
}
if (pattern instanceof IndexedParameterLinkFunction) {
// bind variable
return new BindLikeStrFunction(value, pattern);
}
throw SqlException.$(argPositions.getQuick(1), "use constant or bind variable");
}
Aggregations