use of io.questdb.std.IntList in project questdb by bluestreak01.
the class EqDoubleFunctionFactoryTest method testLeftNaNFloat.
@Test
public void testLeftNaNFloat() throws SqlException {
FunctionFactory factory = getFunctionFactory();
ObjList<Function> args = new ObjList<>();
args.add(new FloatConstant(3.4f));
args.add(new DoubleConstant(Double.NaN));
IntList argPositions = new IntList();
argPositions.add(1);
argPositions.add(2);
Function function = factory.newInstance(4, args, argPositions, configuration, sqlExecutionContext);
Assert.assertFalse(function.getBool(null));
Assert.assertTrue(function.isConstant());
}
use of io.questdb.std.IntList in project questdb by bluestreak01.
the class EqDoubleFunctionFactoryTest method testRightNaNDateNaN.
@Test
public void testRightNaNDateNaN() throws SqlException {
FunctionFactory factory = getFunctionFactory();
ObjList<Function> args = new ObjList<>();
args.add(new DateConstant(Numbers.LONG_NaN));
args.add(new DoubleConstant(Double.NaN));
IntList argPositions = new IntList();
argPositions.add(1);
argPositions.add(2);
Function function = factory.newInstance(4, args, argPositions, configuration, sqlExecutionContext);
Assert.assertTrue(function.getBool(null));
Assert.assertTrue(function.isConstant());
}
use of io.questdb.std.IntList in project questdb by bluestreak01.
the class EqDoubleFunctionFactoryTest method testLeftNaNDate.
@Test
public void testLeftNaNDate() throws SqlException {
FunctionFactory factory = getFunctionFactory();
ObjList<Function> args = new ObjList<>();
args.add(new DoubleConstant(Double.NaN));
args.add(new DateConstant(10000L));
IntList argPositions = new IntList();
argPositions.add(2);
argPositions.add(1);
Function function = factory.newInstance(4, args, argPositions, configuration, sqlExecutionContext);
Assert.assertFalse(function.getBool(null));
}
use of io.questdb.std.IntList in project questdb by bluestreak01.
the class EqDoubleFunctionFactoryTest method testRightNaNTimestampNaN.
@Test
public void testRightNaNTimestampNaN() throws SqlException {
FunctionFactory factory = getFunctionFactory();
ObjList<Function> args = new ObjList<>();
args.add(new TimestampConstant(Numbers.LONG_NaN) {
@Override
public boolean isConstant() {
return false;
}
});
args.add(new DoubleConstant(Double.NaN));
IntList argPositions = new IntList();
argPositions.add(1);
argPositions.add(2);
Function function = factory.newInstance(4, args, argPositions, configuration, sqlExecutionContext);
Assert.assertTrue(function.getBool(null));
Assert.assertFalse(function.isConstant());
}
use of io.questdb.std.IntList in project questdb by bluestreak01.
the class CaseFunctionFactory method newInstance.
@Override
public Function newInstance(int position, @Transient ObjList<Function> args, @Transient IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
int n = args.size();
int returnType = -1;
final ObjList<Function> vars = new ObjList<>(n);
final ObjList<Function> argsToPoke = new ObjList<>(n);
Function elseBranch;
int elseBranchPosition;
if (n % 2 == 1) {
elseBranch = args.getQuick(n - 1);
elseBranchPosition = argPositions.getQuick(n - 1);
n--;
} else {
elseBranch = null;
elseBranchPosition = 0;
}
// compute return type in this loop
for (int i = 0; i < n; i += 2) {
Function bool = args.getQuick(i);
Function value = args.getQuick(i + 1);
if (!ColumnType.isBoolean(bool.getType())) {
throw SqlException.position(argPositions.getQuick(i)).put("BOOLEAN expected, found ").put(ColumnType.nameOf(bool.getType()));
}
returnType = CaseCommon.getCommonType(returnType, value.getType(), argPositions.getQuick(i + 1));
vars.add(bool);
vars.add(value);
argsToPoke.add(bool);
argsToPoke.add(value);
}
if (elseBranch != null) {
returnType = CaseCommon.getCommonType(returnType, elseBranch.getType(), elseBranchPosition);
argsToPoke.add(elseBranch);
}
// next calculate cast functions
for (int i = 1; i < n; i += 2) {
vars.setQuick(i, CaseCommon.getCastFunction(vars.getQuick(i), argPositions.getQuick(i), returnType, configuration, sqlExecutionContext));
}
if (elseBranch != null) {
elseBranch = CaseCommon.getCastFunction(elseBranch, elseBranchPosition, returnType, configuration, sqlExecutionContext);
}
final int argsLen = vars.size();
final Function elseB = elseBranch != null ? elseBranch : Constants.getNullConstant(returnType);
final CaseFunctionPicker picker = record -> {
for (int i = 0; i < argsLen; i += 2) {
if (vars.getQuick(i).getBool(record)) {
return vars.getQuick(i + 1);
}
}
return elseB;
};
return CaseCommon.getCaseFunction(position, returnType, picker, argsToPoke);
}
Aggregations