Search in sources :

Example 26 with TypeSignature

use of io.prestosql.spi.type.TypeSignature in project boostkit-bigdata by kunpengcompute.

the class NdpUdfExpressions method createNdpSplit.

private void createNdpSplit(StringSplit expression, PrestoExpressionInfo prestoExpressionInfo, Map<String, Integer> fieldMap) {
    String signatureName = NdpUdfEnum.SPLIT.getSignatureName();
    Type strType = NdpUtils.transOlkDataType(expression.str().dataType(), true);
    Type regexType = NdpUtils.transOlkDataType(expression.regex().dataType(), true);
    Type returnType = NdpUtils.transOlkDataType(expression.dataType(), true);
    List<RowExpression> rowArguments = new ArrayList<>();
    checkAttributeReference(expression.str(), prestoExpressionInfo, fieldMap, strType, rowArguments);
    rowArguments.add(NdpUtils.transArgumentData(expression.regex().toString(), regexType));
    Signature signature = new Signature(QualifiedObjectName.valueOfDefaultFunction(NdpUdfEnum.SPLIT.getOperatorName()), FunctionKind.SCALAR, new TypeSignature(returnType.toString()), new TypeSignature(strType.toString()), new TypeSignature(regexType.toString()));
    RowExpression resExpression = new CallExpression(signatureName, new BuiltInFunctionHandle(signature), returnType, rowArguments);
    prestoExpressionInfo.setReturnType(returnType);
    prestoExpressionInfo.setPrestoRowExpression(resExpression);
}
Also used : Type(io.prestosql.spi.type.Type) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) TypeSignature(io.prestosql.spi.type.TypeSignature) ArrayList(java.util.ArrayList) RowExpression(io.prestosql.spi.relation.RowExpression) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) CallExpression(io.prestosql.spi.relation.CallExpression)

Example 27 with TypeSignature

use of io.prestosql.spi.type.TypeSignature in project boostkit-bigdata by kunpengcompute.

the class JsonifyVisitor method visitCall.

@Override
public ObjectNode visitCall(CallExpression call, Void context) {
    ObjectNode callRoot = MAPPER.createObjectNode();
    // demangle name to get rid of OPERATOR_PREFIX
    String callName = call.getDisplayName();
    if (callName.startsWith(OPERATOR_PREFIX)) {
        callName = callName.substring(OPERATOR_PREFIX.length()).toUpperCase(Locale.ROOT);
    }
    TypeSignature callSignature = call.getType().getTypeSignature();
    DataType returnType = OperatorUtils.toDataType(call.getType());
    int typeId = returnType.getId().ordinal();
    // Binary operator in rowExpression
    if (ARITH_BIN_OPS.contains(callName) || COM_BIN_OPS.contains(callName)) {
        callRoot.put("exprType", "BINARY").put("returnType", typeId).put("operator", callName);
        if (returnType instanceof Decimal64DataType) {
            callRoot.put("precision", ((Decimal64DataType) returnType).getPrecision()).put("scale", ((Decimal64DataType) returnType).getScale());
        } else if (returnType instanceof Decimal128DataType) {
            callRoot.put("precision", ((Decimal128DataType) returnType).getPrecision()).put("scale", ((Decimal128DataType) returnType).getScale());
        }
        callRoot.set("left", call.getArguments().get(0).accept(this, context));
        callRoot.set("right", call.getArguments().get(1).accept(this, context));
    } else if (UNARY_OPS.contains(callName)) {
        // Unary operator in rowExpression
        callRoot.put("exprType", "UNARY").put("returnType", typeId).put("operator", callName).set("expr", call.getArguments().get(0).accept(this, context));
    } else {
        // Function call in rowExpression
        ArrayNode arguments = MAPPER.createArrayNode();
        // Process all arguments of this function call
        for (RowExpression argument : call.getArguments()) {
            arguments.add(argument.accept(this, context));
        }
        callRoot.put("exprType", "FUNCTION").put("returnType", typeId).put("function_name", callName).set("arguments", arguments);
        if (returnType instanceof VarcharDataType) {
            callRoot.put("width", ((VarcharDataType) returnType).getWidth());
        } else if (returnType instanceof Decimal64DataType) {
            callRoot.put("precision", ((Decimal64DataType) returnType).getPrecision()).put("scale", ((Decimal64DataType) returnType).getScale());
        } else if (returnType instanceof Decimal128DataType) {
            callRoot.put("precision", ((Decimal128DataType) returnType).getPrecision()).put("scale", ((Decimal128DataType) returnType).getScale());
        }
    }
    return callRoot;
}
Also used : Decimal64DataType(nova.hetu.omniruntime.type.Decimal64DataType) TypeSignature(io.prestosql.spi.type.TypeSignature) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) VarcharDataType(nova.hetu.omniruntime.type.VarcharDataType) DataType(nova.hetu.omniruntime.type.DataType) CharDataType(nova.hetu.omniruntime.type.CharDataType) Decimal64DataType(nova.hetu.omniruntime.type.Decimal64DataType) Decimal128DataType(nova.hetu.omniruntime.type.Decimal128DataType) RowExpression(io.prestosql.spi.relation.RowExpression) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Decimal128DataType(nova.hetu.omniruntime.type.Decimal128DataType) VarcharDataType(nova.hetu.omniruntime.type.VarcharDataType)

