use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class TypeOfFunctionFactory method newInstance.
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
if (args != null && args.size() == 1) {
final Function arg = args.getQuick(0);
final int argType = arg.getType();
return ColumnType.isNull(argType) ? NULL : TYPE_NAMES.get(arg.getType());
}
throw SqlException.$(position, "exactly one argument expected");
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class NullRecordFactory method getInstance.
public static Record getInstance(ColumnTypes types) {
final ObjList<Function> functions = new ObjList<>(types.getColumnCount());
for (int i = 0, n = types.getColumnCount(); i < n; i++) {
Function function = Constants.getNullConstant(types.getColumnType(i));
assert function != null;
functions.add(function);
}
return new VirtualRecord(functions);
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class FunctionParserEqFunctionsNullTest method testEqFunctionResolutionNullArgsForNumericTypes.
@Test
public void testEqFunctionResolutionNullArgsForNumericTypes() throws SqlException {
functions.addAll(Arrays.asList(EQ_FUNCS));
FunctionParser functionParser = createFunctionParser();
for (int col0Type : EQUIVALENT_NULL_TYPES) {
for (int col1Type : EQUIVALENT_NULL_TYPES) {
final GenericRecordMetadata metadata = new GenericRecordMetadata();
metadata.add(new TableColumnMetadata("col0", 1, col0Type));
metadata.add(new TableColumnMetadata("col1", 2, col1Type));
Collections.shuffle(functions);
Function function = parseFunction("null = null", metadata, functionParser);
Assert.assertEquals(ColumnType.BOOLEAN, function.getType());
Assert.assertTrue(function.getBool(ILLEGAL_ACCESS_RECORD));
function = parseFunction("null != null", metadata, functionParser);
Assert.assertEquals(ColumnType.BOOLEAN, function.getType());
Assert.assertFalse(function.getBool(ILLEGAL_ACCESS_RECORD));
function = parseFunction("col0 = null", metadata, functionParser);
Assert.assertEquals(ColumnType.BOOLEAN, function.getType());
Assert.assertTrue(function.getBool(NULL_RECORD));
function = parseFunction("col1 = null", metadata, functionParser);
Assert.assertEquals(ColumnType.BOOLEAN, function.getType());
Assert.assertTrue(function.getBool(NULL_RECORD));
function = parseFunction("col0 = col0", metadata, functionParser);
Assert.assertEquals(ColumnType.BOOLEAN, function.getType());
Assert.assertTrue(function.getBool(NULL_RECORD));
function = parseFunction("null = col0", metadata, functionParser);
Assert.assertEquals(ColumnType.BOOLEAN, function.getType());
Assert.assertTrue(function.getBool(NULL_RECORD));
function = parseFunction("null = col1", metadata, functionParser);
Assert.assertEquals(ColumnType.BOOLEAN, function.getType());
Assert.assertTrue(function.getBool(NULL_RECORD));
}
}
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class ToDateFunctionFactory method newInstance.
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
final Function arg = args.getQuick(0);
final CharSequence pattern = args.getQuick(1).getStr(null);
if (pattern == null) {
throw SqlException.$(argPositions.getQuick(1), "pattern is required");
}
return new ToDateFunction(arg, tlCompiler.get().compile(pattern), configuration.getDefaultDateLocale());
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class ToStrDateFunctionFactory method newInstance.
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
Function fmt = args.getQuick(1);
CharSequence format = fmt.getStr(null);
if (format == null) {
throw SqlException.$(argPositions.getQuick(1), "format must not be null");
}
DateFormat dateFormat = tlCompiler.get().compile(fmt.getStr(null));
Function var = args.getQuick(0);
if (var.isConstant()) {
long value = var.getDate(null);
if (value == Numbers.LONG_NaN) {
return StrConstant.NULL;
}
StringSink sink = tlSink.get();
sink.clear();
dateFormat.format(value, configuration.getDefaultDateLocale(), "Z", sink);
return new StrConstant(sink);
}
return new ToCharDateVCFFunc(args.getQuick(0), tlCompiler.get().compile(format), configuration.getDefaultDateLocale());
}
Aggregations