Skip to content

Commit 105af44

Browse files
committed
[pos] Fix connector caused test failures
1 parent 6fe5a5d commit 105af44

File tree

4 files changed

+56
-21
lines changed

4 files changed

+56
-21
lines changed

presto-native-execution/src/test/java/com/facebook/presto/nativeworker/AbstractTestNativeGeneralQueries.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,17 @@ public void testCatalogWithCacheEnabled()
141141
.put("hive.pushdown-filter-enabled", "true")
142142
.build();
143143

144-
getQueryRunner().createCatalog("hivecached", "hive", hiveProperties);
144+
try {
145+
getQueryRunner().createCatalog("hivecached", "hive", hiveProperties);
146+
}
147+
catch (IllegalArgumentException e) {
148+
if (e.getMessage().contains("A catalog already exists")) {
149+
System.out.println("Catalog 'hivecached' already exists, skipping creation");
150+
}
151+
else {
152+
throw e;
153+
}
154+
}
145155

146156
Session actualSession = Session.builder(getSession())
147157
.setCatalog("hivecached")

presto-native-execution/src/test/java/com/facebook/presto/spark/PrestoSparkNativeQueryRunnerUtils.java

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.nio.file.Paths;
3232
import java.util.Map;
3333
import java.util.Optional;
34+
import java.util.stream.Collectors;
3435

3536
import static com.facebook.airlift.log.Level.WARN;
3637
import static com.facebook.presto.nativeworker.NativeQueryRunnerUtils.getNativeWorkerHiveProperties;
@@ -106,6 +107,39 @@ public static PrestoSparkQueryRunner createHiveRunner()
106107
return queryRunner;
107108
}
108109

110+
/**
111+
* Similar to createHiveRunner(), but also add additional specified catalogs and their
112+
* corresponding properties. This method exists because unlike Java, native execution does not
113+
* allow adding catalogs in the tests after process starts. So any tests that need additional
114+
* catalogs need to add them upon runner creation.
115+
*/
116+
public static PrestoSparkQueryRunner createHiveRunner(Map<String, Map<String, String>> additionalCatalogs)
117+
{
118+
// Add connectors on the native side to make them available during execution.
119+
ImmutableMap.Builder<String, Map<String, String>> catalogBuilder = ImmutableMap.builder();
120+
catalogBuilder.put("hive", ImmutableMap.of("connector.name", "hive"))
121+
.putAll(additionalCatalogs);
122+
PrestoSparkQueryRunner queryRunner = createRunner("hive", new NativeExecutionModule(
123+
Optional.of(catalogBuilder.build())));
124+
125+
// Add connectors on the Java side to make them visible during planning.
126+
additionalCatalogs.entrySet().stream().forEach(entry -> {
127+
queryRunner.createCatalog(
128+
entry.getKey(),
129+
entry.getValue().get("connector.name"),
130+
entry.getValue().entrySet().stream().filter(propertyEntry -> {
131+
// Add all properties except for "connector.name" as it is not applicable
132+
// for Java config (it's already fed in as the above function parameter).
133+
return !propertyEntry.getKey().equals("connector.name");
134+
}).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
135+
});
136+
137+
PrestoNativeQueryRunnerUtils.setupJsonFunctionNamespaceManager(queryRunner,
138+
"external_functions.json", "json");
139+
140+
return queryRunner;
141+
}
142+
109143
private static PrestoSparkQueryRunner createRunner(String defaultCatalog, NativeExecutionModule nativeExecutionModule)
110144
{
111145
// Increases log level to reduce log spamming while running test.
@@ -122,10 +156,10 @@ private static PrestoSparkQueryRunner createRunner(String defaultCatalog, Native
122156
public static PrestoSparkQueryRunner createTpchRunner()
123157
{
124158
return createRunner(
125-
"tpchstandard",
126-
new NativeExecutionModule(
127-
Optional.of(
128-
ImmutableMap.of("hive", ImmutableMap.of("connector.name", "tpch")))));
159+
"tpchstandard",
160+
new NativeExecutionModule(
161+
Optional.of(
162+
ImmutableMap.of("tpchstandard", ImmutableMap.of("connector.name", "tpch")))));
129163
}
130164

131165
public static PrestoSparkQueryRunner createRunner(String defaultCatalog, Optional<Path> baseDir, Map<String, String> additionalConfigProperties, Map<String, String> additionalSparkProperties, ImmutableList<Module> nativeModules)

presto-native-execution/src/test/java/com/facebook/presto/spark/TestPrestoSparkNativeGeneralQueries.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.facebook.presto.scalar.sql.SqlInvokedFunctionsPlugin;
2020
import com.facebook.presto.testing.ExpectedQueryRunner;
2121
import com.facebook.presto.testing.QueryRunner;
22+
import com.google.common.collect.ImmutableMap;
2223
import org.testng.annotations.Ignore;
2324

2425
import java.util.ArrayList;
@@ -32,7 +33,12 @@ public class TestPrestoSparkNativeGeneralQueries
3233
@Override
3334
protected QueryRunner createQueryRunner()
3435
{
35-
QueryRunner queryRunner = PrestoSparkNativeQueryRunnerUtils.createHiveRunner();
36+
// Adding additional catalog needed in some tests in the suite.
37+
QueryRunner queryRunner = PrestoSparkNativeQueryRunnerUtils.createHiveRunner(
38+
ImmutableMap.of("hivecached",
39+
ImmutableMap.of("connector.name", "hive",
40+
"hive.storage-format", "DWRF",
41+
"hive.pushdown-filter-enabled", "true")));
3642

3743
// Install plugins needed for extra array functions.
3844
queryRunner.installPlugin(new SqlInvokedFunctionsPlugin());
@@ -115,9 +121,4 @@ public void testRowWiseExchange() {}
115121
@Override
116122
@Ignore
117123
public void testAnalyzeStatsOnDecimals() {}
118-
119-
// VeloxRuntimeError: it != connectors().end() Connector with ID 'hivecached' not registered
120-
@Override
121-
@Ignore
122-
public void testCatalogWithCacheEnabled() {}
123124
}

presto-native-execution/src/test/java/com/facebook/presto/spark/TestPrestoSparkNativeTpchConnectorQueries.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import com.facebook.presto.nativeworker.AbstractTestNativeTpchConnectorQueries;
1717
import com.facebook.presto.testing.ExpectedQueryRunner;
1818
import com.facebook.presto.testing.QueryRunner;
19-
import org.testng.annotations.Ignore;
2019

2120
public class TestPrestoSparkNativeTpchConnectorQueries
2221
extends AbstractTestNativeTpchConnectorQueries
@@ -39,13 +38,4 @@ public void testMissingTpchConnector()
3938
{
4039
super.testMissingTpchConnector(".*Catalog tpch does not exist*");
4140
}
42-
43-
@Override
44-
@Ignore
45-
public void testTpchTinyTables() {}
46-
47-
// VeloxRuntimeError: it != connectors().end() Connector with ID 'tpchstandard' not registered
48-
@Override
49-
@Ignore
50-
public void testTpchDateFilter() {}
5141
}

0 commit comments

Comments
 (0)