Example 28 with TypeSignature

use of io.prestosql.spi.type.TypeSignature in project boostkit-bigdata by kunpengcompute.

the class HiveType method getTypeSignature.

private static TypeSignature getTypeSignature(TypeInfo typeInfo) {
    switch(typeInfo.getCategory()) {
        case PRIMITIVE:
            Type primitiveType = getPrimitiveType((PrimitiveTypeInfo) typeInfo);
            if (primitiveType == null) {
                break;
            }
            return primitiveType.getTypeSignature();
        case MAP:
            MapTypeInfo mapTypeInfo = (MapTypeInfo) typeInfo;
            TypeSignature keyType = getTypeSignature(mapTypeInfo.getMapKeyTypeInfo());
            TypeSignature valueType = getTypeSignature(mapTypeInfo.getMapValueTypeInfo());
            return new TypeSignature(StandardTypes.MAP, ImmutableList.of(TypeSignatureParameter.of(keyType), TypeSignatureParameter.of(valueType)));
        case LIST:
            ListTypeInfo listTypeInfo = (ListTypeInfo) typeInfo;
            TypeSignature elementType = getTypeSignature(listTypeInfo.getListElementTypeInfo());
            return new TypeSignature(StandardTypes.ARRAY, ImmutableList.of(TypeSignatureParameter.of(elementType)));
        case STRUCT:
            StructTypeInfo structTypeInfo = (StructTypeInfo) typeInfo;
            List<TypeInfo> structFieldTypeInfos = structTypeInfo.getAllStructFieldTypeInfos();
            List<String> structFieldNames = structTypeInfo.getAllStructFieldNames();
            if (structFieldTypeInfos.size() != structFieldNames.size()) {
                throw new PrestoException(HiveErrorCode.HIVE_INVALID_METADATA, format("Invalid Hive struct type: %s", typeInfo));
            }
            ImmutableList.Builder<TypeSignatureParameter> typeSignatureBuilder = ImmutableList.builder();
            for (int i = 0; i < structFieldTypeInfos.size(); i++) {
                TypeSignature typeSignature = getTypeSignature(structFieldTypeInfos.get(i));
                // Lower case the struct field names.
                // Otherwise, Presto will refuse to write to columns whose struct type has field names containing upper case characters.
                // Users can't work around this by casting in their queries because Presto parser always lower case types.
                // TODO: This is a hack. Presto engine should be able to handle identifiers in a case insensitive way where necessary.
                String rowFieldName = structFieldNames.get(i).toLowerCase(Locale.US);
                typeSignatureBuilder.add(TypeSignatureParameter.of(new NamedTypeSignature(Optional.of(new RowFieldName(rowFieldName, false)), typeSignature)));
            }
            return new TypeSignature(StandardTypes.ROW, typeSignatureBuilder.build());
    }
    throw new PrestoException(NOT_SUPPORTED, format("Unsupported Hive type: %s", typeInfo));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) RowFieldName(io.prestosql.spi.type.RowFieldName) NamedTypeSignature(io.prestosql.spi.type.NamedTypeSignature) StructTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo) PrestoException(io.prestosql.spi.PrestoException) TypeInfoUtils.getTypeInfosFromTypeString(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils.getTypeInfosFromTypeString) TypeInfoUtils.getTypeInfoFromTypeString(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils.getTypeInfoFromTypeString) TypeInfoFactory.doubleTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.doubleTypeInfo) TypeInfoFactory.dateTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.dateTypeInfo) MapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo) StructTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) TypeInfoFactory.longTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.longTypeInfo) TypeInfoFactory.shortTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.shortTypeInfo) VarcharTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.VarcharTypeInfo) TypeInfoFactory.timestampTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.timestampTypeInfo) TypeInfoFactory.floatTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.floatTypeInfo) TypeInfoFactory.intTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.intTypeInfo) TypeInfoFactory.binaryTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.binaryTypeInfo) TypeInfoFactory.byteTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.byteTypeInfo) ListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo) TypeInfoFactory.booleanTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.booleanTypeInfo) DecimalTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) TypeInfoFactory.stringTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.stringTypeInfo) CharTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.CharTypeInfo) 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) TypeSignature(io.prestosql.spi.type.TypeSignature) NamedTypeSignature(io.prestosql.spi.type.NamedTypeSignature) TypeSignatureParameter(io.prestosql.spi.type.TypeSignatureParameter) ListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo) MapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo)

