Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix : group by on functional expressions in mongo #200

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
Expand Down Expand Up @@ -151,10 +151,12 @@ public static boolean isFunctionExpressionSelectionWithGroupBy(
&& (Boolean) selectionSpec.getExpression().accept(FUNCTION_EXPRESSION_CHECKER);
}

@SuppressWarnings("unchecked")
public static List<String> getGroupByAliases(final List<GroupTypeExpression> expressions) {
return expressions.stream()
.map(expression -> (String) expression.accept(GROUP_BY_ALIAS_GETTER))
.filter(Objects::nonNull)
.map(expression -> (Optional<String>) expression.accept(GROUP_BY_ALIAS_GETTER))
.filter(Optional::isPresent)
.map(Optional::get)
Comment on lines +158 to +159
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Can also be simplified to.

Suggested change
.filter(Optional::isPresent)
.map(Optional::get)
.flatMap(Optional::stream)

.collect(Collectors.toUnmodifiableList());
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package org.hypertrace.core.documentstore.parser;

import java.util.Optional;
import org.hypertrace.core.documentstore.expression.impl.FunctionExpression;
import org.hypertrace.core.documentstore.expression.impl.IdentifierExpression;

@SuppressWarnings("unchecked")
public class GroupByAliasGetter implements GroupTypeExpressionVisitor {

@Override
public String visit(FunctionExpression expression) {
return null;
public Optional<String> visit(FunctionExpression expression) {
return Optional.empty();

Check warning on line 12 in document-store/src/main/java/org/hypertrace/core/documentstore/parser/GroupByAliasGetter.java

View check run for this annotation

Codecov / codecov/patch

document-store/src/main/java/org/hypertrace/core/documentstore/parser/GroupByAliasGetter.java#L12

Added line #L12 was not covered by tests
}

@Override
public String visit(IdentifierExpression expression) {
return expression.getName();
public Optional<String> visit(IdentifierExpression expression) {
return Optional.of(expression.getName());
}
}
Loading