Search in sources :

Example 16 with OperatorType

use of io.prestosql.spi.function.OperatorType in project hetu-core by openlookeng.

the class RowComparisonOperator method getMethodHandles.

protected List<MethodHandle> getMethodHandles(RowType type, FunctionAndTypeManager functionAndTypeManager, OperatorType operatorType) {
    ImmutableList.Builder<MethodHandle> argumentMethods = ImmutableList.builder();
    for (Type parameterType : type.getTypeParameters()) {
        FunctionHandle operatorHandle = functionAndTypeManager.resolveOperatorFunctionHandle(operatorType, TypeSignatureProvider.fromTypes(parameterType, parameterType));
        argumentMethods.add(functionAndTypeManager.getBuiltInScalarFunctionImplementation(operatorHandle).getMethodHandle());
    }
    return argumentMethods.build();
}
Also used : OperatorType(io.prestosql.spi.function.OperatorType) RowType(io.prestosql.spi.type.RowType) Type(io.prestosql.spi.type.Type) ImmutableList(com.google.common.collect.ImmutableList) FunctionHandle(io.prestosql.spi.function.FunctionHandle) MethodHandle(java.lang.invoke.MethodHandle)

Example 17 with OperatorType

use of io.prestosql.spi.function.OperatorType in project hetu-core by openlookeng.

the class ClickHouseRowExpressionConverter method handleOperatorFunction.

private String handleOperatorFunction(CallExpression call, FunctionMetadata functionMetadata, JdbcConverterContext context) {
    Optional<OperatorType> operatorTypeOptional = functionMetadata.getOperatorType();
    OperatorType type = operatorTypeOptional.get();
    if (type.equals(OperatorType.CAST)) {
        return handleCastOperator(call.getArguments().get(0), call.getType(), context);
    }
    List<String> argumentList = call.getArguments().stream().map(expr -> expr.accept(this, context)).collect(Collectors.toList());
    if (type.isArithmeticOperator()) {
        return format("(%s %s %s)", argumentList.get(0), type.getOperator(), argumentList.get(1));
    }
    if (type.isComparisonOperator()) {
        final String[] clickHouseCompareOperators = new String[] { "=", ">", "<", ">=", "<=", "!=", "<>" };
        if (Arrays.asList(clickHouseCompareOperators).contains(type.getOperator())) {
            return format("(%s %s %s)", argumentList.get(0), type.getOperator(), argumentList.get(1));
        } else {
            String exceptionInfo = "ClickHouse Connector does not support comparison operator " + type.getOperator();
            throw new PrestoException(NOT_SUPPORTED, exceptionInfo);
        }
    }
    if (type.equals(OperatorType.SUBSCRIPT)) {
        throw new PrestoException(NOT_SUPPORTED, "ClickHouse Connector does not support subscript now");
    }
    /*
         * "Negative" needs to be tested
         */
    if (call.getArguments().size() == 1 && type.equals(OperatorType.NEGATION)) {
        String value = argumentList.get(0);
        String separator = value.startsWith("-") ? " " : "";
        return format("-%s%s", separator, value);
    }
    throw new PrestoException(NOT_SUPPORTED, String.format("Unknown operator %s in push down", type.getOperator()));
}
Also used : FunctionWriterManager(io.prestosql.sql.builder.functioncall.FunctionWriterManager) Arrays(java.util.Arrays) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) JdbcConverterContext(io.prestosql.plugin.jdbc.optimization.JdbcConverterContext) HashMap(java.util.HashMap) DateParseFunctionCallRewriter(io.hetu.core.plugin.clickhouse.rewrite.functioncall.DateParseFunctionCallRewriter) StandardFunctionResolution(io.prestosql.spi.function.StandardFunctionResolution) DeterminismEvaluator(io.prestosql.spi.relation.DeterminismEvaluator) BaseFunctionUtil.isDefaultFunction(io.prestosql.sql.builder.functioncall.BaseFunctionUtil.isDefaultFunction) CallExpression(io.prestosql.spi.relation.CallExpression) ClickHouseConstants(io.hetu.core.plugin.clickhouse.ClickHouseConstants) ConfigSupplier(io.prestosql.configmanager.ConfigSupplier) OperatorType(io.prestosql.spi.function.OperatorType) Map(java.util.Map) FunctionMetadataManager(io.prestosql.spi.function.FunctionMetadataManager) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) FunctionMetadata(io.prestosql.spi.function.FunctionMetadata) UdfFunctionRewriteConstants(io.hetu.core.plugin.clickhouse.rewrite.UdfFunctionRewriteConstants) Type(io.prestosql.spi.type.Type) FromBase64CallRewriter(io.prestosql.sql.builder.functioncall.functions.base.FromBase64CallRewriter) SpecialForm(io.prestosql.spi.relation.SpecialForm) ENGLISH(java.util.Locale.ENGLISH) DefaultConnectorConfigFunctionRewriter(io.prestosql.sql.builder.functioncall.functions.config.DefaultConnectorConfigFunctionRewriter) PrestoException(io.prestosql.spi.PrestoException) BaseJdbcConfig(io.prestosql.plugin.jdbc.BaseJdbcConfig) Set(java.util.Set) FunctionCallRewriter(io.prestosql.sql.builder.functioncall.functions.FunctionCallRewriter) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) FunctionHandle(io.prestosql.spi.function.FunctionHandle) ClickHouseUnsupportedFunctionCallRewriter(io.hetu.core.plugin.clickhouse.rewrite.ClickHouseUnsupportedFunctionCallRewriter) RowExpressionService(io.prestosql.spi.relation.RowExpressionService) List(java.util.List) BaseJdbcRowExpressionConverter(io.prestosql.plugin.jdbc.optimization.BaseJdbcRowExpressionConverter) Stream(java.util.stream.Stream) FunctionWriterManagerGroup(io.prestosql.sql.builder.functioncall.FunctionWriterManagerGroup) QualifiedName(io.prestosql.spi.sql.expression.QualifiedName) RowExpression(io.prestosql.spi.relation.RowExpression) Optional(java.util.Optional) NOT_SUPPORTED(io.prestosql.spi.StandardErrorCode.NOT_SUPPORTED) DefaultUdfRewriteConfigSupplier(io.prestosql.configmanager.DefaultUdfRewriteConfigSupplier) BuildInDirectMapFunctionCallRewriter(io.hetu.core.plugin.clickhouse.rewrite.BuildInDirectMapFunctionCallRewriter) ClickHouseConfig(io.hetu.core.plugin.clickhouse.ClickHouseConfig) Collections(java.util.Collections) VarcharType(io.prestosql.spi.type.VarcharType) Joiner(com.google.common.base.Joiner) PrestoException(io.prestosql.spi.PrestoException) OperatorType(io.prestosql.spi.function.OperatorType)