Example 29 with TypeSignature

use of io.prestosql.spi.type.TypeSignature in project boostkit-bigdata by kunpengcompute.

the class HiveProjectPushdown method tryProjectPushdown.

protected static Optional<TableScanNode> tryProjectPushdown(ProjectNode plan, Map<String, Type> types) {
    if (!(plan.getSource() instanceof TableScanNode)) {
        return Optional.empty();
    }
    TableScanNode tableScanNode = (TableScanNode) plan.getSource();
    ConnectorTableHandle tableHandle = tableScanNode.getTable().getConnectorHandle();
    if (!(tableHandle instanceof HiveTableHandle) || !(((HiveTableHandle) tableHandle).getOffloadExpression().getProjections().isEmpty())) {
        return Optional.empty();
    }
    Map<Symbol, ColumnHandle> assignments = new HashMap<>();
    HiveTypeTranslator hiveTypeTranslator = new HiveTypeTranslator();
    for (Map.Entry<Symbol, RowExpression> entry : plan.getAssignments().entrySet()) {
        String name = entry.getKey().getName();
        HiveType hiveType = HiveType.toHiveType(hiveTypeTranslator, entry.getValue().getType());
        TypeSignature typeSignature = entry.getValue().getType().getTypeSignature();
        HiveColumnHandle columnHandle = new HiveColumnHandle(name, hiveType, typeSignature, DUMMY_OFFLOADED_COLUMN_INDEX, DUMMY_OFFLOADED, Optional.of("projections pushed down " + name));
        assignments.put(entry.getKey(), columnHandle);
    }
    BiMap<VariableReferenceExpression, VariableReferenceExpression> variableToColumnMapping = tableScanNode.getAssignments().entrySet().stream().collect(toImmutableBiMap(entry -> new VariableReferenceExpression(entry.getKey().getName(), types.get(entry.getKey().getName())), entry -> new VariableReferenceExpression(entry.getValue().getColumnName(), types.get(entry.getKey().getName()))));
    ImmutableMap.Builder<Symbol, RowExpression> projections = new ImmutableMap.Builder<>();
    for (Map.Entry<Symbol, RowExpression> entry : plan.getAssignments().getMap().entrySet()) {
        RowExpression expression = replaceExpression(entry.getValue(), variableToColumnMapping);
        if (!OmniExpressionChecker.checkExpression(expression)) {
            return Optional.empty();
        }
        projections.put(entry.getKey(), expression);
    }
    HiveTableHandle hiveTableHandle = (HiveTableHandle) tableHandle;
    HiveOffloadExpression offloadExpression = hiveTableHandle.getOffloadExpression().updateProjections(projections.build(), getDataSourceColumns(tableScanNode));
    HiveTableHandle newHiveTableHandle = hiveTableHandle.withOffloadExpression(offloadExpression);
    TableHandle newTableHandle = new TableHandle(tableScanNode.getTable().getCatalogName(), newHiveTableHandle, tableScanNode.getTable().getTransaction(), tableScanNode.getTable().getLayout());
    return Optional.of(new TableScanNode(tableScanNode.getId(), newTableHandle, ImmutableList.copyOf(assignments.keySet()), assignments, tableScanNode.getEnforcedConstraint(), tableScanNode.getPredicate(), tableScanNode.getStrategy(), tableScanNode.getReuseTableScanMappingId(), tableScanNode.getConsumerTableScanNodeCount(), tableScanNode.isForDelete()));
}
Also used : HiveTableHandle(io.prestosql.plugin.hive.HiveTableHandle) HivePushdownUtil.getDataSourceColumns(io.prestosql.plugin.hive.rule.HivePushdownUtil.getDataSourceColumns) HiveTypeTranslator(io.prestosql.plugin.hive.HiveTypeTranslator) HashMap(java.util.HashMap) HiveColumnHandle(io.prestosql.plugin.hive.HiveColumnHandle) TableHandle(io.prestosql.spi.metadata.TableHandle) ImmutableList(com.google.common.collect.ImmutableList) OmniExpressionChecker(com.huawei.boostkit.omnidata.expression.OmniExpressionChecker) Map(java.util.Map) Type(io.prestosql.spi.type.Type) RowExpressionNodeInliner.replaceExpression(io.prestosql.expressions.RowExpressionNodeInliner.replaceExpression) Symbol(io.prestosql.spi.plan.Symbol) BiMap(com.google.common.collect.BiMap) DUMMY_OFFLOADED_COLUMN_INDEX(io.prestosql.plugin.hive.HiveColumnHandle.DUMMY_OFFLOADED_COLUMN_INDEX) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) TableScanNode(io.prestosql.spi.plan.TableScanNode) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) HiveType(io.prestosql.plugin.hive.HiveType) ProjectNode(io.prestosql.spi.plan.ProjectNode) HiveOffloadExpression(io.prestosql.plugin.hive.HiveOffloadExpression) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) DUMMY_OFFLOADED(io.prestosql.plugin.hive.HiveColumnHandle.ColumnType.DUMMY_OFFLOADED) RowExpression(io.prestosql.spi.relation.RowExpression) Optional(java.util.Optional) ImmutableBiMap.toImmutableBiMap(com.google.common.collect.ImmutableBiMap.toImmutableBiMap) TypeSignature(io.prestosql.spi.type.TypeSignature) HiveColumnHandle(io.prestosql.plugin.hive.HiveColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) HashMap(java.util.HashMap) Symbol(io.prestosql.spi.plan.Symbol) RowExpression(io.prestosql.spi.relation.RowExpression) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) TypeSignature(io.prestosql.spi.type.TypeSignature) HiveTableHandle(io.prestosql.plugin.hive.HiveTableHandle) HiveTypeTranslator(io.prestosql.plugin.hive.HiveTypeTranslator) TableScanNode(io.prestosql.spi.plan.TableScanNode) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) HiveOffloadExpression(io.prestosql.plugin.hive.HiveOffloadExpression) HiveTableHandle(io.prestosql.plugin.hive.HiveTableHandle) TableHandle(io.prestosql.spi.metadata.TableHandle) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) HiveType(io.prestosql.plugin.hive.HiveType) HashMap(java.util.HashMap) Map(java.util.Map) BiMap(com.google.common.collect.BiMap) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableBiMap.toImmutableBiMap(com.google.common.collect.ImmutableBiMap.toImmutableBiMap) HiveColumnHandle(io.prestosql.plugin.hive.HiveColumnHandle)

