use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class CastStrToGeoHashFunctionFactory method newInstance.
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
Function value = args.getQuick(0);
int argPosition = argPositions.getQuick(0);
int geoType = args.getQuick(1).getType();
return newInstance(argPosition, geoType, value);
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class CaseCommon method getCastFunction.
static Function getCastFunction(Function arg, int argPosition, int toType, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
if (ColumnType.isNull(arg.getType())) {
return Constants.getNullConstant(toType);
}
final int keyIndex = castFactories.keyIndex(Numbers.encodeLowHighInts(arg.getType(), toType));
if (keyIndex < 0) {
FunctionFactory fact = castFactories.valueAt(keyIndex);
ObjList<Function> args = tlArgs.get();
args.clear();
args.add(arg);
IntList argPositions = tlArgPositions.get();
argPositions.clear();
argPositions.add(argPosition);
return fact.newInstance(0, args, argPositions, configuration, sqlExecutionContext);
}
return arg;
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class TimestampCeilFunctionFactory method newInstance.
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
final Function kind = args.getQuick(0);
final char c = kind.getChar(null);
switch(c) {
case 'd':
return new TimestampCeilDDFunction(args.getQuick(1));
case 'M':
return new TimestampCeilMMFunction(args.getQuick(1));
case 'y':
return new TimestampCeilYYYYFunction(args.getQuick(1));
case 'h':
return new TimestampCeilHHFunction(args.getQuick(1));
case 'm':
return new TimestampCeilMIFunction(args.getQuick(1));
case 's':
return new TimestampCeilSSFunction(args.getQuick(1));
case 'T':
return new TimestampCeilMSFunction(args.getQuick(1));
case 0:
throw SqlException.position(argPositions.getQuick(0)).put("invalid kind 'null'");
default:
throw SqlException.position(argPositions.getQuick(0)).put("invalid kind '").put(c).put('\'');
}
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class CursorDereferenceFunctionFactory method newInstance.
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
Function cursorFunction = args.getQuick(0);
Function columnNameFunction = args.getQuick(1);
RecordMetadata metadata = cursorFunction.getMetadata();
// name is always constant
final CharSequence columnName = columnNameFunction.getStr(null);
final int columnIndex = metadata.getColumnIndexQuiet(columnName);
if (columnIndex == -1) {
throw SqlException.invalidColumn(argPositions.getQuick(1), columnName);
}
final int columnType = metadata.getColumnType(columnIndex);
if (ColumnType.isInt(columnType)) {
return new IntColumnFunction(cursorFunction, columnNameFunction, columnIndex);
}
throw SqlException.$(argPositions.getQuick(1), "unsupported column type: ").put(ColumnType.nameOf(columnType));
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class ClassResolveFunctionFactory method newInstance.
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
final Function nameFunction = args.getQuick(0);
final CharSequence type = args.getQuick(1).getStr(null);
if (SqlKeywords.isRegclassKeyword(type)) {
final IntConstant func = map.get(nameFunction.getStr(null));
if (func != null) {
return func;
}
throw SqlException.$(argPositions.getQuick(0), "unsupported class");
}
if (SqlKeywords.isRegprocKeyword(type) || SqlKeywords.isRegprocedureKeyword(type)) {
// return fake OID
return new IntConstant(289208840);
}
if (SqlKeywords.isTimestampKeyword(type)) {
return new ToTimestampFunctionFactory.ToTimestampFunction(nameFunction);
}
if (SqlKeywords.isDateKeyword(type)) {
return new ToPgDateFunctionFactory.ToPgDateFunction(nameFunction);
}
if (SqlKeywords.isTextArrayKeyword(type)) {
return new StringToStringArrayFunction(argPositions.getQuick(0), nameFunction.getStr(null));
}
throw SqlException.$(argPositions.getQuick(1), "unsupported type");
}
Aggregations