Search in sources :

Example 1 with StoragePluginConfig

use of org.apache.drill.common.logical.StoragePluginConfig in project drill by axbaretto.

the class StoragePluginRegistryImpl method getPlugin.

@Override
public StoragePlugin getPlugin(String name) throws ExecutionSetupException {
    StoragePlugin plugin = plugins.get(name);
    if (name.equals(SYS_PLUGIN) || name.equals(INFORMATION_SCHEMA_PLUGIN)) {
        return plugin;
    }
    // since we lazily manage the list of plugins per server, we need to update this once we know that it is time.
    StoragePluginConfig config = this.pluginSystemTable.get(name);
    if (config == null) {
        if (plugin != null) {
            plugins.remove(name);
        }
        return null;
    } else {
        if (plugin == null || !plugin.getConfig().equals(config) || plugin.getConfig().isEnabled() != config.isEnabled()) {
            plugin = createOrUpdate(name, config, false);
        }
        return plugin;
    }
}
Also used : StoragePluginConfig(org.apache.drill.common.logical.StoragePluginConfig) InfoSchemaStoragePlugin(org.apache.drill.exec.store.ischema.InfoSchemaStoragePlugin)

Example 2 with StoragePluginConfig

use of org.apache.drill.common.logical.StoragePluginConfig in project drill by axbaretto.

the class JdbcDataTest method testProjectFilterSubqueryPlan.

@Test
public void testProjectFilterSubqueryPlan() throws Exception {
    LogicalPlan plan = withModel(MODEL, "DONUTS").sql("select d['name'] as name, d['xx'] as xx from (\n" + " select _MAP['donuts'] as d from donuts)\n" + "where cast(d['ppu'] as double) > 0.6").logicalPlan();
    PlanProperties planProperties = plan.getProperties();
    Assert.assertEquals("optiq", planProperties.generator.type);
    Assert.assertEquals("na", planProperties.generator.info);
    Assert.assertEquals(1, planProperties.version);
    Assert.assertEquals(PlanProperties.PlanType.APACHE_DRILL_LOGICAL, planProperties.type);
    Map<String, StoragePluginConfig> seConfigs = plan.getStorageEngines();
    StoragePluginConfig config = seConfigs.get("donuts-json");
    // Assert.assertTrue(config != null && config instanceof ClasspathRSE.ClasspathRSEConfig);
    config = seConfigs.get("queue");
    // Assert.assertTrue(config != null && config instanceof QueueRSE.QueueRSEConfig);
    Scan scan = findOnlyOperator(plan, Scan.class);
    Assert.assertEquals("donuts-json", scan.getStorageEngine());
    Filter filter = findOnlyOperator(plan, Filter.class);
    Assert.assertTrue(filter.getInput() instanceof Scan);
    Project[] projects = Iterables.toArray(findOperator(plan, Project.class), Project.class);
    Assert.assertEquals(2, projects.length);
    Assert.assertEquals(1, projects[0].getSelections().size());
    Assert.assertEquals(Filter.class, projects[0].getInput().getClass());
    Assert.assertEquals(2, projects[1].getSelections().size());
    Assert.assertEquals(Project.class, projects[1].getInput().getClass());
    Store store = findOnlyOperator(plan, Store.class);
    Assert.assertEquals("queue", store.getStorageEngine());
    Assert.assertEquals("output sink", store.getMemo());
    Assert.assertEquals(Project.class, store.getInput().getClass());
}
Also used : Project(org.apache.drill.common.logical.data.Project) PlanProperties(org.apache.drill.common.logical.PlanProperties) Filter(org.apache.drill.common.logical.data.Filter) Store(org.apache.drill.common.logical.data.Store) LogicalPlan(org.apache.drill.common.logical.LogicalPlan) StoragePluginConfig(org.apache.drill.common.logical.StoragePluginConfig) Scan(org.apache.drill.common.logical.data.Scan) Test(org.junit.Test) JdbcTest(org.apache.drill.categories.JdbcTest)

Example 3 with StoragePluginConfig

use of org.apache.drill.common.logical.StoragePluginConfig in project drill by apache.

the class PluginBootstrapLoaderImpl method loadFormatPlugins.

/**
 * Loads format plugins from the given URL and adds the formats to the
 * specified storage plugins
 *
 * @param url
 *          URL to the format plugins bootstrap file
 * @param bootstrapPlugins
 *          a collection with loaded storage plugins. New formats will be
 *          added to them
 * @param pluginURLMap
 *          a map to store correspondence between storage plugins and
 *          bootstrap files in which they are defined. Used for logging
 * @throws IOException
 *           if failed to retrieve a plugin from a bootstrap file
 */
