use of io.questdb.std.str.StringSink in project questdb by questdb.
the class AbstractFunctionFactoryTest method callCustomised.
private Invocation callCustomised(String signature, boolean forceConstant, boolean argTypeFromSig, Object... args) throws SqlException {
setUp();
toShortRefs = 0;
toByteRefs = 0;
toTimestampRefs = 0;
toDateRefs = 0;
final FunctionFactory functionFactory = getFactory0();
if (signature == null) {
signature = functionFactory.getSignature();
}
// validate signature first
final int pos = FunctionFactoryDescriptor.validateSignatureAndGetNameSeparator(signature);
// create metadata
final GenericRecordMetadata metadata = new GenericRecordMetadata();
final String name = signature.substring(0, pos);
final int argCount;
final boolean hasVarArg;
final boolean constVarArg;
if (signature.indexOf('v', pos) != -1) {
hasVarArg = true;
constVarArg = true;
} else if (signature.indexOf('V', pos) != -1) {
hasVarArg = true;
constVarArg = false;
} else {
hasVarArg = false;
constVarArg = false;
}
if (hasVarArg) {
argCount = signature.length() - pos - 3;
Assert.assertTrue(args.length >= argCount);
} else {
argCount = signature.length() - pos - 2;
Assert.assertEquals("Invalid number of arguments", argCount, args.length);
}
final StringSink expression1 = new StringSink();
final StringSink expression2 = new StringSink();
final boolean setOperation = OperatorExpression.getOperatorType(name) == OperatorExpression.SET;
final boolean operator = OperatorExpression.isOperator(name);
if (operator && !setOperation) {
switch(argCount) {
case 0:
expression1.put(name);
expression2.put(name);
break;
case 1:
expression1.put(name).put(' ');
expression2.put(name).put(' ');
printArgument(signature, pos, forceConstant, metadata, argTypeFromSig, constVarArg, expression1, expression2, 0, args[0]);
break;
default:
// two args
printArgument(signature, pos, forceConstant, metadata, argTypeFromSig, constVarArg, expression1, expression2, 0, args[0]);
expression1.put(' ').put(name).put(' ');
expression2.put(' ').put(name).put(' ');
printArgument(signature, pos, forceConstant, metadata, argTypeFromSig, constVarArg, expression1, expression2, 1, args[1]);
break;
}
} else {
if (!setOperation) {
expression1.put(name).put('(');
expression2.put(name).put('(');
}
for (int i = 0, n = args.length; i < n; i++) {
if ((setOperation && i > 1) || (!setOperation && i > 0)) {
expression1.put(',');
expression2.put(',');
}
printArgument(signature, pos, forceConstant, metadata, i < argCount, constVarArg, expression1, expression2, i, args[i]);
if (i == 0 && setOperation) {
expression1.put(' ').put(name).put(' ').put('(');
expression2.put(' ').put(name).put(' ').put('(');
}
}
expression1.put(')');
expression2.put(')');
}
functions.add(functionFactory);
if (toTimestampRefs > 0) {
functions.add(new CastLongToTimestampFunctionFactory());
}
if (toDateRefs > 0) {
functions.add(new CastLongToDateFunctionFactory());
}
if (toShortRefs > 0) {
functions.add(new CastIntToShortFunctionFactory());
}
if (toByteRefs > 0) {
functions.add(new CastIntToByteFunctionFactory());
}
addExtraFunctions();
FunctionParser functionParser = new FunctionParser(configuration, new FunctionFactoryCache(configuration, functions));
return new Invocation(parseFunction(expression1, metadata, functionParser), parseFunction(expression2, metadata, functionParser), new TestRecord(args));
}
use of io.questdb.std.str.StringSink in project questdb by questdb.
the class SqlCompilerTest method testGeoLiteralBinLength.
@Test
public void testGeoLiteralBinLength() throws Exception {
assertMemoryLeak(() -> {
StringSink bitString = Misc.getThreadLocalBuilder();
bitString.put(Chars.repeat("0", 59)).put('1');
assertSql("select ##" + bitString + " as geobits", "geobits\n" + "000000000001\n");
});
}
use of io.questdb.std.str.StringSink in project questdb by questdb.
the class BooleanFunctionTest method testGetStr2.
@Test
public void testGetStr2() {
final StringSink sink = new StringSink();
functionA.getStr(null, sink);
TestUtils.assertEquals("false", sink);
sink.clear();
functionB.getStr(null, sink);
TestUtils.assertEquals("true", sink);
}
use of io.questdb.std.str.StringSink in project questdb by questdb.
the class CharFunctionTest method testGetStrZ2.
@Test
public void testGetStrZ2() {
StringSink sink = new StringSink();
zeroFunc.getStr(null, sink);
TestUtils.assertEquals("", sink);
}
use of io.questdb.std.str.StringSink in project questdb by questdb.
the class CharFunctionTest method testGetStr2.
@Test
public void testGetStr2() {
StringSink sink = new StringSink();
function.getStr(null, sink);
TestUtils.assertEquals("4", sink);
}
Aggregations