Search in sources :

Example 11 with TypeSignature

use of io.prestosql.spi.type.TypeSignature in project hetu-core by openlookeng.

the class AggregationUtils method generateAggregationName.

public static String generateAggregationName(String baseName, TypeSignature outputType, List<TypeSignature> inputTypes) {
    StringBuilder sb = new StringBuilder();
    sb.append(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, outputType.toString()));
    for (TypeSignature inputType : inputTypes) {
        sb.append(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, inputType.toString()));
    }
    sb.append(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, baseName.toLowerCase(ENGLISH)));
    return sb.toString();
}
Also used : TypeSignature(io.prestosql.spi.type.TypeSignature)

Example 12 with TypeSignature

use of io.prestosql.spi.type.TypeSignature in project hetu-core by openlookeng.

the class HiveTypeTranslator method limitedDepthTranslateFromHiveTypeInfo.

private static TypeSignature limitedDepthTranslateFromHiveTypeInfo(TypeInfo typeInfo, int maxDepth) {
    int nowDepth = maxDepth - 1;
    if (nowDepth <= 0) {
        throw new PrestoException(NOT_SUPPORTED, "Hive type nested structure exceed the limit");
    }
    switch(typeInfo.getCategory()) {
        case PRIMITIVE:
            Type primitiveType = translateFromHivePrimitiveTypeInfo((PrimitiveTypeInfo) typeInfo);
            if (primitiveType == null) {
                break;
            }
            return primitiveType.getTypeSignature();
        case MAP:
            MapTypeInfo mapTypeInfo = (MapTypeInfo) typeInfo;
            TypeSignature keyType = limitedDepthTranslateFromHiveTypeInfo(mapTypeInfo.getMapKeyTypeInfo(), nowDepth);
            TypeSignature valueType = limitedDepthTranslateFromHiveTypeInfo(mapTypeInfo.getMapValueTypeInfo(), nowDepth);
            return new TypeSignature(StandardTypes.MAP, ImmutableList.of(TypeSignatureParameter.of(keyType), TypeSignatureParameter.of(valueType)));
        case LIST:
            ListTypeInfo listTypeInfo = (ListTypeInfo) typeInfo;
            TypeSignature elementType = limitedDepthTranslateFromHiveTypeInfo(listTypeInfo.getListElementTypeInfo(), nowDepth);
            return new TypeSignature(StandardTypes.ARRAY, ImmutableList.of(TypeSignatureParameter.of(elementType)));
    }
    throw new PrestoException(NOT_SUPPORTED, String.format("Unsupported Hive type: %s", typeInfo));
}
Also used : DecimalType(io.prestosql.spi.type.DecimalType) Type(io.prestosql.spi.type.Type) DecimalType.createDecimalType(io.prestosql.spi.type.DecimalType.createDecimalType) CharType.createCharType(io.prestosql.spi.type.CharType.createCharType) VarcharType.createVarcharType(io.prestosql.spi.type.VarcharType.createVarcharType) VarcharType.createUnboundedVarcharType(io.prestosql.spi.type.VarcharType.createUnboundedVarcharType) CharType(io.prestosql.spi.type.CharType) VarcharType(io.prestosql.spi.type.VarcharType) TypeSignature(io.prestosql.spi.type.TypeSignature) TypeInfoFactory.getListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getListTypeInfo) ListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo) TypeInfoFactory.getMapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getMapTypeInfo) MapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo) PrestoException(io.prestosql.spi.PrestoException)

Example 13 with TypeSignature

use of io.prestosql.spi.type.TypeSignature in project hetu-core by openlookeng.

the class BuiltInTypeRegistry method addType.

