Search in sources :

Example 46 with MapType

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);
}
Also used : TreeMap(java.util.TreeMap) MapType(io.trino.spi.type.MapType) TypeOperators(io.trino.spi.type.TypeOperators) Test(org.junit.jupiter.api.Test)

Example 47 with MapType

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()));
}
Also used : BlockPositionEqual(io.trino.type.BlockTypeOperators.BlockPositionEqual) Type(io.trino.spi.type.Type) MapType(io.trino.spi.type.MapType) TypeSignature.mapType(io.trino.spi.type.TypeSignature.mapType) MethodHandleAndConstructor(io.trino.sql.gen.VarArgsToArrayAdapterGenerator.MethodHandleAndConstructor) TrinoException(io.trino.spi.TrinoException) BlockPositionHashCode(io.trino.type.BlockTypeOperators.BlockPositionHashCode) MapType(io.trino.spi.type.MapType)

Example 48 with MapType

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));
}
Also used : MapType(io.trino.spi.type.MapType) MethodHandle(java.lang.invoke.MethodHandle) Reflection.constructorMethodHandle(io.trino.util.Reflection.constructorMethodHandle)

Example 49 with MapType

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);
}
Also used : MapType(io.trino.spi.type.MapType) Type(io.trino.spi.type.Type) TypeSignature.mapType(io.trino.spi.type.TypeSignature.mapType) MapType(io.trino.spi.type.MapType) MethodHandle(java.lang.invoke.MethodHandle)

Example 50 with MapType

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);
}
Also used : BlockBuilderAppender.createBlockBuilderAppender(io.trino.util.JsonUtil.BlockBuilderAppender.createBlockBuilderAppender) BlockBuilderAppender(io.trino.util.JsonUtil.BlockBuilderAppender) MapType(io.trino.spi.type.MapType) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

MapType (io.trino.spi.type.MapType)85 Type (io.trino.spi.type.Type)45 ArrayType (io.trino.spi.type.ArrayType)42 RowType (io.trino.spi.type.RowType)38 BlockBuilder (io.trino.spi.block.BlockBuilder)28 VarcharType (io.trino.spi.type.VarcharType)26 Block (io.trino.spi.block.Block)17 DecimalType (io.trino.spi.type.DecimalType)17 Map (java.util.Map)17 Test (org.testng.annotations.Test)17 ImmutableList (com.google.common.collect.ImmutableList)16 List (java.util.List)14 TypeSignature.mapType (io.trino.spi.type.TypeSignature.mapType)13 CharType (io.trino.spi.type.CharType)12 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)11 TypeOperators (io.trino.spi.type.TypeOperators)10 ImmutableMap (com.google.common.collect.ImmutableMap)9 VarbinaryType (io.trino.spi.type.VarbinaryType)8 Collectors.toList (java.util.stream.Collectors.toList)8