private void loadFormatPlugins(URL url, StoragePlugins bootstrapPlugins, Map<String, URL> pluginURLMap) throws IOException {
    StoragePlugins plugins = getPluginsFromResource(url);
    for (Entry<String, StoragePluginConfig> sourceEntry : plugins) {
        String pluginName = sourceEntry.getKey();
        StoragePluginConfig sourcePlugin = sourceEntry.getValue();
        if (!(sourcePlugin instanceof FileSystemConfig)) {
            logger.warn("Formats are only supported by File System plugins. Source name '{}' is of type '{}'.", pluginName, sourcePlugin.getClass().getName());
            continue;
        }
        StoragePluginConfig targetPlugin = bootstrapPlugins.getConfig(pluginName);
        if (targetPlugin == null) {
            logger.warn("No boostrap storage plugin matches the name '{}'", pluginName);
            continue;
        }
        if (!(targetPlugin instanceof FileSystemConfig)) {
            logger.warn("Formats are only supported by File System plugins. Source name '{}' " + "is of type '{}' but the bootstrap plugin of that name is of type '{}.", pluginName, sourcePlugin.getClass().getName(), targetPlugin.getClass().getName());
            continue;
        }
        FileSystemConfig targetFsConfig = (FileSystemConfig) targetPlugin;
        FileSystemConfig sourceFsConfig = (FileSystemConfig) sourcePlugin;
        sourceFsConfig.getFormats().forEach((formatName, formatValue) -> {
            FormatPluginConfig oldPluginConfig = targetFsConfig.getFormats().putIfAbsent(formatName, formatValue);
            if (oldPluginConfig != null) {
                logger.warn("Duplicate format instance '{}' defined in '{}' and '{}', ignoring the later one.", formatName, pluginURLMap.get(pluginName), url);
            }
        });
    }
}
Also used : StoragePlugins(org.apache.drill.exec.planner.logical.StoragePlugins) FormatPluginConfig(org.apache.drill.common.logical.FormatPluginConfig) StoragePluginConfig(org.apache.drill.common.logical.StoragePluginConfig) FileSystemConfig(org.apache.drill.exec.store.dfs.FileSystemConfig)

Example 4 with StoragePluginConfig

use of org.apache.drill.common.logical.StoragePluginConfig in project drill by apache.

the class PluginBootstrapLoaderImpl method loadStoragePlugins.

/**
 * Loads storage plugins from the given URL
 *
 * @param url
 *          URL to the storage plugins bootstrap file
 * @param bootstrapPlugins
 *          a collection where the plugins should be loaded to
 * @param pluginURLMap
 *          a map to store correspondence between storage plugins and
 *          bootstrap files in which they are defined. Used for logging
 * @throws IOException
 *           if failed to retrieve a plugin from a bootstrap file
 */
private void loadStoragePlugins(URL url, StoragePlugins bootstrapPlugins, Map<String, URL> pluginURLMap) throws IOException {
    StoragePlugins plugins = getPluginsFromResource(url);
    plugins.forEach(plugin -> {
        StoragePluginConfig oldPluginConfig = bootstrapPlugins.putIfAbsent(plugin.getKey(), plugin.getValue());
        if (oldPluginConfig != null) {
            logger.warn("Duplicate plugin instance '[{}]' defined in [{}, {}], ignoring the later one.", plugin.getKey(), pluginURLMap.get(plugin.getKey()), url);
        } else {
            pluginURLMap.put(plugin.getKey(), url);
        }
    });
}
Also used : StoragePlugins(org.apache.drill.exec.planner.logical.StoragePlugins) StoragePluginConfig(org.apache.drill.common.logical.StoragePluginConfig)

Example 5 with StoragePluginConfig

use of org.apache.drill.common.logical.StoragePluginConfig in project drill by apache.

the class StoragePluginRegistryImpl method loadEnabledPlugins.

/**
 * Initializes {@link #pluginCache} with currently enabled plugins
 * defined in the persistent store.
 *
 * @return {@code true} if the persistent store contained plugins
 * (and thus was initialized, and should perhaps be upgraded), or
 * {@code false} if no plugins were found and this this is a new store
 * which should be initialized. Avoids the need to check persistent
 * store contents twice
 */
private boolean loadEnabledPlugins() {
    Iterator<Entry<String, StoragePluginConfig>> allPlugins = pluginStore.load();
    int count = 0;
    while (allPlugins.hasNext()) {
        count++;
        Entry<String, StoragePluginConfig> plugin = allPlugins.next();
        String name = plugin.getKey();
        StoragePluginConfig config = plugin.getValue();
        if (!config.isEnabled()) {
            continue;
        }
        try {
            pluginCache.put(createPluginEntry(name, config, PluginType.STORED));
        } catch (Exception e) {
            logger.error("Failure while setting up StoragePlugin with name: '{}', disabling.", name, e);
            config.setEnabled(false);
            pluginStore.put(name, config);
        }
    }
    // If found at least one entry then this is an existing registry.
    return count > 0;
}
Also used : ImmutableEntry(org.apache.drill.common.collections.ImmutableEntry) Entry(java.util.Map.Entry) StoragePluginConfig(org.apache.drill.common.logical.StoragePluginConfig) UnrecognizedPropertyException(com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException) UserException(org.apache.drill.common.exceptions.UserException) InvalidTypeIdException(com.fasterxml.jackson.databind.exc.InvalidTypeIdException) ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

StoragePluginConfig (org.apache.drill.common.logical.StoragePluginConfig)28 Test (org.junit.Test)15 FileSystemConfig (org.apache.drill.exec.store.dfs.FileSystemConfig)12 StoragePlugins (org.apache.drill.exec.planner.logical.StoragePlugins)9 OperatorFixture (org.apache.drill.test.OperatorFixture)6 BaseTest (org.apache.drill.test.BaseTest)5 ClusterFixture (org.apache.drill.test.ClusterFixture)5 ClusterFixtureBuilder (org.apache.drill.test.ClusterFixtureBuilder)5 HashMap (java.util.HashMap)4 JdbcTest (org.apache.drill.categories.JdbcTest)4 LogicalPlan (org.apache.drill.common.logical.LogicalPlan)4 PlanProperties (org.apache.drill.common.logical.PlanProperties)4 Project (org.apache.drill.common.logical.data.Project)4 Scan (org.apache.drill.common.logical.data.Scan)4 Store (org.apache.drill.common.logical.data.Store)4 InfoSchemaStoragePlugin (org.apache.drill.exec.store.ischema.InfoSchemaStoragePlugin)4 IOException (java.io.IOException)3 Map (java.util.Map)3 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)3 PluginException (org.apache.drill.exec.store.StoragePluginRegistry.PluginException)3