public void addType(String alias, Type type) {
    requireNonNull(alias, "alias is null");
    requireNonNull(type, "type is null");
    Type existingType = types.putIfAbsent(new TypeSignature(alias), type);
    checkState(existingType == null || existingType.equals(type), "Alias %s is already mapped to %s", alias, type);
}
Also used : Re2JRegexpType(io.prestosql.type.Re2JRegexpType) DecimalType(io.prestosql.spi.type.DecimalType) ColorType(io.prestosql.type.ColorType) ParametricType(io.prestosql.spi.type.ParametricType) RowType(io.prestosql.spi.type.RowType) Type(io.prestosql.spi.type.Type) DecimalType.createDecimalType(io.prestosql.spi.type.DecimalType.createDecimalType) LikePatternType(io.prestosql.spi.type.LikePatternType) ArrayType(io.prestosql.spi.type.ArrayType) CharType.createCharType(io.prestosql.spi.type.CharType.createCharType) VarcharType.createVarcharType(io.prestosql.spi.type.VarcharType.createVarcharType) VarcharType.createUnboundedVarcharType(io.prestosql.spi.type.VarcharType.createUnboundedVarcharType) CharParametricType(io.prestosql.spi.type.CharParametricType) VarcharParametricType(io.prestosql.spi.type.VarcharParametricType) UnknownType(io.prestosql.spi.type.UnknownType) CharType(io.prestosql.spi.type.CharType) JoniRegexpType(io.prestosql.type.JoniRegexpType) CodePointsType(io.prestosql.type.CodePointsType) MapType(io.prestosql.spi.type.MapType) JsonPathType(io.prestosql.type.JsonPathType) SetDigestType(io.prestosql.type.setdigest.SetDigestType) DecimalParametricType(io.prestosql.spi.type.DecimalParametricType) VarcharType(io.prestosql.spi.type.VarcharType) TypeSignature(io.prestosql.spi.type.TypeSignature)

Example 14 with TypeSignature

use of io.prestosql.spi.type.TypeSignature in project hetu-core by openlookeng.

the class ExternalFunctionsParser method parseExternalFunction.

public static Optional<SqlInvokedFunction> parseExternalFunction(ExternalFunctionInfo externalFunctionInfo, CatalogSchemaName catalogSchemaName, RoutineCharacteristics.Language language) {
    Optional<String> functionName = externalFunctionInfo.getFunctionName();
    Optional<String> description = externalFunctionInfo.getDescription();
    List<String> inputArgs = externalFunctionInfo.getInputArgs();
    Optional<String> returnType = externalFunctionInfo.getReturnType();
    boolean deterministic = externalFunctionInfo.isDeterministic();
    boolean calledOnNullInput = externalFunctionInfo.isCalledOnNullInput();
    if (functionName.isPresent() && returnType.isPresent()) {
        QualifiedObjectName qualifiedObjectName = new QualifiedObjectName(catalogSchemaName.getCatalogName(), catalogSchemaName.getSchemaName(), functionName.get());
        List<Parameter> parameters = inputArgs.stream().map(str -> {
            checkState(SUPPORTED_TYPE.contains(str), format("external function do not supported type: %s", str));
            if (str.equals(StandardTypes.DECIMAL)) {
                return new Parameter(getRandomString((inputArgs.size() / ALPHABET.length() + 1), ALPHABET), parseTypeSignature(str + "(p, s)", ImmutableSet.of("p", "s")));
            } else if (str.equals(StandardTypes.CHAR) || str.equals(StandardTypes.VARCHAR)) {
                return new Parameter(getRandomString((inputArgs.size() / ALPHABET.length() + 1), ALPHABET), parseTypeSignature(str + "(x)", ImmutableSet.of("x")));
            } else {
                return new Parameter(getRandomString((inputArgs.size() / ALPHABET.length() + 1), ALPHABET), parseTypeSignature(str));
            }
        }).collect(toImmutableList());
        TypeSignature reType = parseTypeSignature(returnType.get());
        String deter = deterministic ? "DETERMINISTIC" : "NOT_DETERMINISTIC";
        String nullCallClause = calledOnNullInput ? "CALLED_ON_NULL_INPUT" : "RETURNS_NULL_ON_NULL_INPUT";
        RoutineCharacteristics routineCharacteristics = RoutineCharacteristics.builder().setLanguage(new RoutineCharacteristics.Language(language.getLanguage())).setDeterminism(RoutineCharacteristics.Determinism.valueOf(deter)).setNullCallClause(RoutineCharacteristics.NullCallClause.valueOf(nullCallClause)).build();
        SqlInvokedFunction sqlInvokedFunction = new SqlInvokedFunction(qualifiedObjectName, parameters, reType, description.orElse(""), routineCharacteristics, EXTERNAL_FUNCTION_BODY, ImmutableMap.of(), Optional.empty());
        return Optional.of(sqlInvokedFunction);
    }
    return Optional.empty();
}
Also used : RoutineCharacteristics(io.prestosql.spi.function.RoutineCharacteristics) ImmutableSet(com.google.common.collect.ImmutableSet) StandardTypes(io.prestosql.spi.type.StandardTypes) ImmutableMap(com.google.common.collect.ImmutableMap) Parameter(io.prestosql.spi.function.Parameter) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) ExternalFunctionInfo(io.prestosql.spi.function.ExternalFunctionInfo) SqlInvokedFunction(io.prestosql.spi.function.SqlInvokedFunction) String.format(java.lang.String.format) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) Preconditions.checkState(com.google.common.base.Preconditions.checkState) SecureRandom(java.security.SecureRandom) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) List(java.util.List) Optional(java.util.Optional) TypeSignature(io.prestosql.spi.type.TypeSignature) CatalogSchemaName(io.prestosql.spi.connector.CatalogSchemaName) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) RoutineCharacteristics(io.prestosql.spi.function.RoutineCharacteristics) SqlInvokedFunction(io.prestosql.spi.function.SqlInvokedFunction) Parameter(io.prestosql.spi.function.Parameter) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName)

