Search in sources :

Example 16 with IntList

use of io.questdb.std.IntList 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 17 with IntList

use of io.questdb.std.IntList in project questdb by bluestreak01.

the class EqTimestampStrFunctionFactoryTest method testFalseWhenVariableStringIsNotValidTimestamp.

@Test
public void testFalseWhenVariableStringIsNotValidTimestamp() throws SqlException, NumericException {
    long timestamp = parseUTCTimestamp("2020-12-31T23:59:59.000000Z");
    CharSequence invalidTimestamp = "abc";
    FunctionFactory factory = getFunctionFactory();
    ObjList<Function> args = new ObjList<>();
    args.add(TimestampColumn.newInstance(0));
    args.add(StrColumn.newInstance(5));
    IntList argPositions = new IntList();
    argPositions.add(0);
    argPositions.add(1);
    Function function = factory.newInstance(3, args, argPositions, configuration, sqlExecutionContext);
    Assert.assertFalse(function.getBool(new Record() {

        @Override
        public CharSequence getStr(int col) {
            return invalidTimestamp;
        }

        @Override
        public long getTimestamp(int col) {
            return timestamp;
        }
    }));
}
Also used : Function(io.questdb.cairo.sql.Function) ObjList(io.questdb.std.ObjList) Record(io.questdb.cairo.sql.Record) InTimestampStrFunctionFactory(io.questdb.griffin.engine.functions.bool.InTimestampStrFunctionFactory) FunctionFactory(io.questdb.griffin.FunctionFactory) IntList(io.questdb.std.IntList) Test(org.junit.Test) AbstractFunctionFactoryTest(io.questdb.griffin.engine.AbstractFunctionFactoryTest)

Example 18 with IntList

use of io.questdb.std.IntList in project questdb by bluestreak01.

the class EqDoubleFunctionFactoryTest method testLeftNaNTimestamp.

@Test
public void testLeftNaNTimestamp() throws SqlException {
    FunctionFactory factory = getFunctionFactory();
    ObjList<Function> args = new ObjList<>();
    args.add(DoubleConstant.NULL);
    args.add(new TimestampConstant(20000L));
    IntList argPositions = new IntList();
    argPositions.add(2);
    argPositions.add(1);
    Function function = factory.newInstance(4, args, argPositions, configuration, sqlExecutionContext);
    Assert.assertFalse(function.getBool(null));
    Assert.assertTrue(function.isConstant());
}
Also used : Function(io.questdb.cairo.sql.Function) TimestampConstant(io.questdb.griffin.engine.functions.constants.TimestampConstant) ObjList(io.questdb.std.ObjList) FunctionFactory(io.questdb.griffin.FunctionFactory) IntList(io.questdb.std.IntList) Test(org.junit.Test) AbstractFunctionFactoryTest(io.questdb.griffin.engine.AbstractFunctionFactoryTest)

Example 19 with IntList

use of io.questdb.std.IntList in project questdb by bluestreak01.

the class EqDoubleFunctionFactoryTest method testRightNaNTimestamp.

@Test
public void testRightNaNTimestamp() throws SqlException {
    FunctionFactory factory = getFunctionFactory();
    ObjList<Function> args = new ObjList<>();
    args.add(new TimestampConstant(20000L));
    args.add(DoubleConstant.NULL);
    IntList argPositions = new IntList();
    argPositions.add(1);
    argPositions.add(2);
    Function function = factory.newInstance(4, args, argPositions, configuration, sqlExecutionContext);
    Assert.assertFalse(function.getBool(null));
}
Also used : Function(io.questdb.cairo.sql.Function) TimestampConstant(io.questdb.griffin.engine.functions.constants.TimestampConstant) ObjList(io.questdb.std.ObjList) FunctionFactory(io.questdb.griffin.FunctionFactory) IntList(io.questdb.std.IntList) Test(org.junit.Test) AbstractFunctionFactoryTest(io.questdb.griffin.engine.AbstractFunctionFactoryTest)

Example 20 with IntList

use of io.questdb.std.IntList in project questdb by bluestreak01.

the class EqDoubleFunctionFactoryTest method testRightNaNFloat.

@Test
public void testRightNaNFloat() throws SqlException {
    FunctionFactory factory = getFunctionFactory();
    ObjList<Function> args = new ObjList<>();
    args.add(new DoubleConstant(Double.NaN));
    args.add(new FloatConstant(5.1f) {

        @Override
        public boolean isConstant() {
            return false;
        }
    });
    IntList argPositions = new IntList();
    argPositions.add(2);
    argPositions.add(1);
    Function function = factory.newInstance(4, args, argPositions, configuration, sqlExecutionContext);
    Assert.assertFalse(function.getBool(null));
    Assert.assertFalse(function.isConstant());
}
Also used : Function(io.questdb.cairo.sql.Function) DoubleConstant(io.questdb.griffin.engine.functions.constants.DoubleConstant) ObjList(io.questdb.std.ObjList) FloatConstant(io.questdb.griffin.engine.functions.constants.FloatConstant) FunctionFactory(io.questdb.griffin.FunctionFactory) IntList(io.questdb.std.IntList) Test(org.junit.Test) AbstractFunctionFactoryTest(io.questdb.griffin.engine.AbstractFunctionFactoryTest)

Aggregations

IntList (io.questdb.std.IntList)37 Function (io.questdb.cairo.sql.Function)33 Test (org.junit.Test)31 InStrFunctionFactory (io.questdb.griffin.engine.functions.bool.InStrFunctionFactory)22 NotFunctionFactory (io.questdb.griffin.engine.functions.bool.NotFunctionFactory)22 OrFunctionFactory (io.questdb.griffin.engine.functions.bool.OrFunctionFactory)22 CastStrToGeoHashFunctionFactory (io.questdb.griffin.engine.functions.cast.CastStrToGeoHashFunctionFactory)22 CursorDereferenceFunctionFactory (io.questdb.griffin.engine.functions.catalogue.CursorDereferenceFunctionFactory)22 SwitchFunctionFactory (io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory)22 SysdateFunctionFactory (io.questdb.griffin.engine.functions.date.SysdateFunctionFactory)22 ToStrDateFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory)22 ToStrTimestampFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory)22 EqDoubleFunctionFactory (io.questdb.griffin.engine.functions.eq.EqDoubleFunctionFactory)22 EqIntFunctionFactory (io.questdb.griffin.engine.functions.eq.EqIntFunctionFactory)22 EqLongFunctionFactory (io.questdb.griffin.engine.functions.eq.EqLongFunctionFactory)22 LengthStrFunctionFactory (io.questdb.griffin.engine.functions.str.LengthStrFunctionFactory)22 LengthSymbolFunctionFactory (io.questdb.griffin.engine.functions.str.LengthSymbolFunctionFactory)22 ToCharBinFunctionFactory (io.questdb.griffin.engine.functions.str.ToCharBinFunctionFactory)22 Record (io.questdb.cairo.sql.Record)15 FunctionFactory (io.questdb.griffin.FunctionFactory)11