Search in sources :

Example 6 with Function

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

the class BindVariablesTest method testUppercaseStr.

@Test
public void testUppercaseStr() throws SqlException {
    bindVariableService.setStr("str", "abcDEFghiJKLmnoPQRstuVXZ");
    Function func = expr("to_uppercase(:str)").withFunction(new ToUppercaseFunctionFactory()).$();
    func.init(null, sqlExecutionContext);
    TestUtils.assertEquals("ABCDEFGHIJKLMNOPQRSTUVXZ", func.getStr(builder.getRecord()));
}
Also used : Function(io.questdb.cairo.sql.Function) Test(org.junit.Test)

Example 7 with Function

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

the class BindVariablesTest method testCharIndexed.

@Test
public void testCharIndexed() throws SqlException {
    bindVariableService.setChar(0, 'C');
    bindVariableService.setChar(1, 'A');
    Function func = expr("$1 || $2").withFunction(new ConcatFunctionFactory()).$();
    func.init(null, sqlExecutionContext);
    TestUtils.assertEquals("CA", func.getStr(builder.getRecord()));
    bindVariableService.setChar(1, '0');
    func.init(null, sqlExecutionContext);
    TestUtils.assertEquals("C0", func.getStr(builder.getRecord()));
    func.close();
}
Also used : Function(io.questdb.cairo.sql.Function) Test(org.junit.Test)

Example 8 with Function

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

the class BindVariablesTest method testBooleanIndexed.

@Test
public void testBooleanIndexed() throws SqlException {
    bindVariableService.setBoolean(1, false);
    bindVariableService.setBoolean(0, false);
    Function func = expr("not $1").withFunction(new NotFunctionFactory()).$();
    func.init(null, sqlExecutionContext);
    Assert.assertTrue(func.getBool(builder.getRecord()));
    bindVariableService.setBoolean(0, 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)

Example 9 with Function

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

the class BindVariablesTest method testFloatExplicitlyIndexed.

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

Example 10 with Function

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

the class BindVariablesTest method testDate.

@Test
public void testDate() throws SqlException, NumericException {
    bindVariableService.setDate("xyz", DateFormatUtils.parseUTCDate("2015-04-10T10:00:00.000Z"));
    Function func = expr("to_str(:xyz, 'yyyy-MM')").withFunction(new ToStrDateFunctionFactory()).$();
    func.init(null, sqlExecutionContext);
    TestUtils.assertEquals("2015-04", func.getStr(builder.getRecord()));
    bindVariableService.setDate("xyz", 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)

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