Search in sources :

Example 66 with Record

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

the class LastGeoHashGroupByFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) {
    Function function = args.getQuick(0);
    int type = function.getType();
    // Reuse first implementation overriding computeNext() method inline
    switch(ColumnType.tagOf(type)) {
        case ColumnType.GEOBYTE:
            return new FirstGeoHashGroupByFunctionByte(type, function) {

                @Override
                public void computeNext(MapValue mapValue, Record record) {
                    mapValue.putByte(this.valueIndex, this.function.getGeoByte(record));
                }
            };
        case ColumnType.GEOSHORT:
            return new FirstGeoHashGroupByFunctionShort(type, function) {

                @Override
                public void computeNext(MapValue mapValue, Record record) {
                    mapValue.putShort(this.valueIndex, this.function.getGeoShort(record));
                }
            };
        case ColumnType.GEOINT:
            return new FirstGeoHashGroupByFunctionInt(type, function) {

                @Override
                public void computeNext(MapValue mapValue, Record record) {
                    mapValue.putInt(this.valueIndex, this.function.getGeoInt(record));
                }
            };
        default:
            return new FirstGeoHashGroupByFunctionLong(type, function) {

                @Override
                public void computeNext(MapValue mapValue, Record record) {
                    mapValue.putLong(this.valueIndex, this.function.getGeoLong(record));
                }
            };
    }
}
Also used : Function(io.questdb.cairo.sql.Function) MapValue(io.questdb.cairo.map.MapValue) Record(io.questdb.cairo.sql.Record)

Example 67 with Record

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

the class IntersectRecordCursor method populateSlaveMap.

private void populateSlaveMap(RecordCursor cursor) {
    final Record record = cursor.getRecord();
    while (cursor.hasNext()) {
        MapKey key = map.withKey();
        key.put(record, recordSink);
        key.createValue();
        interruptor.checkInterrupted();
    }
}
Also used : MapKey(io.questdb.cairo.map.MapKey) Record(io.questdb.cairo.sql.Record)

Example 68 with Record

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

the class RecordValueSinkFactoryTest method testSubset.

@Test
public void testSubset() {
    SingleColumnType keyTypes = new SingleColumnType(ColumnType.INT);
    try (TableModel model = new TableModel(configuration, "all", PartitionBy.NONE).col("int", ColumnType.INT).col("short", ColumnType.SHORT).col("byte", ColumnType.BYTE).col("double", ColumnType.DOUBLE).col("float", ColumnType.FLOAT).col("long", ColumnType.LONG).col("sym", ColumnType.SYMBOL).symbolCapacity(64).col("bool", ColumnType.BOOLEAN).col("date", ColumnType.DATE).col("ts", ColumnType.TIMESTAMP)) {
        CairoTestUtils.create(model);
    }
    final int N = 1024;
    final Rnd rnd = new Rnd();
    try (TableWriter writer = new TableWriter(configuration, "all")) {
        for (int i = 0; i < N; i++) {
            TableWriter.Row row = writer.newRow();
            row.putInt(0, rnd.nextInt());
            row.putShort(1, rnd.nextShort());
            row.putByte(2, rnd.nextByte());
            row.putDouble(3, rnd.nextDouble());
            row.putFloat(4, rnd.nextFloat());
            row.putLong(5, rnd.nextLong());
            row.putSym(6, rnd.nextChars(10));
            row.putBool(7, rnd.nextBoolean());
            row.putDate(8, rnd.nextLong());
            row.putTimestamp(9, rnd.nextLong());
            row.append();
        }
        writer.commit();
    }
    try (TableReader reader = new TableReader(configuration, "all")) {
        ArrayColumnTypes valueTypes = new ArrayColumnTypes();
        valueTypes.add(ColumnType.BOOLEAN);
        valueTypes.add(ColumnType.TIMESTAMP);
        valueTypes.add(ColumnType.INT);
        try (final Map map = new FastMap(Numbers.SIZE_1MB, keyTypes, valueTypes, N, 0.5, 100)) {
            ListColumnFilter columnFilter = new ListColumnFilter();
            columnFilter.add(8);
            columnFilter.add(10);
            columnFilter.add(7);
            RecordValueSink sink = RecordValueSinkFactory.getInstance(new BytecodeAssembler(), reader.getMetadata(), columnFilter);
            RecordCursor cursor = reader.getCursor();
            final Record record = cursor.getRecord();
            int index = 0;
            while (cursor.hasNext()) {
                MapKey key = map.withKey();
                key.putInt(index++);
                MapValue value = key.createValue();
                sink.copy(record, value);
            }
            Assert.assertEquals(N, index);
            rnd.reset();
            StaticSymbolTable symbolTable = reader.getSymbolMapReader(6);
            for (int i = 0; i < N; i++) {
                MapKey key = map.withKey();
                key.putInt(i);
                MapValue value = key.findValue();
                Assert.assertNotNull(value);
                // 0
                rnd.nextInt();
                // 1
                rnd.nextShort();
                // 2
                rnd.nextByte();
                // 3
                rnd.nextDouble();
                // 4
                rnd.nextFloat();
                // 5
                rnd.nextLong();
                // 6
                Assert.assertEquals(symbolTable.keyOf(rnd.nextChars(10)), value.getInt(2));
                // 7
                Assert.assertEquals(rnd.nextBoolean(), value.getBool(0));
                // 8
                rnd.nextLong();
                // 9
                Assert.assertEquals(rnd.nextLong(), value.getTimestamp(1));
            }
        }
    }
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) Rnd(io.questdb.std.Rnd) BytecodeAssembler(io.questdb.std.BytecodeAssembler) StaticSymbolTable(io.questdb.cairo.sql.StaticSymbolTable) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 69 with Record

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

