use of io.trino.spi.type.MapType in project yauaa by nielsbasjes.
the class TestParseFunction method testParser.
@Test
void testParser() {
TreeMap<String, String> expected = new TreeMap<>();
expected.put("DeviceClass", "Desktop");
expected.put("DeviceName", "Linux Desktop");
expected.put("DeviceBrand", "Unknown");
expected.put("DeviceCpu", "Intel x86_64");
expected.put("DeviceCpuBits", "64");
expected.put("DeviceFirmwareVersion", "??");
expected.put("DeviceVersion", "??");
expected.put("OperatingSystemClass", "Desktop");
expected.put("OperatingSystemName", "Linux");
expected.put("OperatingSystemVersion", "??");
expected.put("OperatingSystemVersionMajor", "??");
expected.put("OperatingSystemNameVersion", "Linux ??");
expected.put("OperatingSystemNameVersionMajor", "Linux ??");
expected.put("OperatingSystemVersionBuild", "??");
expected.put("LayoutEngineClass", "Browser");
expected.put("LayoutEngineName", "Blink");
expected.put("LayoutEngineVersion", "98.0");
expected.put("LayoutEngineVersionMajor", "98");
expected.put("LayoutEngineNameVersion", "Blink 98.0");
expected.put("LayoutEngineNameVersionMajor", "Blink 98");
expected.put("LayoutEngineBuild", "Unknown");
expected.put("AgentClass", "Browser");
expected.put("AgentName", "Chrome");
expected.put("AgentVersion", "98.0.4758.102");
expected.put("AgentVersionMajor", "98");
expected.put("AgentNameVersion", "Chrome 98.0.4758.102");
expected.put("AgentNameVersionMajor", "Chrome 98");
expected.put("AgentBuild", "Unknown");
expected.put("AgentLanguage", "Unknown");
expected.put("AgentLanguageCode", "Unknown");
expected.put("AgentInformationEmail", "Unknown");
expected.put("AgentInformationUrl", "Unknown");
expected.put("AgentSecurity", "Unknown");
expected.put("AgentUuid", "Unknown");
expected.put("WebviewAppName", "Unknown");
expected.put("WebviewAppVersion", "??");
expected.put("WebviewAppVersionMajor", "??");
expected.put("WebviewAppNameVersion", "Unknown ??");
expected.put("WebviewAppNameVersionMajor", "Unknown ??");
expected.put("FacebookCarrier", "Unknown");
expected.put("FacebookDeviceClass", "Unknown");
expected.put("FacebookDeviceName", "Unknown");
expected.put("FacebookDeviceVersion", "??");
expected.put("FacebookFBOP", "Unknown");
expected.put("FacebookFBSS", "Unknown");
expected.put("FacebookOperatingSystemName", "Unknown");
expected.put("FacebookOperatingSystemVersion", "??");
expected.put("Anonymized", "Unknown");
expected.put("HackerAttackVector", "Unknown");
expected.put("HackerToolkit", "Unknown");
expected.put("KoboAffiliate", "Unknown");
expected.put("KoboPlatformId", "Unknown");
expected.put("IECompatibilityVersion", "??");
expected.put("IECompatibilityVersionMajor", "??");
expected.put("IECompatibilityNameVersion", "Unknown ??");
expected.put("IECompatibilityNameVersionMajor", "Unknown ??");
expected.put("__SyntaxError__", "false");
expected.put("Carrier", "Unknown");
expected.put("GSAInstallationID", "Unknown");
expected.put("NetworkType", "Unknown");
assertFunction("parse_user_agent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36')", new MapType(VARCHAR, VARCHAR, new TypeOperators()), expected);
}
use of io.trino.spi.type.MapType in project trino by trinodb.
the class MapConcatFunction method specialize.
@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature) {
if (boundSignature.getArity() < 2) {
throw new TrinoException(INVALID_FUNCTION_ARGUMENT, "There must be two or more concatenation arguments to " + FUNCTION_NAME);
}
MapType mapType = (MapType) boundSignature.getReturnType();
Type keyType = mapType.getKeyType();
BlockPositionEqual keyEqual = blockTypeOperators.getEqualOperator(keyType);
BlockPositionHashCode keyHashCode = blockTypeOperators.getHashCodeOperator(keyType);
MethodHandleAndConstructor methodHandleAndConstructor = generateVarArgsToArrayAdapter(Block.class, Block.class, boundSignature.getArity(), MethodHandles.insertArguments(METHOD_HANDLE, 0, mapType, keyEqual, keyHashCode), USER_STATE_FACTORY.bindTo(mapType));
return new ChoicesScalarFunctionImplementation(boundSignature, FAIL_ON_NULL, nCopies(boundSignature.getArity(), NEVER_NULL), methodHandleAndConstructor.getMethodHandle(), Optional.of(methodHandleAndConstructor.getConstructor()));
}
use of io.trino.spi.type.MapType in project trino by trinodb.
the class MapConstructor method specialize.
@Override
public ScalarFunctionImplementation specialize(BoundSignature boundSignature, FunctionDependencies functionDependencies) {
MapType mapType = (MapType) boundSignature.getReturnType();
MethodHandle keyIndeterminate = functionDependencies.getOperatorInvoker(INDETERMINATE, ImmutableList.of(mapType.getKeyType()), simpleConvention(FAIL_ON_NULL, NEVER_NULL)).getMethodHandle();
MethodHandle instanceFactory = constructorMethodHandle(State.class, MapType.class).bindTo(mapType);
return new ChoicesScalarFunctionImplementation(boundSignature, FAIL_ON_NULL, ImmutableList.of(NEVER_NULL, NEVER_NULL), METHOD_HANDLE.bindTo(mapType).bindTo(keyIndeterminate), Optional.of(instanceFactory));
}
use of io.trino.spi.type.MapType in project trino by trinodb.
the class MapElementAtFunction method specialize.
@Override
public ScalarFunctionImplementation specialize(BoundSignature boundSignature, FunctionDependencies functionDependencies) {
MapType mapType = (MapType) boundSignature.getArgumentType(0);
Type keyType = mapType.getKeyType();
Type valueType = mapType.getValueType();
MethodHandle methodHandle;
if (keyType.getJavaType() == boolean.class) {
methodHandle = METHOD_HANDLE_BOOLEAN;
} else if (keyType.getJavaType() == long.class) {
methodHandle = METHOD_HANDLE_LONG;
} else if (keyType.getJavaType() == double.class) {
methodHandle = METHOD_HANDLE_DOUBLE;
} else {
methodHandle = METHOD_HANDLE_OBJECT;
}
methodHandle = methodHandle.bindTo(valueType);
methodHandle = methodHandle.asType(methodHandle.type().changeReturnType(Primitives.wrap(valueType.getJavaType())));
return new ChoicesScalarFunctionImplementation(boundSignature, NULLABLE_RETURN, ImmutableList.of(NEVER_NULL, NEVER_NULL), methodHandle);
}
use of io.trino.spi.type.MapType in project trino by trinodb.
the class JsonToMapCast method specialize.
@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature) {
checkArgument(boundSignature.getArity() == 1, "Expected arity to be 1");
MapType mapType = (MapType) boundSignature.getReturnType();
checkCondition(canCastFromJson(mapType), INVALID_CAST_ARGUMENT, "Cannot cast JSON to %s", mapType);
BlockBuilderAppender mapAppender = createBlockBuilderAppender(mapType);
MethodHandle methodHandle = METHOD_HANDLE.bindTo(mapType).bindTo(mapAppender);
return new ChoicesScalarFunctionImplementation(boundSignature, NULLABLE_RETURN, ImmutableList.of(NEVER_NULL), methodHandle);
}
Aggregations