Search in sources :

Example 1 with ExpressionTranslator

use of com.hortonworks.streamline.streams.layout.component.rule.expression.ExpressionTranslator 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());
            }
        }
    }
}
Also used : FunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression) Expression(com.hortonworks.streamline.streams.layout.component.rule.expression.Expression) ExpressionTranslator(com.hortonworks.streamline.streams.layout.component.rule.expression.ExpressionTranslator)

Example 2 with ExpressionTranslator

use of com.hortonworks.streamline.streams.layout.component.rule.expression.ExpressionTranslator in project streamline by hortonworks.

the class StormSqlExpression method handleGroupByHaving.

private void handleGroupByHaving() {
    if (groupBy != null) {
        List<String> groupByExpressions = new ArrayList<>();
        for (Expression expr : groupBy.getExpressions()) {
            ExpressionTranslator groupByTranslator = new StormSqlExpressionTranslator();
            expr.accept(groupByTranslator);
            stormSqlFields.addAll(groupByTranslator.getFields());
            groupByFields.addAll(groupByTranslator.getFields());
            functions.addAll(groupByTranslator.getFunctions());
            groupByExpressions.add(groupByTranslator.getTranslatedExpression());
        }
        groupByExpression = Joiner.on(",").join(groupByExpressions);
        if (having != null) {
            ExpressionTranslator havingTranslator = new StormSqlExpressionTranslator();
            having.getExpression().accept(havingTranslator);
            stormSqlFields.addAll(havingTranslator.getFields());
            functions.addAll(havingTranslator.getFunctions());
            aggregateFunctions.addAll(havingTranslator.getAggregateFunctions());
            havingExpression = havingTranslator.getTranslatedExpression();
            LOG.debug("Built expression [{}] for having [{}]", havingExpression, having);
        }
    }
}
Also used : FunctionExpression(com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression) Expression(com.hortonworks.streamline.streams.layout.component.rule.expression.Expression) ArrayList(java.util.ArrayList) ExpressionTranslator(com.hortonworks.streamline.streams.layout.component.rule.expression.ExpressionTranslator)

Example 3 with ExpressionTranslator

use of com.hortonworks.streamline.streams.layout.component.rule.expression.ExpressionTranslator in project streamline by hortonworks.

the class StormSqlExpression method handleFilter.

private void handleFilter() {
    if (condition != null) {
        ExpressionTranslator conditionTranslator = new StormSqlExpressionTranslator();
        condition.getExpression().accept(conditionTranslator);
        stormSqlFields.addAll(conditionTranslator.getFields());
        if (!conditionTranslator.getAggregateFunctions().isEmpty()) {
            throw new IllegalArgumentException("Cannot have aggregate functions filter condition.");
        }
        functions.addAll(conditionTranslator.getFunctions());
        expression = conditionTranslator.getTranslatedExpression();
        LOG.debug("Built expression [{}] for filter condition [{}]", expression, condition);
    }
}
Also used : ExpressionTranslator(com.hortonworks.streamline.streams.layout.component.rule.expression.ExpressionTranslator)

Aggregations

ExpressionTranslator (com.hortonworks.streamline.streams.layout.component.rule.expression.ExpressionTranslator)3 Expression (com.hortonworks.streamline.streams.layout.component.rule.expression.Expression)2 FunctionExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.FunctionExpression)2 ArrayList (java.util.ArrayList)1