use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class BindVariablesTest method testLong256Compare.
@Test
public void testLong256Compare() throws SqlException {
bindVariableService.setLong256("x", 1, 2, 3, 4);
bindVariableService.setLong256("y", 1, 2, 3, 4);
Function func = expr(":x = :y").withFunction(new EqLong256FunctionFactory()).$();
func.init(null, sqlExecutionContext);
Assert.assertTrue(func.getBool(builder.getRecord()));
bindVariableService.setLong256("y", 2, 4, 5, 6);
Assert.assertFalse(func.getBool(builder.getRecord()));
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class BindVariablesTest method testInt.
@Test
public void testInt() throws SqlException {
bindVariableService.setInt("xyz", 10);
bindVariableService.setInt("zz", 5);
Function func = expr("a + :xyz + :xyz - :zz").withFunction(new AddIntFunctionFactory()).withFunction(new SubIntFunctionFactory()).withColumn("a", ColumnType.INT, 22).$();
func.init(null, sqlExecutionContext);
Assert.assertEquals(37, func.getInt(builder.getRecord()));
bindVariableService.setInt("zz", 8);
Assert.assertEquals(34, func.getInt(builder.getRecord()));
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class CastGeoHashFunctionFactoryTest method testCastStringToGeoHashSizesChar.
@Test
public void testCastStringToGeoHashSizesChar() throws SqlException {
String longHash = "sp052w92bcde";
for (int i = 0; i < longHash.length(); i++) {
String expectedGeoHash = longHash.substring(0, i + 1);
for (int j = 0; j <= i; j++) {
int parsedGeoHashLen = j + 1;
String castExpr = String.format("cast('%s' as geohash(%sc))", expectedGeoHash, parsedGeoHashLen);
Function function = parseFunction(castExpr, metadata, functionParser);
Assert.assertTrue(castExpr, function.isConstant());
Assert.assertEquals(castExpr, parsedGeoHashLen * 5, ColumnType.getGeoHashBits(function.getType()));
}
}
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class BindVariableServiceImpl method setChar.
@Override
public void setChar(int index, char value) throws SqlException {
indexedVariables.extendPos(index + 1);
// variable exists
Function function = indexedVariables.getQuick(index);
if (function != null) {
setChar0(function, value, index, null);
} else {
indexedVariables.setQuick(index, function = charVarPool.next());
((CharBindVariable) function).value = value;
}
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class BindVariableServiceImpl method setLong.
@Override
public void setLong(int index, long value) throws SqlException {
indexedVariables.extendPos(index + 1);
// variable exists
Function function = indexedVariables.getQuick(index);
if (function != null) {
setLong0(function, value, index, null, ColumnType.LONG);
} else {
indexedVariables.setQuick(index, function = longVarPool.next());
((LongBindVariable) function).value = value;
}
}
Aggregations