Example 18 with OperatorType

use of io.prestosql.spi.function.OperatorType in project hetu-core by openlookeng.

the class FunctionsParserHelper method createTypeVariableConstraints.

public static List<TypeVariableConstraint> createTypeVariableConstraints(Iterable<TypeParameter> typeParameters, List<ImplementationDependency> dependencies) {
    Set<String> orderableRequired = new HashSet<>();
    Set<String> comparableRequired = new HashSet<>();
    for (ImplementationDependency dependency : dependencies) {
        if (dependency instanceof OperatorImplementationDependency) {
            OperatorType operator = ((OperatorImplementationDependency) dependency).getOperator();
            if (operator == CAST) {
                continue;
            }
            Set<String> argumentTypes = ((OperatorImplementationDependency) dependency).getArgumentTypes().stream().map(TypeSignature::getBase).collect(toImmutableSet());
            checkArgument(argumentTypes.size() == 1, "Operator dependency must only have arguments of a single type");
            String argumentType = Iterables.getOnlyElement(argumentTypes);
            if (COMPARABLE_TYPE_OPERATORS.contains(operator)) {
                comparableRequired.add(argumentType);
            }
            if (ORDERABLE_TYPE_OPERATORS.contains(operator)) {
                orderableRequired.add(argumentType);
            }
        }
    }
    ImmutableList.Builder<TypeVariableConstraint> typeVariableConstraints = ImmutableList.builder();
    for (TypeParameter typeParameter : typeParameters) {
        String name = typeParameter.value();
        if (orderableRequired.contains(name)) {
            typeVariableConstraints.add(orderableTypeParameter(name));
        } else if (comparableRequired.contains(name)) {
            typeVariableConstraints.add(comparableTypeParameter(name));
        } else {
            typeVariableConstraints.add(typeVariable(name));
        }
    }
    return typeVariableConstraints.build();
}
Also used : Signature.orderableTypeParameter(io.prestosql.spi.function.Signature.orderableTypeParameter) Signature.comparableTypeParameter(io.prestosql.spi.function.Signature.comparableTypeParameter) TypeParameter(io.prestosql.spi.function.TypeParameter) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) OperatorType(io.prestosql.spi.function.OperatorType) TypeVariableConstraint(io.prestosql.spi.function.TypeVariableConstraint) HashSet(java.util.HashSet)

Example 19 with OperatorType

