Source:
public TranslatedExpression<JdbcExpression> translateSpecialForm(SpecialFormExpression specialForm, Map<VariableReferenceExpression, ColumnHandle> context, RowExpressionTreeTranslator<JdbcExpression, Map<VariableReferenceExpression, ColumnHandle>> rowExpressionTreeTranslator) { List<TranslatedExpression<JdbcExpression>> translatedExpressions = specialForm.getArguments().stream() .map(expression -> rowExpressionTreeTranslator.rewrite(expression, context)) .collect(toImmutableList()); List<JdbcExpression> jdbcExpressions = translatedExpressions.stream() .map(TranslatedExpression::getTranslated) .filter(Optional::isPresent) .map(Optional::get) .collect(toImmutableList()); if (jdbcExpressions.size() < translatedExpressions.size()) { return untranslated(specialForm, translatedExpressions); } List<String> sqlBodies = jdbcExpressions.stream() .map(JdbcExpression::getSql) .map(sql -> '(' + sql + ')') .collect(toImmutableList()); List<ConstantExpression> variableBindings = jdbcExpressions.stream() .map(JdbcExpression::getBindValues) .flatMap(List::stream) .collect(toImmutableList()); switch (specialForm.getForm()) { case AND: return new TranslatedExpression<>( Optional.of(new JdbcExpression(format("(%s)", Joiner.on(" AND ").join(sqlBodies)), variableBindings)), specialForm, translatedExpressions); case OR: return new TranslatedExpression<>( Optional.of(new JdbcExpression(format("(%s)", Joiner.on(" OR ").join(sqlBodies)), variableBindings)), specialForm, translatedExpressions); case IN: return new TranslatedExpression<>( Optional.of(new JdbcExpression(format("(%s IN (%s))", sqlBodies.get(0), Joiner.on(" , ").join(sqlBodies.subList(1, sqlBodies.size()))), variableBindings)), specialForm, translatedExpressions); } return untranslated(specialForm, translatedExpressions); }

Target:
public TranslatedExpression<JdbcExpression> translateSpecialForm(SpecialFormExpression specialForm, Map<VariableReferenceExpression, ColumnHandle> context, RowExpressionTreeTranslator<JdbcExpression, Map<VariableReferenceExpression, ColumnHandle>> rowExpressionTreeTranslator) { List<TranslatedExpression<JdbcExpression>> translatedExpressions = specialForm.getArguments().stream() .map(expression -> rowExpressionTreeTranslator.rewrite(expression, context)) .collect(toImmutableList()); List<JdbcExpression> jdbcExpressions = translatedExpressions.stream() .map(TranslatedExpression::getTranslated) .filter(Optional::isPresent) .map(Optional::get) .collect(toImmutableList()); if (jdbcExpressions.size() < translatedExpressions.size()) { return untranslated(specialForm, translatedExpressions); } List<String> sqlBodies = jdbcExpressions.stream() .map(JdbcExpression::getExpression) .map(sql -> '(' + sql + ')') .collect(toImmutableList()); List<ConstantExpression> variableBindings = jdbcExpressions.stream() .map(JdbcExpression::getBoundConstantValues) .flatMap(List::stream) .collect(toImmutableList()); switch (specialForm.getForm()) { case AND: return new TranslatedExpression<>( Optional.of(new JdbcExpression(format("(%s)", Joiner.on(" AND ").join(sqlBodies)), variableBindings)), specialForm, translatedExpressions); case OR: return new TranslatedExpression<>( Optional.of(new JdbcExpression(format("(%s)", Joiner.on(" OR ").join(sqlBodies)), variableBindings)), specialForm, translatedExpressions); case IN: return new TranslatedExpression<>( Optional.of(new JdbcExpression(format("(%s IN (%s))", sqlBodies.get(0), Joiner.on(" , ").join(sqlBodies.subList(1, sqlBodies.size()))), variableBindings)), specialForm, translatedExpressions); } return untranslated(specialForm, translatedExpressions); }