forked from prestodb/presto
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve how we configure plan checkers
Plan checker configurations go in the configured plan checker configuration directory. We load the configuration files to figure out which plan checkers to register, and pass any configuration properties to the PlanCheckerProviderFactory. This change also wraps SimplePlanFragmentSerde into a PlanCheckerProviderContext so that if plan checkers need other things arguments added we can add them to that wrapper class. That way we won't break anyone's plan checker provider plugins by changing the PlanCheckerProviderFactory SPI.
- Loading branch information
1 parent
0a90d6e
commit 1a1fdd8
Showing
15 changed files
with
271 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...rc/main/java/com/facebook/presto/sql/planner/sanity/PlanCheckerProviderManagerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.facebook.presto.sql.planner.sanity; | ||
|
||
import com.facebook.airlift.configuration.Config; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
import java.io.File; | ||
|
||
public class PlanCheckerProviderManagerConfig | ||
{ | ||
private File planCheckerConfigurationDir = new File("etc/plan-checker-providers/"); | ||
|
||
@NotNull | ||
public File getPlanCheckerConfigurationDir() | ||
{ | ||
return planCheckerConfigurationDir; | ||
} | ||
|
||
@Config("plan-checker.config-dir") | ||
public PlanCheckerProviderManagerConfig setPlanCheckerConfigurationDir(File dir) | ||
{ | ||
this.planCheckerConfigurationDir = dir; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
.../src/test/java/com/facebook/presto/sql/planner/sanity/TestPlanCheckerProviderManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.facebook.presto.sql.planner.sanity; | ||
|
||
import com.facebook.airlift.json.JsonCodec; | ||
import com.facebook.presto.spi.plan.PlanCheckerProvider; | ||
import com.facebook.presto.spi.plan.PlanCheckerProviderContext; | ||
import com.facebook.presto.spi.plan.PlanCheckerProviderFactory; | ||
import com.facebook.presto.spi.plan.SimplePlanFragment; | ||
import com.facebook.presto.sql.planner.plan.JsonCodecSimplePlanFragmentSerde; | ||
import com.google.common.collect.ImmutableList; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import static com.facebook.presto.sql.planner.sanity.TestPlanCheckerProviderManager.TestingPlanCheckerProvider.TESTING_PLAN_CHECKER_PROVIDER; | ||
import static com.facebook.presto.testing.assertions.Assert.assertEquals; | ||
|
||
public class TestPlanCheckerProviderManager | ||
{ | ||
@Test | ||
public void testLoadPlanCheckerProviders() | ||
throws IOException | ||
{ | ||
PlanCheckerProviderManagerConfig planCheckerProviderManagerConfig = new PlanCheckerProviderManagerConfig() | ||
.setPlanCheckerConfigurationDir(new File("src/test/resources/plan-checkers")); | ||
PlanCheckerProviderManager planCheckerProviderManager = new PlanCheckerProviderManager(new JsonCodecSimplePlanFragmentSerde(JsonCodec.jsonCodec(SimplePlanFragment.class)), planCheckerProviderManagerConfig); | ||
planCheckerProviderManager.addPlanCheckerProviderFactory(new TestingPlanCheckerProviderFactory()); | ||
planCheckerProviderManager.loadPlanCheckerProviders(); | ||
assertEquals(planCheckerProviderManager.getPlanCheckerProviders(), ImmutableList.of(TESTING_PLAN_CHECKER_PROVIDER)); | ||
} | ||
|
||
@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "No planCheckerProviderFactory found for 'test'. Available factories were \\[]") | ||
public void testLoadUnregisteredPlanCheckerProvider() | ||
throws IOException | ||
{ | ||
PlanCheckerProviderManagerConfig planCheckerProviderManagerConfig = new PlanCheckerProviderManagerConfig() | ||
.setPlanCheckerConfigurationDir(new File("src/test/resources/plan-checkers")); | ||
PlanCheckerProviderManager planCheckerProviderManager = new PlanCheckerProviderManager(new JsonCodecSimplePlanFragmentSerde(JsonCodec.jsonCodec(SimplePlanFragment.class)), planCheckerProviderManagerConfig); | ||
planCheckerProviderManager.loadPlanCheckerProviders(); | ||
} | ||
|
||
public static class TestingPlanCheckerProviderFactory | ||
implements PlanCheckerProviderFactory | ||
{ | ||
@Override | ||
public String getName() | ||
{ | ||
return "test"; | ||
} | ||
|
||
@Override | ||
public PlanCheckerProvider create(Map<String, String> properties, PlanCheckerProviderContext planCheckerProviderContext) | ||
{ | ||
return TESTING_PLAN_CHECKER_PROVIDER; | ||
} | ||
} | ||
|
||
public static class TestingPlanCheckerProvider | ||
implements PlanCheckerProvider | ||
{ | ||
public static final TestingPlanCheckerProvider TESTING_PLAN_CHECKER_PROVIDER = new TestingPlanCheckerProvider(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...est/java/com/facebook/presto/sql/planner/sanity/TestPlanCheckerProviderManagerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.facebook.presto.sql.planner.sanity; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.File; | ||
import java.util.Map; | ||
|
||
import static com.facebook.airlift.configuration.testing.ConfigAssertions.assertFullMapping; | ||
import static com.facebook.airlift.configuration.testing.ConfigAssertions.assertRecordedDefaults; | ||
import static com.facebook.airlift.configuration.testing.ConfigAssertions.recordDefaults; | ||
|
||
public class TestPlanCheckerProviderManagerConfig | ||
{ | ||
@Test | ||
public void testDefaults() | ||
{ | ||
assertRecordedDefaults(recordDefaults(PlanCheckerProviderManagerConfig.class) | ||
.setPlanCheckerConfigurationDir(new File("etc/plan-checker-providers"))); | ||
} | ||
|
||
@Test | ||
public void testExplicitPropertyMappings() | ||
{ | ||
Map<String, String> properties = new ImmutableMap.Builder<String, String>() | ||
.put("plan-checker.config-dir", "/foo") | ||
.build(); | ||
|
||
PlanCheckerProviderManagerConfig expected = new PlanCheckerProviderManagerConfig() | ||
.setPlanCheckerConfigurationDir(new File("/foo")); | ||
|
||
assertFullMapping(properties, expected); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
presto-main/src/test/resources/plan-checkers/test-plan-checker.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
plan-checker-provider.name=test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
presto-spi/src/main/java/com/facebook/presto/spi/plan/PlanCheckerProviderContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.facebook.presto.spi.plan; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class PlanCheckerProviderContext | ||
{ | ||
private final SimplePlanFragmentSerde simplePlanFragmentSerde; | ||
|
||
public PlanCheckerProviderContext(SimplePlanFragmentSerde simplePlanFragmentSerde) | ||
{ | ||
this.simplePlanFragmentSerde = requireNonNull(simplePlanFragmentSerde, "simplePlanFragmentSerde is null"); | ||
} | ||
|
||
public SimplePlanFragmentSerde getSimplePlanFragmentSerde() | ||
{ | ||
return simplePlanFragmentSerde; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.