Example 30 with TypeSignature

use of io.prestosql.spi.type.TypeSignature in project boostkit-bigdata by kunpengcompute.

the class TestHivePageSourceProvider method testModifyDomainGreaterThanOrEqual.

@Test
public void testModifyDomainGreaterThanOrEqual() {
    Collection<Object> valueSet = new HashSet<>();
    valueSet.add(Long.valueOf(40));
    VariableReferenceExpression argument1 = new VariableReferenceExpression("arg_1", BIGINT);
    VariableReferenceExpression argument2 = new VariableReferenceExpression("arg_2", BIGINT);
    QualifiedObjectName objectName = new QualifiedObjectName("presto", "default", "$operator$greater_than_or_equal");
    BuiltInFunctionHandle functionHandle = new BuiltInFunctionHandle(new Signature(objectName, FunctionKind.SCALAR, ImmutableList.of(), ImmutableList.of(), new TypeSignature("boolean"), ImmutableList.of(new TypeSignature("bigint"), new TypeSignature("bigint")), false));
    CallExpression filter = new CallExpression("GREATER_THAN_OR_EQUAL", functionHandle, BOOLEAN, ImmutableList.of(argument1, argument2));
    Domain domain = Domain.create(ValueSet.copyOf(BIGINT, valueSet), false);
    domain = modifyDomain(domain, Optional.of(filter));
    assertEquals(domain.getValues().getRanges().getSpan().getHigh().getValueBlock(), Optional.empty());
    assertEquals(domain.getValues().getRanges().getSpan().getLow().getValue(), Long.valueOf(40));
}
Also used : TypeSignature(io.prestosql.spi.type.TypeSignature) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature(io.prestosql.spi.function.Signature) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) HivePageSourceProvider.modifyDomain(io.prestosql.plugin.hive.HivePageSourceProvider.modifyDomain) Domain(io.prestosql.spi.predicate.Domain) CallExpression(io.prestosql.spi.relation.CallExpression) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

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