Search in sources :

Example 31 with Record

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

the class FunctionParserTest method testConstVarArgFunction.

@Test
public void testConstVarArgFunction() throws SqlException {
    functions.add(new InStrFunctionFactory());
    final GenericRecordMetadata metadata = new GenericRecordMetadata();
    metadata.add(new TableColumnMetadata("a", 1, ColumnType.STRING));
    FunctionParser functionParser = createFunctionParser();
    Function function = parseFunction("a in ('xu', 'yk')", metadata, functionParser);
    Assert.assertEquals(ColumnType.BOOLEAN, function.getType());
    Assert.assertTrue(function.getBool(new Record() {

        @Override
        public CharSequence getStr(int col) {
            return "yk";
        }
    }));
}
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 32 with Record

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

the class FunctionParserTest method testImplicitConstantInt.

@Test
public void testImplicitConstantInt() 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 IntFunction() {

                @Override
                public int getInt(Record rec) {
                    return 0;
                }

                @Override
                public boolean isConstant() {
                    return true;
                }
            };
        }
    });
    Function function = parseFunction("x()", new GenericRecordMetadata(), createFunctionParser());
    Assert.assertTrue(function instanceof IntConstant);
}
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 33 with Record

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

the class FunctionParserTest method testAmbiguousFunctionInvocation.

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

        @Override
        public String getSignature() {
            // double,double
            return "+(DD)";
        }

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

                @Override
                public double getDouble(Record rec) {
                    return 123.123;
                }
            };
        }
    });
    functions.add(new FunctionFactory() {

        @Override
        public String getSignature() {
            // float,float
            return "+(FF)";
        }

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

                @Override
                public float getFloat(Record rec) {
                    return 123.123f;
                }
            };
        }
    });
    final GenericRecordMetadata metadata = new GenericRecordMetadata();
    metadata.add(new TableColumnMetadata("a", 1, ColumnType.BYTE));
    metadata.add(new TableColumnMetadata("c", 2, ColumnType.SHORT));
    FunctionParser functionParser = createFunctionParser();
    Function f = parseFunction("a + c", metadata, functionParser);
    Assert.assertEquals(123.123f, f.getFloat(null), 0.0001);
}
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 34 with Record

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

the class FunctionParserTest method testBooleanConstants.

@Test
public void testBooleanConstants() throws SqlException {
    functions.add(new NotFunctionFactory());
    functions.add(new OrFunctionFactory());
    final Record record = new Record() {

        @Override
        public boolean getBool(int col) {
            // col0 = false
            return false;
        }
    };
    final GenericRecordMetadata metadata = new GenericRecordMetadata();
    metadata.add(new TableColumnMetadata("a", 1, ColumnType.BOOLEAN));
    FunctionParser functionParser = createFunctionParser();
    Function function = parseFunction("a or not false", metadata, functionParser);
    Assert.assertEquals(ColumnType.BOOLEAN, function.getType());
    Assert.assertTrue(function.getBool(record));
    Function function2 = parseFunction("a or true", metadata, functionParser);
    Assert.assertTrue(function2.getBool(record));
}
Also used : Function(io.questdb.cairo.sql.Function) OrFunctionFactory(io.questdb.griffin.engine.functions.bool.OrFunctionFactory) Record(io.questdb.cairo.sql.Record) NotFunctionFactory(io.questdb.griffin.engine.functions.bool.NotFunctionFactory) Test(org.junit.Test)

Example 35 with Record

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

the class FunctionParserTest method testImplicitConstantNull.

@Test
public void testImplicitConstantNull() 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() {

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

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

                @Override
                public boolean isConstant() {
                    return true;
                }
            };
        }
    });
    Function function = parseFunction("x()", new GenericRecordMetadata(), createFunctionParser());
    Assert.assertSame(StrConstant.NULL, function);
}
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)

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