Search in sources :

Example 11 with Type

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

the class MySqlRowExpressionConverter method visitCall.

@Override
public String visitCall(CallExpression call, JdbcConverterContext context) {
    // remote udf verify
    FunctionHandle functionHandle = call.getFunctionHandle();
    if (!isDefaultFunction(call)) {
        Optional<String> result = mySqlApplyRemoteFunctionPushDown.rewriteRemoteFunction(call, this, context);
        if (result.isPresent()) {
            return result.get();
        }
        throw new PrestoException(NOT_SUPPORTED, String.format("MySql connector does not support remote function: %s.%s", call.getDisplayName(), call.getFunctionHandle().getFunctionNamespace()));
    }
    if (standardFunctionResolution.isArrayConstructor(functionHandle)) {
        throw new PrestoException(NOT_SUPPORTED, "MySql connector does not support array constructor");
    }
    if (standardFunctionResolution.isSubscriptFunction(functionHandle)) {
        throw new PrestoException(NOT_SUPPORTED, "MySql connector does not support subscript expression");
    }
    if (standardFunctionResolution.isCastFunction(functionHandle)) {
        // deal with literal, when generic literal expression translate to rowExpression, it will be
        // translated to a 'CAST' rowExpression with a varchar type 'CONSTANT' rowExpression, in some
        // case, 'CAST' is superfluous
        RowExpression argument = call.getArguments().get(0);
        Type type = call.getType();
        if (argument instanceof ConstantExpression && argument.getType().equals(VARCHAR)) {
            String value = argument.accept(this, context);
            if (type instanceof VarcharType || type instanceof CharType || type instanceof VarbinaryType || type instanceof DecimalType || type instanceof RealType || type instanceof DoubleType) {
                return value;
            }
        }
        if (call.getType().getDisplayName().equals(LIKE_PATTERN_NAME)) {
            return call.getArguments().get(0).accept(this, context);
        }
        return getCastExpression(call.getArguments().get(0).accept(this, context), call.getType());
    }
    return super.visitCall(call, context);
}
Also used : VarcharType(io.prestosql.spi.type.VarcharType) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) RowExpression(io.prestosql.spi.relation.RowExpression) PrestoException(io.prestosql.spi.PrestoException) RealType(io.prestosql.spi.type.RealType) CharType(io.prestosql.spi.type.CharType) DecimalType(io.prestosql.spi.type.DecimalType) DoubleType(io.prestosql.spi.type.DoubleType) Type(io.prestosql.spi.type.Type) RealType(io.prestosql.spi.type.RealType) VarbinaryType(io.prestosql.spi.type.VarbinaryType) VarcharType(io.prestosql.spi.type.VarcharType) VarbinaryType(io.prestosql.spi.type.VarbinaryType) DoubleType(io.prestosql.spi.type.DoubleType) DecimalType(io.prestosql.spi.type.DecimalType) CharType(io.prestosql.spi.type.CharType) FunctionHandle(io.prestosql.spi.function.FunctionHandle)

Example 12 with Type

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

the class TestLearnAggregations method testLearnLibSvm.

