Search in sources :

Example 21 with Function

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

the class BindVariablesTest method testDoubleIndexed.

@Test
public void testDoubleIndexed() throws SqlException {
    bindVariableService.setDouble(2, Double.NaN);
    bindVariableService.setDouble(0, 0.223232);
    bindVariableService.setDouble(1, 9.222333);
    Function func = expr("$1 + $2").withFunction(new AddDoubleFunctionFactory()).$();
    func.init(null, sqlExecutionContext);
    Assert.assertEquals(9.445565, func.getDouble(builder.getRecord()), 0.001);
    bindVariableService.setDouble(1, 0.1322990);
    func.init(null, sqlExecutionContext);
    Assert.assertEquals(0.355531, func.getDouble(builder.getRecord()), 0.001);
    func.close();
}
Also used : Function(io.questdb.cairo.sql.Function) Test(org.junit.Test)

Example 22 with Function

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

the class BindVariablesTest method testDateIndexed.

@Test
public void testDateIndexed() throws SqlException, NumericException {
    bindVariableService.setDate(1, 0);
    bindVariableService.setDate(0, DateFormatUtils.parseUTCDate("2015-04-10T10:00:00.000Z"));
    Function func = expr("to_str($1, 'yyyy-MM')").withFunction(new ToStrDateFunctionFactory()).$();
    func.init(null, sqlExecutionContext);
    TestUtils.assertEquals("2015-04", func.getStr(builder.getRecord()));
    bindVariableService.setDate(0, DateFormatUtils.parseUTCDate("2015-08-10T10:00:00.000Z"));
    TestUtils.assertEquals("2015-08", func.getStr(builder.getRecord()));
}
Also used : Function(io.questdb.cairo.sql.Function) ToStrDateFunctionFactory(io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory) Test(org.junit.Test)

Example 23 with Function

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

the class BindVariablesTest method testShort.

@Test
public void testShort() throws SqlException {
    bindVariableService.setShort("xyz", (short) 8);
    Function func = expr("b + :xyz").withFunction(new AddShortFunctionFactory()).withColumn("b", ColumnType.SHORT, (short) 22).$();
    func.init(null, sqlExecutionContext);
    Assert.assertEquals(30, func.getShort(builder.getRecord()));
    bindVariableService.setShort("xyz", (short) 33);
    Assert.assertEquals(55, func.getShort(builder.getRecord()));
}
Also used : Function(io.questdb.cairo.sql.Function) Test(org.junit.Test)

Example 24 with Function

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

the class BindVariablesTest method testShortIndexed.

@Test
public void testShortIndexed() throws SqlException {
    bindVariableService.setShort(1, (short) 2);
    bindVariableService.setShort(0, (short) 8);
    Function func = expr("b + $1").withFunction(new AddShortFunctionFactory()).withColumn("b", ColumnType.SHORT, (short) 22).$();
    func.init(null, sqlExecutionContext);
    Assert.assertEquals(30, func.getShort(builder.getRecord()));
    bindVariableService.setShort(0, (short) 33);
    Assert.assertEquals(55, func.getShort(builder.getRecord()));
}
Also used : Function(io.questdb.cairo.sql.Function) Test(org.junit.Test)

Example 25 with Function

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

the class BindVariablesTest method testBoolean.

@Test
public void testBoolean() throws SqlException {
    bindVariableService.setBoolean("xyz", false);
    Function func = expr("not :xyz").withFunction(new NotFunctionFactory()).$();
    func.init(null, sqlExecutionContext);
    Assert.assertTrue(func.getBool(builder.getRecord()));
    bindVariableService.setBoolean("xyz", true);
    Assert.assertFalse(func.getBool(builder.getRecord()));
}
Also used : Function(io.questdb.cairo.sql.Function) NotFunctionFactory(io.questdb.griffin.engine.functions.bool.NotFunctionFactory) 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