Skip to content

Commit 5de645b

Browse files
committed
Add performance warning for MAP_FILTER
1 parent bc7c50b commit 5de645b

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/ExpressionAnalyzer.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
import static com.facebook.presto.common.type.VarcharType.VARCHAR;
155155
import static com.facebook.presto.metadata.BuiltInTypeAndFunctionNamespaceManager.JAVA_BUILTIN_NAMESPACE;
156156
import static com.facebook.presto.spi.StandardErrorCode.OPERATOR_NOT_FOUND;
157+
import static com.facebook.presto.spi.StandardWarningCode.PERFORMANCE_WARNING;
157158
import static com.facebook.presto.spi.StandardWarningCode.SEMANTIC_WARNING;
158159
import static com.facebook.presto.sql.NodeUtils.getSortItemsFromOrderBy;
159160
import static com.facebook.presto.sql.analyzer.Analyzer.verifyNoAggregateWindowOrGroupingFunctions;
@@ -1110,6 +1111,14 @@ else if (frame.getType() == GROUPS) {
11101111
FunctionHandle function = resolveFunction(sessionFunctions, transactionId, node, argumentTypes, functionAndTypeResolver);
11111112
FunctionMetadata functionMetadata = functionAndTypeResolver.getFunctionMetadata(function);
11121113

1114+
String functionName = functionMetadata.getName().getObjectName().toUpperCase();
1115+
if (functionName.equals("MAP_FILTER")) {
1116+
String warningMessage = String.format(
1117+
"Using MAP_FILTER is expensive and may slow down training pipelines. Consider using map_subset or other built-ins for better performance.",
1118+
functionName);
1119+
warningCollector.add(new PrestoWarning(PERFORMANCE_WARNING, warningMessage));
1120+
}
1121+
11131122
if (node.getOrderBy().isPresent()) {
11141123
for (SortItem sortItem : node.getOrderBy().get().getSortItems()) {
11151124
Type sortKeyType = process(sortItem.getSortKey(), context);

presto-main-base/src/test/java/com/facebook/presto/sql/analyzer/TestAnalyzer.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,35 @@ void testNoORWarning()
152152
assertNoWarning(analyzeWithWarnings("SELECT * FROM t1 JOIN t2 ON t1.a = t2.a \n" + "AND (t1.b = t2.b OR t1.b > t2.b)"));
153153
}
154154

155+
@Test
156+
public void testMapFilterWarnings()
157+
{
158+
assertHasWarning(
159+
analyzeWithWarnings("SELECT map_filter(x, (k, v) -> v > 1) FROM (VALUES (map(ARRAY[1,2], ARRAY[2,3]))) AS t(x)"),
160+
PERFORMANCE_WARNING,
161+
"Using MAP_FILTER is expensive and may slow down training pipelines. Consider using map_subset or other built-ins for better performance.");
162+
163+
assertHasWarning(
164+
analyzeWithWarnings("SELECT map_filter(x, (k, v) -> k = 2) FROM (VALUES (map(ARRAY[1,2,3], ARRAY[10,20,30]))) AS t(x)"),
165+
PERFORMANCE_WARNING,
166+
"Using MAP_FILTER is expensive and may slow down training pipelines. Consider using map_subset or other built-ins for better performance.");
167+
168+
assertHasWarning(
169+
analyzeWithWarnings("SELECT map_filter(x, (k, v) -> k IN (1, 3)) FROM (VALUES (map(ARRAY[1,2,3], ARRAY[10,20,30]))) AS t(x)"),
170+
PERFORMANCE_WARNING,
171+
"Using MAP_FILTER is expensive and may slow down training pipelines. Consider using map_subset or other built-ins for better performance.");
172+
173+
assertHasWarning(
174+
analyzeWithWarnings("SELECT map_filter(x, (k, v) -> v IN (20, 30)) FROM (VALUES (map(ARRAY[1,2,3], ARRAY[10,20,30]))) AS t(x)"),
175+
PERFORMANCE_WARNING,
176+
"Using MAP_FILTER is expensive and may slow down training pipelines. Consider using map_subset or other built-ins for better performance.");
177+
178+
assertHasWarning(
179+
analyzeWithWarnings("SELECT map_filter(x, (k, v) -> k + v > 25) FROM (VALUES (map(ARRAY[1,2,3], ARRAY[10,20,30]))) AS t(x)"),
180+
PERFORMANCE_WARNING,
181+
"Using MAP_FILTER is expensive and may slow down training pipelines. Consider using map_subset or other built-ins for better performance.");
182+
}
183+
155184
@Test
156185
public void testIgnoreNullWarning()
157186
{

0 commit comments

Comments
 (0)