Search in sources :

Example 16 with Function

use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.

the class BindVariablesTest method testFloatIndexed.

@Test
public void testFloatIndexed() throws SqlException {
    bindVariableService.setFloat(2, Float.NaN);
    bindVariableService.setFloat(0, 7.6f);
    bindVariableService.setFloat(1, 9.21f);
    Function func = expr("$1 + $2").withFunction(new AddFloatFunctionFactory()).$();
    func.init(null, sqlExecutionContext);
    Assert.assertEquals(16.81f, func.getFloat(builder.getRecord()), 0.001f);
    bindVariableService.setFloat(1, 0.13f);
    func.init(null, sqlExecutionContext);
    Assert.assertEquals(7.73f, func.getFloat(builder.getRecord()), 0.001f);
    func.close();
}
Also used : Function(io.questdb.cairo.sql.Function) Test(org.junit.Test)

Example 17 with Function

use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.

the class BindVariablesTest method testFloatExplicitlyIndexedTwoVars.

@Test
public void testFloatExplicitlyIndexedTwoVars() throws SqlException {
    bindVariableService.setFloat(2, Float.NaN);
    bindVariableService.setFloat(0, 7.6f);
    bindVariableService.setFloat(1, 9.21f);
    Function func = expr("$1 + $2").withFunction(new AddFloatFunctionFactory()).$();
    func.init(null, sqlExecutionContext);
    Assert.assertEquals(16.81, func.getFloat(builder.getRecord()), 0.001f);
    bindVariableService.setFloat(0, 0.13f);
    func.init(null, sqlExecutionContext);
    Assert.assertEquals(9.34f, func.getFloat(builder.getRecord()), 0.001f);
    func.close();
}
Also used : Function(io.questdb.cairo.sql.Function) Test(org.junit.Test)

Example 18 with Function

use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.

the class BindVariablesTest method testByte.

@Test
public void testByte() throws SqlException {
    bindVariableService.setByte("xyz", (byte) 8);
    Function func = expr("b + :xyz").withFunction(new AddByteFunctionFactory()).withColumn("b", ColumnType.BYTE, (byte) 22).$();
    func.init(null, sqlExecutionContext);
    Assert.assertEquals(30, func.getByte(builder.getRecord()));
    bindVariableService.setByte("xyz", (byte) 10);
    Assert.assertEquals(32, func.getByte(builder.getRecord()));
}
Also used : Function(io.questdb.cairo.sql.Function) Test(org.junit.Test)

Example 19 with Function

use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.

the class BindVariablesTest method testNonAsciiLowerCaseStr.

@Test
public void testNonAsciiLowerCaseStr() throws SqlException {
    bindVariableService.setStr("str", "abcDEFghiJKLm...() { _; } >_[$($())] { <<< %(='%') \"noPQRstuVXZ");
    Function func = expr("to_lowercase(:str)").withFunction(new ToLowercaseFunctionFactory()).$();
    func.init(null, sqlExecutionContext);
    TestUtils.assertEquals("abcdefghijklm...() { _; } >_[$($())] { <<< %(='%') \"nopqrstuvxz", func.getStr(builder.getRecord()));
}
Also used : Function(io.questdb.cairo.sql.Function) Test(org.junit.Test)

Example 20 with Function

use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.

the class BindVariablesTest method testFloat.

@Test
public void testFloat() throws SqlException {
    bindVariableService.setFloat("xyz", 7.6f);
    Function func = expr("a + :xyz").withFunction(new AddFloatFunctionFactory()).withColumn("a", ColumnType.FLOAT, 25.1f).$();
    func.init(null, sqlExecutionContext);
    Assert.assertEquals(32.7f, func.getFloat(builder.getRecord()), 0.001f);
    bindVariableService.setFloat("xyz", 0.78f);
    func.init(null, sqlExecutionContext);
    Assert.assertEquals(25.88f, func.getFloat(builder.getRecord()), 0.001f);
    func.close();
}
Also used : Function(io.questdb.cairo.sql.Function) Test(org.junit.Test)

Aggregations

Function (io.questdb.cairo.sql.Function)204 Test (org.junit.Test)101 UnaryFunction (io.questdb.griffin.engine.functions.UnaryFunction)39 IntList (io.questdb.std.IntList)33 Record (io.questdb.cairo.sql.Record)28 ToStrTimestampFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory)28 ToStrDateFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory)27 NotFunctionFactory (io.questdb.griffin.engine.functions.bool.NotFunctionFactory)26 InStrFunctionFactory (io.questdb.griffin.engine.functions.bool.InStrFunctionFactory)25 EqDoubleFunctionFactory (io.questdb.griffin.engine.functions.eq.EqDoubleFunctionFactory)25 EqIntFunctionFactory (io.questdb.griffin.engine.functions.eq.EqIntFunctionFactory)25 EqLongFunctionFactory (io.questdb.griffin.engine.functions.eq.EqLongFunctionFactory)25 OrFunctionFactory (io.questdb.griffin.engine.functions.bool.OrFunctionFactory)24 CastStrToGeoHashFunctionFactory (io.questdb.griffin.engine.functions.cast.CastStrToGeoHashFunctionFactory)23 CursorDereferenceFunctionFactory (io.questdb.griffin.engine.functions.catalogue.CursorDereferenceFunctionFactory)23 SysdateFunctionFactory (io.questdb.griffin.engine.functions.date.SysdateFunctionFactory)23 LengthStrFunctionFactory (io.questdb.griffin.engine.functions.str.LengthStrFunctionFactory)23 LengthSymbolFunctionFactory (io.questdb.griffin.engine.functions.str.LengthSymbolFunctionFactory)23 ToCharBinFunctionFactory (io.questdb.griffin.engine.functions.str.ToCharBinFunctionFactory)23 SwitchFunctionFactory (io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory)22