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);
}
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());
}
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();
}
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);
})));
}
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")));
}
Aggregations