the class DataFrameRecordCursorFactoryTest method testFactory.

@Test
public void testFactory() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        final int N = 100;
        // separate two symbol columns with primitive. It will make problems apparent if index does not shift correctly
        try (TableModel model = new TableModel(configuration, "x", PartitionBy.DAY).col("a", ColumnType.STRING).col("b", ColumnType.SYMBOL).indexed(true, N / 4).col("i", ColumnType.INT).col("c", ColumnType.SYMBOL).indexed(true, N / 4).timestamp()) {
            CairoTestUtils.create(model);
        }
        final Rnd rnd = new Rnd();
        final String[] symbols = new String[N];
        final int M = 1000;
        final long increment = 1000000 * 60L * 4;
        for (int i = 0; i < N; i++) {
            symbols[i] = rnd.nextChars(8).toString();
        }
        rnd.reset();
        // prepare the data
        long timestamp = 0;
        try (TableWriter writer = new TableWriter(configuration, "x")) {
            for (int i = 0; i < M; i++) {
                TableWriter.Row row = writer.newRow(timestamp += increment);
                row.putStr(0, rnd.nextChars(20));
                row.putSym(1, symbols[rnd.nextPositiveInt() % N]);
                row.putInt(2, rnd.nextInt());
                row.putSym(3, symbols[rnd.nextPositiveInt() % N]);
                row.append();
            }
            writer.commit();
        }
        try (CairoEngine engine = new CairoEngine(configuration)) {
            String value = symbols[N - 10];
            int columnIndex;
            int symbolKey;
            RecordMetadata metadata;
            try (TableReader reader = engine.getReader(AllowAllCairoSecurityContext.INSTANCE, "x", TableUtils.ANY_TABLE_ID, TableUtils.ANY_TABLE_VERSION)) {
                columnIndex = reader.getMetadata().getColumnIndexQuiet("b");
                symbolKey = reader.getSymbolMapReader(columnIndex).keyOf(value);
                metadata = GenericRecordMetadata.copyOf(reader.getMetadata());
            }
            SymbolIndexRowCursorFactory symbolIndexRowCursorFactory = new SymbolIndexRowCursorFactory(columnIndex, symbolKey, true, BitmapIndexReader.DIR_FORWARD, null);
            FullFwdDataFrameCursorFactory dataFrameFactory = new FullFwdDataFrameCursorFactory(engine, "x", TableUtils.ANY_TABLE_ID, TableUtils.ANY_TABLE_VERSION);
            // entity index
            final IntList columnIndexes = new IntList();
            for (int i = 0, n = metadata.getColumnCount(); i < n; i++) {
                columnIndexes.add(i);
            }
            DataFrameRecordCursorFactory factory = new DataFrameRecordCursorFactory(metadata, dataFrameFactory, symbolIndexRowCursorFactory, false, null, false, columnIndexes, null);
            SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1).with(AllowAllCairoSecurityContext.INSTANCE, null, null, -1, null);
            try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
                Record record = cursor.getRecord();
                while (cursor.hasNext()) {
                    TestUtils.assertEquals(value, record.getSym(1));
                }
            }
        }
    });
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) Rnd(io.questdb.std.Rnd) IntList(io.questdb.std.IntList) RecordMetadata(io.questdb.cairo.sql.RecordMetadata) SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 70 with Record

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

the class MinCharGroupByFunctionFactoryTest method testAllNull.

@Test
public void testAllNull() throws SqlException {
    compiler.compile("create table tab (f char)", sqlExecutionContext);
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
        for (int i = 100; i > 10; i--) {
            TableWriter.Row r = w.newRow();
            r.append();
        }
        w.commit();
    }
    try (RecordCursorFactory factory = compiler.compile("select min(f) from tab", sqlExecutionContext).getRecordCursorFactory()) {
        try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
            Record record = cursor.getRecord();
            Assert.assertEquals(1, cursor.size());
            Assert.assertTrue(cursor.hasNext());
            Assert.assertEquals(0, record.getChar(0));
        }
    }
}
Also used : TableWriter(io.questdb.cairo.TableWriter) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) 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