use of com.hortonworks.streamline.streams.layout.component.rule.expression.Expression in project streamline by hortonworks.
the class RuleProcessorRuntime method createSqlExpression.
private StormSqlExpression createSqlExpression(Rule rule) {
List<Expression> groupByExpressions = new ArrayList<>();
if (rule.getWindow() != null) {
groupByExpressions.addAll(GROUP_BY_WINDOWID.getExpressions());
}
if (rule.getGroupBy() != null) {
groupByExpressions.addAll(rule.getGroupBy().getExpressions());
}
StormSqlExpression stormSqlExpression = new StormSqlExpression(rule.getCondition(), rule.getProjection(), groupByExpressions.isEmpty() ? null : new GroupBy(groupByExpressions), groupByExpressions.isEmpty() ? null : rule.getHaving());
LOG.info("Built stormSqlExpression {}", stormSqlExpression);
return stormSqlExpression;
}
use of com.hortonworks.streamline.streams.layout.component.rule.expression.Expression in project streamline by hortonworks.
the class StormSqlExpression method handleProjection.
private void handleProjection() {
if (projection != null) {
for (Expression expr : projection.getExpressions()) {
ExpressionTranslator translator = new StormSqlExpressionTranslator();
expr.accept(translator);
stormSqlFields.addAll(translator.getFields());
functions.addAll(translator.getFunctions());
aggregateFunctions.addAll(translator.getAggregateFunctions());
projectedFields.add(translator.getTranslatedExpression());
if (!translator.getAliases().isEmpty()) {
outputFields.add(translator.getAliases().get(0));
} else {
outputFields.add(translator.getUnquotedTranslatedExpression());
}
}
}
}
use of com.hortonworks.streamline.streams.layout.component.rule.expression.Expression in project streamline by hortonworks.
the class GroovyExpressionTest method testOrString.
@Test
public void testOrString() throws Exception {
Condition condition = new Condition();
Expression left = new BinaryExpression(Operator.LESS_THAN, getVariable("a"), getVariable("b"));
Expression right = new BinaryExpression(Operator.GREATER_THAN, getVariable("c"), getVariable("d"));
condition.setExpression(new BinaryExpression(Operator.OR, left, right));
GroovyExpression expr = new GroovyExpression(condition);
Assert.assertEquals("a < b || c > d", expr.asString());
}
use of com.hortonworks.streamline.streams.layout.component.rule.expression.Expression in project streamline by hortonworks.
the class GroovyExpressionTest method testAndAsString.
@Test
public void testAndAsString() throws Exception {
Condition condition = new Condition();
Expression left = new BinaryExpression(Operator.OR, getVariable("a"), getVariable("b"));
Expression right = new BinaryExpression(Operator.OR, getVariable("c"), getVariable("d"));
condition.setExpression(new BinaryExpression(Operator.AND, left, right));
GroovyExpression expr = new GroovyExpression(condition);
Assert.assertEquals("(a || b) && (c || d)", expr.asString());
}
use of com.hortonworks.streamline.streams.layout.component.rule.expression.Expression in project streamline by hortonworks.
the class ExpressionGenerator method visitSqlSpecialOperator.
private Expression visitSqlSpecialOperator(SqlSpecialOperator specialOperator, List<SqlNode> operands) {
if (specialOperator.getName().equalsIgnoreCase("ITEM")) {
Expression left = operands.get(0).accept(this);
SqlNode right = operands.get(1);
if (right instanceof SqlNumericLiteral) {
SqlNumericLiteral index = (SqlNumericLiteral) right;
if (!index.isInteger()) {
throw new IllegalArgumentException("Invalid array index " + index);
}
return new ArrayFieldExpression(left, Integer.parseInt(index.toValue()));
} else if (right instanceof SqlCharStringLiteral) {
String key = ((SqlCharStringLiteral) right).toValue();
return new MapFieldExpression(left, key);
} else {
throw new IllegalArgumentException("Item right operand '" + right + "' must be numeric or character type");
}
} else if (specialOperator.getName().equalsIgnoreCase("AS")) {
Expression left = operands.get(0).accept(this);
String alias = operands.get(1).toString();
return new AsExpression(left, alias);
} else {
throw new UnsupportedOperationException("Operator " + specialOperator + " not implemented");
}
}
Aggregations