use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class FunctionParserTest method testImplicitConstantNullSymbol.
@Test
public void testImplicitConstantNullSymbol() throws SqlException {
functions.add(new FunctionFactory() {
@Override
public String getSignature() {
return "x()";
}
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration1, SqlExecutionContext sqlExecutionContext) {
return new SymbolConstant(null, SymbolTable.VALUE_IS_NULL);
}
});
Function function = parseFunction("x()", new GenericRecordMetadata(), createFunctionParser());
Assert.assertTrue(function instanceof SymbolConstant);
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class FunctionParserTest method testByteToShortCast.
@Test
public void testByteToShortCast() throws SqlException {
functions.add(new AddShortFunctionFactory());
final GenericRecordMetadata metadata = new GenericRecordMetadata();
metadata.add(new TableColumnMetadata("a", 1, ColumnType.BYTE));
metadata.add(new TableColumnMetadata("b", 2, ColumnType.BYTE));
FunctionParser functionParser = createFunctionParser();
Function function = parseFunction("a+b", metadata, functionParser);
Assert.assertEquals(ColumnType.SHORT, function.getType());
Assert.assertEquals(131, function.getShort(new Record() {
@Override
public byte getByte(int col) {
if (col == 0) {
return 41;
}
return 90;
}
}));
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class EqDoubleFunctionFactoryTest method testRightNaNDate.
@Test
public void testRightNaNDate() throws SqlException {
FunctionFactory factory = getFunctionFactory();
ObjList<Function> args = new ObjList<>();
args.add(new DateConstant(10000L));
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));
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class EqDoubleFunctionFactoryTest method testLeftNaNFloatNaN.
@Test
public void testLeftNaNFloatNaN() throws SqlException {
FunctionFactory factory = getFunctionFactory();
ObjList<Function> args = new ObjList<>();
args.add(new FloatConstant(Float.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.cairo.sql.Function in project questdb by bluestreak01.
the class EqGeoHashGeoHashFunctionFactoryTest method createEqFunctionAndAssert.
private void createEqFunctionAndAssert(boolean isConstant, boolean expectedEq) {
try {
Function func = factory.newInstance(-1, args, null, null, null);
Assert.assertEquals(expectedEq, func.getBool(null));
Assert.assertEquals(isConstant, func.isConstant());
if (func instanceof NegatableBooleanFunction) {
try {
NegatingFunctionFactory nf = new NegatingFunctionFactory("noteq", factory);
func = nf.newInstance(-1, args, null, null, null);
Assert.assertEquals(!expectedEq, func.getBool(null));
} catch (SqlException e) {
e.printStackTrace();
Assert.fail();
}
}
} catch (SqlException e) {
Assert.fail(e.getMessage());
}
}
Aggregations