use of io.prestosql.spi.function.OperatorType in project hetu-core by openlookeng.

the class TestFunctionAndTypeManager method testOperatorTypes.

@Test
public void testOperatorTypes() {
    FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
    FunctionResolution functionResolution = new FunctionResolution(functionAndTypeManager);
    assertTrue(functionAndTypeManager.getFunctionMetadata(functionResolution.arithmeticFunction(ADD, BIGINT, BIGINT)).getOperatorType().map(OperatorType::isArithmeticOperator).orElse(false));
    assertFalse(functionAndTypeManager.getFunctionMetadata(functionResolution.arithmeticFunction(ADD, BIGINT, BIGINT)).getOperatorType().map(OperatorType::isComparisonOperator).orElse(true));
    assertTrue(functionAndTypeManager.getFunctionMetadata(functionResolution.comparisonFunction(GREATER_THAN, BIGINT, BIGINT)).getOperatorType().map(OperatorType::isComparisonOperator).orElse(false));
    assertFalse(functionAndTypeManager.getFunctionMetadata(functionResolution.comparisonFunction(GREATER_THAN, BIGINT, BIGINT)).getOperatorType().map(OperatorType::isArithmeticOperator).orElse(true));
    assertFalse(functionAndTypeManager.getFunctionMetadata(functionResolution.notFunction()).getOperatorType().isPresent());
}
Also used : FunctionAndTypeManager.createTestFunctionAndTypeManager(io.prestosql.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) OperatorType(io.prestosql.spi.function.OperatorType) OperatorType.tryGetOperatorType(io.prestosql.spi.function.OperatorType.tryGetOperatorType) Test(org.testng.annotations.Test)

Example 20 with OperatorType

use of io.prestosql.spi.function.OperatorType in project hetu-core by openlookeng.

the class TestFunctionAndTypeManager method testExactMatchBeforeCoercion.

@Test
public void testExactMatchBeforeCoercion() {
    FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
    boolean foundOperator = false;
    for (SqlFunction function : functionAndTypeManager.listOperators()) {
        OperatorType operatorType = tryGetOperatorType(function.getSignature().getName()).get();
        if (operatorType == CAST || operatorType == SATURATED_FLOOR_CAST) {
            continue;
        }
        if (!function.getSignature().getTypeVariableConstraints().isEmpty()) {
            continue;
        }
        if (function.getSignature().getArgumentTypes().stream().anyMatch(TypeSignature::isCalculated)) {
            continue;
        }
        BuiltInFunctionHandle exactOperator = (BuiltInFunctionHandle) functionAndTypeManager.resolveOperatorFunctionHandle(operatorType, fromTypeSignatures(function.getSignature().getArgumentTypes()));
        assertEquals(exactOperator.getSignature(), function.getSignature());
        foundOperator = true;
    }
    assertTrue(foundOperator);
}
Also used : TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) TypeSignature(io.prestosql.spi.type.TypeSignature) FunctionAndTypeManager.createTestFunctionAndTypeManager(io.prestosql.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) OperatorType(io.prestosql.spi.function.OperatorType) OperatorType.tryGetOperatorType(io.prestosql.spi.function.OperatorType.tryGetOperatorType) SqlFunction(io.prestosql.spi.function.SqlFunction) Test(org.testng.annotations.Test)

Aggregations

OperatorType (io.prestosql.spi.function.OperatorType)28 CallExpression (io.prestosql.spi.relation.CallExpression)11 PrestoException (io.prestosql.spi.PrestoException)10 Signature (io.prestosql.spi.function.Signature)9 ImmutableList (com.google.common.collect.ImmutableList)8 FunctionMetadata (io.prestosql.spi.function.FunctionMetadata)8 TypeSignature (io.prestosql.spi.type.TypeSignature)8 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)8 List (java.util.List)8 BuiltInFunctionHandle (io.prestosql.spi.function.BuiltInFunctionHandle)7 RowExpression (io.prestosql.spi.relation.RowExpression)7 FunctionHandle (io.prestosql.spi.function.FunctionHandle)6 Slice (io.airlift.slice.Slice)5 SqlType (io.prestosql.spi.function.SqlType)5 SpecialForm (io.prestosql.spi.relation.SpecialForm)5 Type (io.prestosql.spi.type.Type)5 Objects.requireNonNull (java.util.Objects.requireNonNull)5 ImmutableSet (com.google.common.collect.ImmutableSet)4 SqlScalarFunction (io.prestosql.metadata.SqlScalarFunction)4 UsedByGeneratedCode (io.prestosql.spi.annotation.UsedByGeneratedCode)4