use of io.questdb.std.str.StringSink in project questdb by bluestreak01.
the class GeoHashesTest method testFromString.
@Test(expected = NumericException.class)
public void testFromString() throws NumericException {
StringSink sink = Misc.getThreadLocalBuilder();
sink.put("@s");
GeoHashes.fromString(sink.toString(), 0, 2);
}
use of io.questdb.std.str.StringSink in project questdb by bluestreak01.
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 bluestreak01.
the class StrBindVariableTest method testSimple.
@Test
public void testSimple() {
String expected = "xyz";
StrBindVariable variable = new StrBindVariable(Numbers.MAX_SCALE);
variable.setValue(expected);
TestUtils.assertEquals(expected, variable.getStr(null));
TestUtils.assertEquals(expected, variable.getStrB(null));
Assert.assertEquals(expected.length(), variable.getStrLen(null));
StringSink sink = new StringSink();
variable.getStr(null, sink);
TestUtils.assertEquals(expected, sink);
}
use of io.questdb.std.str.StringSink in project questdb by bluestreak01.
the class BindVariableServiceImplTest method testNamedSetLong256ToLong256NoDefine.
@Test
public void testNamedSetLong256ToLong256NoDefine() throws SqlException {
bindVariableService.setLong256("x", 888, 777, 6666, 5555);
StringSink sink = new StringSink();
bindVariableService.getFunction(":x").getLong256(null, sink);
TestUtils.assertEquals("0x15b30000000000001a0a00000000000003090000000000000378", sink);
}
use of io.questdb.std.str.StringSink in project questdb by bluestreak01.
the class BindVariableServiceImplTest method testSetLong256ToLong256.
@Test
public void testSetLong256ToLong256() throws SqlException {
bindVariableService.define(0, ColumnType.LONG256, 0);
bindVariableService.setLong256(0, 888, 777, 6666, 5555);
StringSink sink = new StringSink();
bindVariableService.getFunction(0).getLong256(null, sink);
TestUtils.assertEquals("0x15b30000000000001a0a00000000000003090000000000000378", sink);
}
Aggregations