Skip to content

Commit 2a1e70c

Browse files
committed
Add performance warning for MAP_FILTER
1 parent bc7c50b commit 2a1e70c

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

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

Lines changed: 10 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,15 @@ 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+
);
1120+
warningCollector.add(new PrestoWarning(PERFORMANCE_WARNING, warningMessage));
1121+
}
1122+
11131123
if (node.getOrderBy().isPresent()) {
11141124
for (SortItem sortItem : node.getOrderBy().get().getSortItems()) {
11151125
Type sortKeyType = process(sortItem.getSortKey(), context);

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,40 @@ 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+
164+
assertHasWarning(
165+
analyzeWithWarnings("SELECT map_filter(x, (k, v) -> k = 2) FROM (VALUES (map(ARRAY[1,2,3], ARRAY[10,20,30]))) AS t(x)"),
166+
PERFORMANCE_WARNING,
167+
"Using MAP_FILTER is expensive and may slow down training pipelines. Consider using map_subset or other built-ins for better performance."
168+
);
169+
170+
assertHasWarning(
171+
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)"),
172+
PERFORMANCE_WARNING,
173+
"Using MAP_FILTER is expensive and may slow down training pipelines. Consider using map_subset or other built-ins for better performance."
174+
);
175+
176+
assertHasWarning(
177+
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)"),
178+
PERFORMANCE_WARNING,
179+
"Using MAP_FILTER is expensive and may slow down training pipelines. Consider using map_subset or other built-ins for better performance."
180+
);
181+
182+
assertHasWarning(
183+
analyzeWithWarnings("SELECT map_filter(x, (k, v) -> k + v > 25) FROM (VALUES (map(ARRAY[1,2,3], ARRAY[10,20,30]))) AS t(x)"),
184+
PERFORMANCE_WARNING,
185+
"Using MAP_FILTER is expensive and may slow down training pipelines. Consider using map_subset or other built-ins for better performance."
186+
);
187+
}
188+
155189
@Test
156190
public void testIgnoreNullWarning()
157191
{

0 commit comments

Comments
 (0)