use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class CoalesceBenchmark method testBaseline.
@Benchmark
public long testBaseline() {
Function function = new CoalesceFunctionFactory.LongCoalesceFunction(constFunctions, constFunctions.size());
long sum = 0;
for (int i = 0; i < N; i++) {
sum += function.getLong(records[i]);
}
return sum;
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class CastFloatToSymbolFunctionFactory 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.getFloat(null), 4);
return SymbolConstant.newInstance(sink);
}
return new Func(arg);
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class CastGeoHashToGeoHashFunctionFactory 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);
int srcType = value.getType();
int targetType = args.getQuick(1).getType();
int srcBitsPrecision = ColumnType.getGeoHashBits(srcType);
int targetBitsPrecision = ColumnType.getGeoHashBits(targetType);
int shift = srcBitsPrecision - targetBitsPrecision;
if (shift > 0) {
if (value.isConstant()) {
long val = GeoHashes.getGeoLong(srcType, value, null);
// >> shift will take care of NULL value -1
return Constants.getGeoHashConstantWithType(val >> shift, targetType);
}
final Function result = castFunc(shift, targetType, value, srcType);
if (result != null) {
return result;
}
} else if (shift == 0) {
return value;
}
// check if this is a null of different bit count
if (value.isConstant() && GeoHashes.getGeoLong(value.getType(), value, null) == GeoHashes.NULL) {
return Constants.getNullConstant(targetType);
}
throw SqlException.position(position).put("CAST cannot decrease precision from GEOHASH(").put(srcBitsPrecision).put("b) to GEOHASH(").put(targetBitsPrecision).put("b)");
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class InSymbolFunctionFactory method newInstance.
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
CharSequenceHashSet set = new CharSequenceHashSet();
int n = args.size();
if (n == 1) {
return BooleanConstant.FALSE;
}
for (int i = 1; i < n; i++) {
Function func = args.getQuick(i);
switch(ColumnType.tagOf(func.getType())) {
case ColumnType.NULL:
case ColumnType.STRING:
case ColumnType.SYMBOL:
CharSequence value = func.getStr(null);
if (value == null) {
set.add(null);
} else {
set.add(Chars.toString(value));
}
break;
case ColumnType.CHAR:
set.add(String.valueOf(func.getChar(null)));
break;
default:
throw SqlException.$(argPositions.getQuick(i), "STRING constant expected");
}
}
SymbolFunction var = (SymbolFunction) args.getQuick(0);
if (var.isConstant()) {
return BooleanConstant.of(set.contains(var.getSymbol(null)));
}
return new Func(var, set);
}
use of io.questdb.cairo.sql.Function 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());
}
Aggregations