Skip to content

Commit 0a49b00

Browse files
MinuteHanDhantangwangd
authored andcommitted
Migrate Iceberg ApplyChangeLog to connector function
Move ApplyChangelogFunction from IcebergPlugin.getFunctions() to IcebergConnector.getSystemFunctions() to make it available in the iceberg.system namespace instead of presto.default namespace. This follows the connector-level function pattern introduced in PR prestodb#25594 and improves function organization by keeping connector-specific functions within their appropriate namespaces. The function behavior remains unchanged – only the namespace changes from presto.default to iceberg.system. Resolves: prestodb#25849 Add test for ApplyChangeLog function in connector namespace Add tests to TestIcebergTableChangelog to verify that the apply_changelog function is correctly available in the iceberg.system namespace and no longer accessible in the global or presto.default namespaces. This ensures the migration from IcebergPlugin.getFunctions() to IcebergConnector.getSystemFunctions() works as expected.
1 parent 604587b commit 0a49b00

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergConnector.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import com.facebook.airlift.bootstrap.LifeCycleManager;
1717
import com.facebook.presto.hive.HiveTransactionHandle;
18+
import com.facebook.presto.iceberg.function.changelog.ApplyChangelogFunction;
1819
import com.facebook.presto.spi.SystemTable;
1920
import com.facebook.presto.spi.classloader.ThreadContextClassLoader;
2021
import com.facebook.presto.spi.connector.Connector;
@@ -218,4 +219,12 @@ public ConnectorPlanOptimizerProvider getConnectorPlanOptimizerProvider()
218219
{
219220
return planOptimizerProvider;
220221
}
222+
223+
@Override
224+
public Set<Class<?>> getSystemFunctions()
225+
{
226+
return ImmutableSet.<Class<?>>builder()
227+
.add(ApplyChangelogFunction.class)
228+
.build();
229+
}
221230
}

presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergPlugin.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@
1313
*/
1414
package com.facebook.presto.iceberg;
1515

16-
import com.facebook.presto.iceberg.function.changelog.ApplyChangelogFunction;
1716
import com.facebook.presto.spi.Plugin;
1817
import com.facebook.presto.spi.connector.ConnectorFactory;
1918
import com.google.common.collect.ImmutableList;
20-
import com.google.common.collect.ImmutableSet;
2119

2220
import javax.management.MBeanServer;
2321

2422
import java.lang.management.ManagementFactory;
25-
import java.util.Set;
2623

2724
public class IcebergPlugin
2825
implements Plugin
@@ -44,12 +41,4 @@ public Iterable<ConnectorFactory> getConnectorFactories()
4441
{
4542
return ImmutableList.of(new IcebergConnectorFactory(mBeanServer));
4643
}
47-
48-
@Override
49-
public Set<Class<?>> getFunctions()
50-
{
51-
return ImmutableSet.<Class<?>>builder()
52-
.add(ApplyChangelogFunction.class)
53-
.build();
54-
}
5544
}

presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergTableChangelog.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,28 @@ private long getSnapshot(int idx, String tableName)
308308
.mapToLong(Long.class::cast)
309309
.skip(idx).findFirst().getAsLong();
310310
}
311+
312+
@Test
313+
public void testApplyChangelogFunctionInSystemNamespace()
314+
{
315+
assertQuery(
316+
"SELECT iceberg.system.apply_changelog(1, 'INSERT', 'test_value') IS NOT NULL",
317+
"SELECT true");
318+
}
319+
320+
@Test
321+
public void testApplyChangelogFunctionNotInGlobalNamespace()
322+
{
323+
assertQueryFails(
324+
"SELECT apply_changelog(1, 'INSERT', 'test_value')",
325+
"line 1:8: Function apply_changelog not registered");
326+
}
327+
328+
@Test
329+
public void testApplyChangelogFunctionNotInPrestoDefaultNamespace()
330+
{
331+
assertQueryFails(
332+
"SELECT presto.default.apply_changelog(1, 'INSERT', 'test_value')",
333+
"line 1:8: Function apply_changelog not registered");
334+
}
311335
}

0 commit comments

Comments
 (0)