Search in sources :

Example 36 with Record

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

the class FunctionParserTest method testVarArgFunction.

@Test
public void testVarArgFunction() throws SqlException {
    functions.add(new InStrFunctionFactory());
    final GenericRecordMetadata metadata = new GenericRecordMetadata();
    metadata.add(new TableColumnMetadata("a", 1, ColumnType.STRING));
    FunctionParser functionParser = createFunctionParser();
    Record record = new Record() {

        @Override
        public CharSequence getStr(int col) {
            return "YZ";
        }
    };
    Function function = parseFunction("a in ('XY', 'YZ')", metadata, functionParser);
    Assert.assertEquals(ColumnType.BOOLEAN, function.getType());
    Assert.assertTrue(function.getBool(record));
}
Also used : Function(io.questdb.cairo.sql.Function) InStrFunctionFactory(io.questdb.griffin.engine.functions.bool.InStrFunctionFactory) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 37 with Record

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

the class FunctionParserTest method testImplicitConstantStr.

@Test
public void testImplicitConstantStr() throws SqlException {
    functions.add(new FunctionFactory() {

        @Override
        public String getSignature() {
            return "x()";
        }

        @Override
        public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration1, SqlExecutionContext sqlExecutionContext) {
            return new StrFunction() {

                private final String x = "abc";

                @Override
                public CharSequence getStr(Record rec) {
                    return x;
                }

                @Override
                public CharSequence getStrB(Record rec) {
                    return x;
                }

                @Override
                public boolean isConstant() {
                    return true;
                }
            };
        }
    });
    Function function = parseFunction("x()", new GenericRecordMetadata(), createFunctionParser());
    Assert.assertTrue(function instanceof StrConstant);
}
Also used : IntList(io.questdb.std.IntList) Function(io.questdb.cairo.sql.Function) Record(io.questdb.cairo.sql.Record) SysdateFunctionFactory(io.questdb.griffin.engine.functions.date.SysdateFunctionFactory) EqLongFunctionFactory(io.questdb.griffin.engine.functions.eq.EqLongFunctionFactory) ToStrDateFunctionFactory(io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory) SwitchFunctionFactory(io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory) EqIntFunctionFactory(io.questdb.griffin.engine.functions.eq.EqIntFunctionFactory) LengthSymbolFunctionFactory(io.questdb.griffin.engine.functions.str.LengthSymbolFunctionFactory) OrFunctionFactory(io.questdb.griffin.engine.functions.bool.OrFunctionFactory) LengthStrFunctionFactory(io.questdb.griffin.engine.functions.str.LengthStrFunctionFactory) EqDoubleFunctionFactory(io.questdb.griffin.engine.functions.eq.EqDoubleFunctionFactory) InStrFunctionFactory(io.questdb.griffin.engine.functions.bool.InStrFunctionFactory) NotFunctionFactory(io.questdb.griffin.engine.functions.bool.NotFunctionFactory) CursorDereferenceFunctionFactory(io.questdb.griffin.engine.functions.catalogue.CursorDereferenceFunctionFactory) ToStrTimestampFunctionFactory(io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory) ToCharBinFunctionFactory(io.questdb.griffin.engine.functions.str.ToCharBinFunctionFactory) CastStrToGeoHashFunctionFactory(io.questdb.griffin.engine.functions.cast.CastStrToGeoHashFunctionFactory) Test(org.junit.Test)

Example 38 with Record

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

the class FunctionParserTest method testImplicitConstantDate.

@Test
public void testImplicitConstantDate() throws SqlException {
    functions.add(new FunctionFactory() {

        @Override
        public String getSignature() {
            return "x()";
        }

        @Override
        public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration1, SqlExecutionContext sqlExecutionContext) {
            return new DateFunction() {

                @Override
                public long getDate(Record rec) {
                    return 0;
                }

                @Override
                public boolean isConstant() {
                    return true;
                }
            };
        }
    });
    Function function = parseFunction("x()", new GenericRecordMetadata(), createFunctionParser());
    Assert.assertTrue(function instanceof DateConstant);
}
Also used : IntList(io.questdb.std.IntList) Function(io.questdb.cairo.sql.Function) Record(io.questdb.cairo.sql.Record) SysdateFunctionFactory(io.questdb.griffin.engine.functions.date.SysdateFunctionFactory) EqLongFunctionFactory(io.questdb.griffin.engine.functions.eq.EqLongFunctionFactory) ToStrDateFunctionFactory(io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory) SwitchFunctionFactory(io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory) EqIntFunctionFactory(io.questdb.griffin.engine.functions.eq.EqIntFunctionFactory) LengthSymbolFunctionFactory(io.questdb.griffin.engine.functions.str.LengthSymbolFunctionFactory) OrFunctionFactory(io.questdb.griffin.engine.functions.bool.OrFunctionFactory) LengthStrFunctionFactory(io.questdb.griffin.engine.functions.str.LengthStrFunctionFactory) EqDoubleFunctionFactory(io.questdb.griffin.engine.functions.eq.EqDoubleFunctionFactory) InStrFunctionFactory(io.questdb.griffin.engine.functions.bool.InStrFunctionFactory) NotFunctionFactory(io.questdb.griffin.engine.functions.bool.NotFunctionFactory) CursorDereferenceFunctionFactory(io.questdb.griffin.engine.functions.catalogue.CursorDereferenceFunctionFactory) ToStrTimestampFunctionFactory(io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory) ToCharBinFunctionFactory(io.questdb.griffin.engine.functions.str.ToCharBinFunctionFactory) CastStrToGeoHashFunctionFactory(io.questdb.griffin.engine.functions.cast.CastStrToGeoHashFunctionFactory) Test(org.junit.Test)