@Test
public void testLearnLibSvm() {
    Type mapType = METADATA.getFunctionAndTypeManager().getParameterizedType("map", ImmutableList.of(TypeSignatureParameter.of(parseTypeSignature(StandardTypes.BIGINT)), TypeSignatureParameter.of(parseTypeSignature(StandardTypes.DOUBLE))));
    InternalAggregationFunction aggregation = parseFunctionDefinitionWithTypesConstraint(LearnLibSvmClassifierAggregation.class, BIGINT_CLASSIFIER.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature(), mapType.getTypeSignature(), VarcharType.getParametrizedVarcharSignature("x"))).specialize(BoundVariables.builder().setLongVariable("x", (long) Integer.MAX_VALUE).build(), 3, METADATA.getFunctionAndTypeManager());
    assertLearnClassifer(aggregation.bind(ImmutableList.of(0, 1, 2), Optional.empty()).createAccumulator());
}
Also used : RegressorType(io.prestosql.plugin.ml.type.RegressorType) ModelType(io.prestosql.plugin.ml.type.ModelType) Type(io.prestosql.spi.type.Type) ClassifierParametricType(io.prestosql.plugin.ml.type.ClassifierParametricType) VarcharType(io.prestosql.spi.type.VarcharType) InternalAggregationFunction(io.prestosql.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Example 13 with Type

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

the class TestLearnAggregations method getPage.

private static Page getPage() {
    Type mapType = METADATA.getFunctionAndTypeManager().getParameterizedType("map", ImmutableList.of(TypeSignatureParameter.of(parseTypeSignature(StandardTypes.BIGINT)), TypeSignatureParameter.of(parseTypeSignature(StandardTypes.DOUBLE))));
    int datapoints = 100;
    RowPageBuilder builder = RowPageBuilder.rowPageBuilder(BIGINT, mapType, VarcharType.VARCHAR);
    Random rand = new Random(0);
    for (int i = 0; i < datapoints; i++) {
        long label = rand.nextDouble() < 0.5 ? 0 : 1;
        builder.row(label, mapBlockOf(BIGINT, DOUBLE, 0L, label + rand.nextGaussian()), "C=1");
    }
    return builder.build();
}
Also used : RegressorType(io.prestosql.plugin.ml.type.RegressorType) ModelType(io.prestosql.plugin.ml.type.ModelType) Type(io.prestosql.spi.type.Type) ClassifierParametricType(io.prestosql.plugin.ml.type.ClassifierParametricType) VarcharType(io.prestosql.spi.type.VarcharType) Random(java.util.Random) RowPageBuilder(io.prestosql.RowPageBuilder) AggregationFromAnnotationsParser.parseFunctionDefinitionWithTypesConstraint(io.prestosql.operator.aggregation.AggregationFromAnnotationsParser.parseFunctionDefinitionWithTypesConstraint)

Example 14 with Type

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

the class TupleDomain method fromFixedValues.

/**
 * Convert a map of columns to values into the TupleDomain which requires
 * those columns to be fixed to those values. Null is allowed as a fixed value.
 */
public static <T> TupleDomain<T> fromFixedValues(Map<T, NullableValue> fixedValues) {
    return TupleDomain.withColumnDomains(fixedValues.entrySet().stream().collect(toLinkedMap(Map.Entry::getKey, entry -> {
        Type type = entry.getValue().getType();
        Object value = entry.getValue().getValue();
        return value == null ? Domain.onlyNull(type) : Domain.singleValue(type, value);
    })));
}
Also used : Type(io.prestosql.spi.type.Type)

Example 15 with Type

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

the class TestPushPredicateIntoTableScan method ruleWithPushdownableToTableLayoutPredicate.

@Test
public void ruleWithPushdownableToTableLayoutPredicate() {
    Type orderStatusType = createVarcharType(1);
    tester().assertThat(pushPredicateIntoTableScan).on(p -> {
        p.symbol("orderstatus", orderStatusType);
        return p.filter(p.rowExpression("orderstatus = 'O'"), p.tableScan(ordersTableHandle, ImmutableList.of(p.symbol("orderstatus", orderStatusType)), ImmutableMap.of(p.symbol("orderstatus", orderStatusType), new TpchColumnHandle("orderstatus", orderStatusType))));
    }).matches(constrainedTableScanWithTableLayout("orders", ImmutableMap.of("orderstatus", singleValue(orderStatusType, utf8Slice("O"))), ImmutableMap.of("orderstatus", "orderstatus")));
}
Also used : TpchTableLayoutHandle(io.prestosql.plugin.tpch.TpchTableLayoutHandle) BaseRuleTest(io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest) TpchTableHandle(io.prestosql.plugin.tpch.TpchTableHandle) TpchColumnHandle(io.prestosql.plugin.tpch.TpchColumnHandle) Test(org.testng.annotations.Test) SqlParser(io.prestosql.sql.parser.SqlParser) TableHandle(io.prestosql.spi.metadata.TableHandle) TypeAnalyzer(io.prestosql.sql.planner.TypeAnalyzer) PlanMatchPattern.values(io.prestosql.sql.planner.assertions.PlanMatchPattern.values) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Domain.singleValue(io.prestosql.spi.predicate.Domain.singleValue) TpchTransactionHandle(io.prestosql.plugin.tpch.TpchTransactionHandle) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Type(io.prestosql.spi.type.Type) PlanMatchPattern.filter(io.prestosql.sql.planner.assertions.PlanMatchPattern.filter) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) ImmutableMap(com.google.common.collect.ImmutableMap) TupleDomain(io.prestosql.spi.predicate.TupleDomain) BeforeClass(org.testng.annotations.BeforeClass) CatalogName(io.prestosql.spi.connector.CatalogName) VarcharType.createVarcharType(io.prestosql.spi.type.VarcharType.createVarcharType) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) Domain(io.prestosql.spi.predicate.Domain) Optional(java.util.Optional) PlanMatchPattern.constrainedTableScanWithTableLayout(io.prestosql.sql.planner.assertions.PlanMatchPattern.constrainedTableScanWithTableLayout) Type(io.prestosql.spi.type.Type) VarcharType.createVarcharType(io.prestosql.spi.type.VarcharType.createVarcharType) TpchColumnHandle(io.prestosql.plugin.tpch.TpchColumnHandle) BaseRuleTest(io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest) Test(org.testng.annotations.Test)

Aggregations

Type (io.prestosql.spi.type.Type)764 Test (org.testng.annotations.Test)260 ImmutableList (com.google.common.collect.ImmutableList)230 List (java.util.List)222 ArrayList (java.util.ArrayList)212 ArrayType (io.prestosql.spi.type.ArrayType)200 RowType (io.prestosql.spi.type.RowType)194 VarcharType (io.prestosql.spi.type.VarcharType)159 VarcharType.createUnboundedVarcharType (io.prestosql.spi.type.VarcharType.createUnboundedVarcharType)150 Map (java.util.Map)150 Block (io.prestosql.spi.block.Block)133 ImmutableMap (com.google.common.collect.ImmutableMap)131 Page (io.prestosql.spi.Page)129 PrestoException (io.prestosql.spi.PrestoException)123 DecimalType (io.prestosql.spi.type.DecimalType)118 HashMap (java.util.HashMap)115 Optional (java.util.Optional)113 DecimalType.createDecimalType (io.prestosql.spi.type.DecimalType.createDecimalType)112 Slice (io.airlift.slice.Slice)88 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)87