Search in sources :

Example 6 with ToStrTimestampFunctionFactory

use of io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory in project questdb by bluestreak01.

the class BindVariablesTest method testBinIndexed.

@Test
public void testBinIndexed() throws SqlException {
    Rnd rnd = new Rnd();
    TestBinarySequence sequence = new TestBinarySequence();
    sequence.of(rnd.nextBytes(256));
    bindVariableService.setBin(1, null);
    bindVariableService.setBin(0, sequence);
    Function func = expr("to_char($1)").withFunction(new ToCharBinFunctionFactory()).withFunction(new ToStrTimestampFunctionFactory()).$();
    func.init(null, sqlExecutionContext);
    Function func2 = expr("length($1)").withFunction(new LengthBinFunctionFactory()).$();
    func2.init(null, sqlExecutionContext);
    TestUtils.assertEquals("00000000 56 54 4a 57 43 50 53 57 48 59 52 58 50 45 48 4e\n" + "00000010 52 58 47 5a 53 58 55 58 49 42 42 54 47 50 47 57\n" + "00000020 46 46 59 55 44 45 59 59 51 45 48 42 48 46 4f 57\n" + "00000030 4c 50 44 58 59 53 42 45 4f 55 4f 4a 53 48 52 55\n" + "00000040 45 44 52 51 51 55 4c 4f 46 4a 47 45 54 4a 52 53\n" + "00000050 5a 53 52 59 52 46 42 56 54 4d 48 47 4f 4f 5a 5a\n" + "00000060 56 44 5a 4a 4d 59 49 43 43 58 5a 4f 55 49 43 57\n" + "00000070 45 4b 47 48 56 55 56 53 44 4f 54 53 45 44 59 59\n" + "00000080 43 54 47 51 4f 4c 59 58 57 43 4b 59 4c 53 55 57\n" + "00000090 44 53 57 55 47 53 48 4f 4c 4e 56 54 49 51 42 5a\n" + "000000a0 58 49 4f 56 49 4b 4a 53 4d 53 53 55 51 53 52 4c\n" + "000000b0 54 4b 56 56 53 4a 4f 4a 49 50 48 5a 45 50 49 48\n" + "000000c0 56 4c 54 4f 56 4c 4a 55 4d 4c 47 4c 48 4d 4c 4c\n" + "000000d0 45 4f 59 50 48 52 49 50 5a 49 4d 4e 5a 5a 52 4d\n" + "000000e0 46 4d 42 45 5a 47 48 57 56 44 4b 46 4c 4f 50 4a\n" + "000000f0 4f 58 50 4b 52 47 49 49 48 59 48 42 4f 51 4d 59", func.getStr(builder.getRecord()));
    // check that bin bind variable length is accurate
    Assert.assertEquals(256, func2.getLong(builder.getRecord()));
    sequence.of(rnd.nextBytes(16));
    bindVariableService.setBin(0, sequence);
    TestUtils.assertEquals("00000000 53 53 4d 50 47 4c 55 4f 48 4e 5a 48 5a 53 51 4c", func.getStr(builder.getRecord()));
    bindVariableService.setBin(0, new TestBinarySequence().of(rnd.nextBytes(24)));
    TestUtils.assertEquals("00000000 44 47 4c 4f 47 49 46 4f 55 53 5a 4d 5a 56 51 45\n" + "00000010 42 4e 44 43 51 43 45 48", func.getStr(builder.getRecord()));
}
Also used : ToStrTimestampFunctionFactory(io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory) TestBinarySequence(io.questdb.griffin.engine.TestBinarySequence) Function(io.questdb.cairo.sql.Function) Test(org.junit.Test)

Example 7 with ToStrTimestampFunctionFactory

use of io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory in project questdb by bluestreak01.

the class BindVariablesTest method testBin.

@Test
public void testBin() throws SqlException {
    Rnd rnd = new Rnd();
    TestBinarySequence sequence = new TestBinarySequence();
    sequence.of(rnd.nextBytes(256));
    bindVariableService.setBin("x", sequence);
    Function func = expr("to_char(:x)").withFunction(new ToCharBinFunctionFactory()).withFunction(new ToStrTimestampFunctionFactory()).$();
    func.init(null, sqlExecutionContext);
    Function func2 = expr("length(:x)").withFunction(new LengthBinFunctionFactory()).$();
    func2.init(null, sqlExecutionContext);
    TestUtils.assertEquals("00000000 56 54 4a 57 43 50 53 57 48 59 52 58 50 45 48 4e\n" + "00000010 52 58 47 5a 53 58 55 58 49 42 42 54 47 50 47 57\n" + "00000020 46 46 59 55 44 45 59 59 51 45 48 42 48 46 4f 57\n" + "00000030 4c 50 44 58 59 53 42 45 4f 55 4f 4a 53 48 52 55\n" + "00000040 45 44 52 51 51 55 4c 4f 46 4a 47 45 54 4a 52 53\n" + "00000050 5a 53 52 59 52 46 42 56 54 4d 48 47 4f 4f 5a 5a\n" + "00000060 56 44 5a 4a 4d 59 49 43 43 58 5a 4f 55 49 43 57\n" + "00000070 45 4b 47 48 56 55 56 53 44 4f 54 53 45 44 59 59\n" + "00000080 43 54 47 51 4f 4c 59 58 57 43 4b 59 4c 53 55 57\n" + "00000090 44 53 57 55 47 53 48 4f 4c 4e 56 54 49 51 42 5a\n" + "000000a0 58 49 4f 56 49 4b 4a 53 4d 53 53 55 51 53 52 4c\n" + "000000b0 54 4b 56 56 53 4a 4f 4a 49 50 48 5a 45 50 49 48\n" + "000000c0 56 4c 54 4f 56 4c 4a 55 4d 4c 47 4c 48 4d 4c 4c\n" + "000000d0 45 4f 59 50 48 52 49 50 5a 49 4d 4e 5a 5a 52 4d\n" + "000000e0 46 4d 42 45 5a 47 48 57 56 44 4b 46 4c 4f 50 4a\n" + "000000f0 4f 58 50 4b 52 47 49 49 48 59 48 42 4f 51 4d 59", func.getStr(builder.getRecord()));
    // check that bin bind variable length is accurate
    Assert.assertEquals(256, func2.getLong(builder.getRecord()));
    sequence.of(rnd.nextBytes(16));
    bindVariableService.setBin("x", sequence);
    TestUtils.assertEquals("00000000 53 53 4d 50 47 4c 55 4f 48 4e 5a 48 5a 53 51 4c", func.getStr(builder.getRecord()));
    bindVariableService.setBin("x", new TestBinarySequence().of(rnd.nextBytes(24)));
    TestUtils.assertEquals("00000000 44 47 4c 4f 47 49 46 4f 55 53 5a 4d 5a 56 51 45\n" + "00000010 42 4e 44 43 51 43 45 48", func.getStr(builder.getRecord()));
}
Also used : ToStrTimestampFunctionFactory(io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory) TestBinarySequence(io.questdb.griffin.engine.TestBinarySequence) Function(io.questdb.cairo.sql.Function) Test(org.junit.Test)

Aggregations

ToStrTimestampFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory)7 Test (org.junit.Test)7 Function (io.questdb.cairo.sql.Function)6 ToStrDateFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory)3 TestBinarySequence (io.questdb.griffin.engine.TestBinarySequence)2 Record (io.questdb.cairo.sql.Record)1 ToCharBinFunctionFactory (io.questdb.griffin.engine.functions.str.ToCharBinFunctionFactory)1