Example 39 with Record

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

the class O3CommitLagTest method insertUncommitted.

private void insertUncommitted(SqlCompiler compiler, SqlExecutionContext sqlExecutionContext, String sql, TableWriter writer) throws SqlException {
    minTimestamp = Long.MAX_VALUE;
    maxTimestamp = Long.MIN_VALUE;
    try (RecordCursorFactory factory = compiler.compile(sql, sqlExecutionContext).getRecordCursorFactory()) {
        RecordMetadata metadata = factory.getMetadata();
        int timestampIndex = writer.getMetadata().getTimestampIndex();
        EntityColumnFilter toColumnFilter = new EntityColumnFilter();
        toColumnFilter.of(metadata.getColumnCount());
        if (null == copier) {
            copier = SqlCompiler.assembleRecordToRowCopier(new BytecodeAssembler(), metadata, writer.getMetadata(), toColumnFilter);
        }
        try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
            final Record record = cursor.getRecord();
            while (cursor.hasNext()) {
                long timestamp = record.getTimestamp(timestampIndex);
                if (timestamp > maxTimestamp) {
                    maxTimestamp = timestamp;
                }
                if (timestamp < minTimestamp) {
                    minTimestamp = timestamp;
                }
                Row row = writer.newRow(timestamp);
                copier.copy(record, row);
                row.append();
            }
        }
    }
}
Also used : RecordMetadata(io.questdb.cairo.sql.RecordMetadata) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record) Row(io.questdb.cairo.TableWriter.Row) BytecodeAssembler(io.questdb.std.BytecodeAssembler)

Example 40 with Record

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

the class KeyedAggregationTest method testIntSymbolSumAddKeyTimeRange.

@Test
public void testIntSymbolSumAddKeyTimeRange() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table tab as (select rnd_symbol('s1','s2','s3', null) s1, rnd_double(2) val, timestamp_sequence(0, 1000000) t from long_sequence(1000000)) timestamp(t) partition by DAY", sqlExecutionContext);
        compiler.compile("alter table tab add column s2 symbol cache", sqlExecutionContext);
        compiler.compile("insert into tab select rnd_symbol('s1','s2','s3', null), rnd_double(2), timestamp_sequence(cast('1970-01-13T00:00:00.000000Z' as timestamp), 1000000), rnd_symbol('a1','a2','a3', null) s2 from long_sequence(1000000)", sqlExecutionContext);
        // test with key falling within null columns
        try (RecordCursorFactory factory = compiler.compile("select s2, sum(val) from tab where t >= '1970-01-04T12:01' and t < '1970-01-07T11:00' order by s2", sqlExecutionContext).getRecordCursorFactory()) {
            Record[] expected = new Record[] { new Record() {

                @Override
                public CharSequence getSym(int col) {
                    return null;
                }

                @Override
                public double getDouble(int col) {
                    return 106413.99769604905;
                }
            } };
            assertCursorRawRecords(expected, factory, false, true);
        }
        // / test key on overlap
        try (RecordCursorFactory factory = compiler.compile("select s2, sum(val) from tab where t >= '1970-01-12T12:01' and t < '1970-01-14T11:00' order by s2", sqlExecutionContext).getRecordCursorFactory()) {
            Record[] expected = new Record[] { new Record() {

                @Override
                public CharSequence getSym(int col) {
                    return null;
                }

                @Override
                public double getDouble(int col) {
                    return 15636.977658744854;
                }
            }, new Record() {

                @Override
                public CharSequence getSym(int col) {
                    return "a1";
                }

                @Override
                public double getDouble(int col) {
                    return 13073.816187889399;
                }
            }, new Record() {

                @Override
                public CharSequence getSym(int col) {
                    return "a2";
                }

                @Override
                public double getDouble(int col) {
                    return 13240.269899560482;
                }
            }, new Record() {

                @Override
                public CharSequence getSym(int col) {
                    return "a3";
                }

                @Override
                public double getDouble(int col) {
                    return 13223.021189180576;
                }
            } };
            assertCursorRawRecords(expected, factory, false, true);
        }
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Aggregations

Record (io.questdb.cairo.sql.Record)171 Test (org.junit.Test)130 RecordCursor (io.questdb.cairo.sql.RecordCursor)121 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)79 TableWriter (io.questdb.cairo.TableWriter)70 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)66 Rnd (io.questdb.std.Rnd)32 Function (io.questdb.cairo.sql.Function)28 InStrFunctionFactory (io.questdb.griffin.engine.functions.bool.InStrFunctionFactory)16 NotFunctionFactory (io.questdb.griffin.engine.functions.bool.NotFunctionFactory)15 OrFunctionFactory (io.questdb.griffin.engine.functions.bool.OrFunctionFactory)15 IntList (io.questdb.std.IntList)15 CastStrToGeoHashFunctionFactory (io.questdb.griffin.engine.functions.cast.CastStrToGeoHashFunctionFactory)14 ToStrDateFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory)14 ToStrTimestampFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory)14 LengthStrFunctionFactory (io.questdb.griffin.engine.functions.str.LengthStrFunctionFactory)14 LengthSymbolFunctionFactory (io.questdb.griffin.engine.functions.str.LengthSymbolFunctionFactory)14 ToCharBinFunctionFactory (io.questdb.griffin.engine.functions.str.ToCharBinFunctionFactory)14 CursorDereferenceFunctionFactory (io.questdb.griffin.engine.functions.catalogue.CursorDereferenceFunctionFactory)13 SwitchFunctionFactory (io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory)13