use of io.prestosql.sql.tree.SymbolReference in project hetu-core by openlookeng.
the class TestExpressionDomainTranslator method testCubeRangeVisitorRightSymbolReferenceComparisonExpression.
@Test
public void testCubeRangeVisitorRightSymbolReferenceComparisonExpression() {
CubeRangeCanonicalizer.CubeRangeVisitor visitor = new CubeRangeCanonicalizer.CubeRangeVisitor(TYPES, metadata, TEST_SESSION.toConnectorSession());
Expression cubePredicate = new ComparisonExpression(EQUAL, new LongLiteral("1"), new SymbolReference(C_TINYINT.getName()));
List<Expression> predicates = ExpressionUtils.extractDisjuncts(cubePredicate);
Expression transformed = ExpressionUtils.or(predicates.stream().map(visitor::process).collect(Collectors.toList()));
assertNotNull(transformed);
}
use of io.prestosql.sql.tree.SymbolReference in project hetu-core by openlookeng.
the class TestExpressionDomainTranslator method testCubeRangeVisitorRightCastedSymbolReferenceComparisonExpression.
@Test
public void testCubeRangeVisitorRightCastedSymbolReferenceComparisonExpression() {
CubeRangeCanonicalizer.CubeRangeVisitor visitor = new CubeRangeCanonicalizer.CubeRangeVisitor(TYPES, metadata, TEST_SESSION.toConnectorSession());
Expression cubePredicate = new ComparisonExpression(EQUAL, new LongLiteral("1"), new Cast(new SymbolReference(C_TINYINT.getName()), "integer"));
List<Expression> predicates = ExpressionUtils.extractDisjuncts(cubePredicate);
Expression transformed = ExpressionUtils.or(predicates.stream().map(visitor::process).collect(Collectors.toList()));
assertNotNull(transformed);
}
use of io.prestosql.sql.tree.SymbolReference in project hetu-core by openlookeng.
the class TestExpressionRewriteRuleSet method testAggregationExpressionRewrite.
@Test
public void testAggregationExpressionRewrite() {
ExpressionRewriteRuleSet functionCallRewriter = new ExpressionRewriteRuleSet((expression, context) -> new FunctionCallBuilder(tester().getMetadata()).setName(QualifiedName.of("count")).addArgument(VARCHAR, new SymbolReference("y")).build());
tester().assertThat(functionCallRewriter.aggregationExpressionRewrite()).on(p -> p.aggregation(a -> a.globalGrouping().addAggregation(p.symbol("count_1", BigintType.BIGINT), new FunctionCallBuilder(tester().getMetadata()).setName(QualifiedName.of("count")).addArgument(VARCHAR, new SymbolReference("x")).build(), ImmutableList.of(BigintType.BIGINT)).source(p.values(p.symbol("x"), p.symbol("y"))))).matches(PlanMatchPattern.aggregation(ImmutableMap.of("count_1", aliases -> new FunctionCallBuilder(tester().getMetadata()).setName(QualifiedName.of("count")).addArgument(VARCHAR, new SymbolReference("y")).build()), values("x", "y")));
}
use of io.prestosql.sql.tree.SymbolReference in project hetu-core by openlookeng.
the class RowExpressionVerifier method visitCast.
@Override
protected Boolean visitCast(Cast expected, RowExpression actual) {
// TODO: clean up cast path
if (actual instanceof ConstantExpression && expected.getExpression() instanceof Literal && expected.getType().equals(actual.getType().toString())) {
Literal literal = (Literal) expected.getExpression();
if (literal instanceof StringLiteral) {
Object value = LiteralInterpreter.evaluate((ConstantExpression) actual);
String actualString = value instanceof Slice ? ((Slice) value).toStringUtf8() : String.valueOf(value);
return ((StringLiteral) literal).getValue().equals(actualString);
}
return getValueFromLiteral(literal).equals(String.valueOf(LiteralInterpreter.evaluate((ConstantExpression) actual)));
}
if (actual instanceof VariableReferenceExpression && expected.getExpression() instanceof SymbolReference && expected.getType().equals(actual.getType().toString())) {
return visitSymbolReference((SymbolReference) expected.getExpression(), actual);
}
if (!(actual instanceof CallExpression) || !functionResolution.isCastFunction(((CallExpression) actual).getFunctionHandle())) {
return false;
}
if (!expected.getType().equalsIgnoreCase(actual.getType().toString()) && !(expected.getType().toLowerCase(ENGLISH).equals(VARCHAR) && actual.getType().getTypeSignature().getBase().equals(VARCHAR))) {
return false;
}
return process(expected.getExpression(), ((CallExpression) actual).getArguments().get(0));
}
use of io.prestosql.sql.tree.SymbolReference in project hetu-core by openlookeng.
the class SymbolAliases method getOptional.
public Optional<SymbolReference> getOptional(String inputAlias) {
String alias = inputAlias;
alias = toKey(alias);
SymbolReference result = map.get(alias);
return Optional.ofNullable(result);
}
Aggregations