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

feat(java): support spark in predict push down to lance scan #3314

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -36,6 +36,7 @@
import java.sql.Date;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -89,7 +90,7 @@ public static boolean isFilterSupported(Filter filter) {
} else if (filter instanceof EqualNullSafe) {
return false;
} else if (filter instanceof In) {
return false;
return true;
} else if (filter instanceof LessThan) {
return true;
} else if (filter instanceof LessThanOrEqual) {
Expand Down Expand Up @@ -163,6 +164,13 @@ private static Optional<String> compileFilter(Filter filter) {
Optional<String> child = compileFilter(f.child());
if (child.isEmpty()) return child;
return Optional.of(String.format("NOT (%s)", child.get()));
} else if (filter instanceof In) {
In in = (In) filter;
String values =
Arrays.stream(in.values())
.map(FilterPushDown::compileValue)
.collect(Collectors.joining(","));
return Optional.of(String.format("%s IN (%s)", in.attribute(), values));
}

return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,26 @@ public void testCompileFiltersToSqlWhereClauseWithEmptyFilters() {
Optional<String> whereClause = FilterPushDown.compileFiltersToSqlWhereClause(filters);
assertFalse(whereClause.isPresent());
}

@Test
public void testIntegerInFilterPushDown() {
Object[] values = new Object[2];
values[0] = 500;
values[1] = 600;
Filter[] filters = new Filter[] {new GreaterThan("age", 30), new In("salary", values)};
Optional<String> whereClause = FilterPushDown.compileFiltersToSqlWhereClause(filters);
assertTrue(whereClause.isPresent());
assertEquals("(age > 30) AND (salary IN (500,600))", whereClause.get());
}

@Test
public void testStringInFilterPushDown() {
Object[] values = new Object[2];
values[0] = "500";
values[1] = "600";
Filter[] filters = new Filter[] {new GreaterThan("age", 30), new In("salary", values)};
Optional<String> whereClause = FilterPushDown.compileFiltersToSqlWhereClause(filters);
assertTrue(whereClause.isPresent());
assertEquals("(age > 30) AND (salary IN ('500','600'))", whereClause.get());
}
}
Loading