Example 15 with TypeSignature

use of io.prestosql.spi.type.TypeSignature in project hetu-core by openlookeng.

the class MongoSession method guessTableFields.

private List<Document> guessTableFields(String schemaName, String tableName) {
    MongoDatabase db = client.getDatabase(schemaName);
    Document doc = db.getCollection(tableName).find().first();
    if (doc == null) {
        // no records at the collection
        return ImmutableList.of();
    }
    ImmutableList.Builder<Document> builder = ImmutableList.builder();
    for (String key : doc.keySet()) {
        Object value = doc.get(key);
        Optional<TypeSignature> fieldType = guessFieldType(value);
        if (fieldType.isPresent()) {
            Document metadata = new Document();
            metadata.append(FIELDS_NAME_KEY, key);
            metadata.append(FIELDS_TYPE_KEY, fieldType.get().toString());
            metadata.append(FIELDS_HIDDEN_KEY, key.equals("_id") && fieldType.get().equals(OBJECT_ID.getTypeSignature()));
            builder.add(metadata);
        } else {
            log.debug("Unable to guess field type from %s : %s", value == null ? "null" : value.getClass().getName(), value);
        }
    }
    return builder.build();
}
Also used : TypeSignature(io.prestosql.spi.type.TypeSignature) NamedTypeSignature(io.prestosql.spi.type.NamedTypeSignature) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) Document(org.bson.Document) MongoDatabase(com.mongodb.client.MongoDatabase)

Aggregations

TypeSignature (io.prestosql.spi.type.TypeSignature)79 Signature (io.prestosql.spi.function.Signature)36 Type (io.prestosql.spi.type.Type)27 Test (org.testng.annotations.Test)24 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)22 ImmutableList (com.google.common.collect.ImmutableList)18 BuiltInFunctionHandle (io.prestosql.spi.function.BuiltInFunctionHandle)18 CallExpression (io.prestosql.spi.relation.CallExpression)18 PrestoException (io.prestosql.spi.PrestoException)17 List (java.util.List)14 RowExpression (io.prestosql.spi.relation.RowExpression)12 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)11 RowType (io.prestosql.spi.type.RowType)11 ArrayList (java.util.ArrayList)11 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)10 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)10 ArrayType (io.prestosql.spi.type.ArrayType)10 VarcharType.createUnboundedVarcharType (io.prestosql.spi.type.VarcharType.createUnboundedVarcharType)10 HashSet (java.util.HashSet)10 Domain (io.prestosql.spi.predicate.Domain)9