Open shfshihuafeng opened 1 year ago
we should determines whether the parameter name equals the plug-in name ?
--- a/contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/HttpSchemaFactory.java
+++ b/contrib/storage-http/src/main/java/org/apache/drill/exec/store/http/HttpSchemaFactory.java
@@ -18,8 +18,11 @@
package org.apache.drill.exec.store.http;
import java.util.Collections;
+import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
+import java.util.stream.Collectors;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.schema.Table;
@@ -85,7 +88,7 @@ public class HttpSchemaFactory extends AbstractSchemaFactory {
HttpAPIConnectionSchema subSchema = subSchemas.get(name);
if (subSchema != null) {
return subSchema;
- } else if (tables.containsKey(name)) {
+ } else if (tables.containsKey(name) || isRegistryPluginName(name.toLowerCase(Locale.ROOT))) {
return null;
} else {
throw UserException
@@ -95,6 +98,12 @@ public class HttpSchemaFactory extends AbstractSchemaFactory {
}
}
+ private boolean isRegistryPluginName(String name) {
+ Set<String> pluginNames = plugin.getRegistry().availablePlugins();
+ Set<String> pluginNamesToLower = pluginNames.stream().map(String::toLowerCase).collect(Collectors.toSet());
+ return pluginNamesToLower.contains(name);
+ }
@shfshihuafeng I don't think this is a bug. You are first running the query USE http
which sets the root at http
. Then you're running a SELECT ... FROM http.sunrise
. So at that point, the plugin is looking for a path: http.http.sunrise
which does not exist.
I'd bet that if you either skipped the USE
query or ran a SELECT ... FROM sunrise
it would work.
@cgivre You are right, but when use http, the default schema is http, when we use another data source schema, will report error. It think this is not right.
@cgivre
@cgivre when i use "use my.test" command to switch schema, It is correct to query data with full schema Name from other data sources
@shfshihuafeng
So are you saying the behavior with USE
is inconsistent? I want to make sure I understand the issue.
@cgivre There are two problems with this
I think that I have exactly the same problem. It seems that after you change schema to http storage schema you cannot run any SQL.
➜ tmp cat bootstrap-storage-plugins.json
{ "storage": { "http": { "type": "http", "cacheResults": false, "enabled": true, "timeout": 5, "connections": { "sunrise": { "url": "https://api.sunrise-sunset.org/json", "requireTail": false, "method": "GET", "dataPath": "results", "headers": null, "params": [ "lat", "lng", "date" ], "authType": "none", "userName": null, "password": null, "postBody": null } } } } } ➜ tmp docker run -it --rm --name drill -v "${HOME}"/tmp/bootstrap-storage-plugins.json:/opt/drill/conf/bootstrap-storage-plugins.json apache/drill WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested Apache Drill 1.21.1 "Drill must go on." apache drill> !schemas +--------------------+---------------+ | TABLE_SCHEM | TABLE_CATALOG | +--------------------+---------------+ | cp.default | DRILL | | dfs.default | DRILL | | dfs.root | DRILL | | dfs.tmp | DRILL | | http | DRILL | | information_schema | DRILL | | sys | DRILL | +--------------------+---------------+ apache drill> SELECT version FROM sys.version; +---------+ | version | +---------+ | 1.21.1 | +---------+ 1 row selected (2.638 seconds) apache drill> SELECT sunrise, sunset FROM http.sunrise WHERElat
= 36.7201600 ANDlng
= -4.4203400 ANDdate
= 'today'; +------------+------------+ | sunrise | sunset | +------------+------------+ | 6:32:42 AM | 5:30:55 PM | +------------+------------+ 1 row selected (2.506 seconds) apache drill> use http; +------+----------------------------------+ | ok | summary | +------+----------------------------------+ | true | Default schema changed to [http] | +------+----------------------------------+ 1 row selected (0.219 seconds) apache drill (http)> SELECT sunrise, sunset FROM sunrise WHERElat
= 36.7201600 ANDlng
= -4.4203400 ANDdate
= 'today'; Error: CONNECTION ERROR: API 'http' does not exist in HTTP storage plugin 'http'[Error Id: 574dff2e-53ac-47c8-a4dc-f4368f5d60ea ] (state=,code=0) apache drill (http)> SELECT sunrise, sunset FROM http.sunrise WHERE
lat
= 36.7201600 ANDlng
= -4.4203400 ANDdate
= 'today'; Error: CONNECTION ERROR: API 'http' does not exist in HTTP storage plugin 'http'[Error Id: ff623dec-3ecc-4eed-9caa-bad804694ea9 ] (state=,code=0) apache drill (http)> SELECT version FROM sys.version; Error: CONNECTION ERROR: API 'sys' does not exist in HTTP storage plugin 'http'
[Error Id: fd4309e5-8883-4219-b0b7-3beec7147b96 ] (state=,code=0) apache drill (http)> use sys; Error: CONNECTION ERROR: API 'sys' does not exist in HTTP storage plugin 'http'
[Error Id: 08a3b91a-a216-4088-8fc2-e0bc0d79bfc1 ] (state=,code=0) apache drill (http)> !schemas +--------------------+---------------+ | TABLE_SCHEM | TABLE_CATALOG | +--------------------+---------------+ | cp.default | DRILL | | dfs.default | DRILL | | dfs.root | DRILL | | dfs.tmp | DRILL | | http | DRILL | | information_schema | DRILL | | sys | DRILL | +--------------------+---------------+ apache drill (http)> !reconnect Reconnecting to "jdbc:drill:zk=local"... apache drill> SELECT version FROM sys.version; +---------+ | version | +---------+ | 1.21.1 | +---------+ 1 row selected (0.24 seconds) apache drill> !quit ➜ tmp
Only exception is that if you name HTTP storage and connection with same name (eg. schema sunrise and connection sunrise) you can query data using both schema.connection and connection but you still can't query any other schema using anotherschema.connection.
➜ tmp cat bootstrap-storage-plugins.json
{ "storage": { "sunrise": { "type": "http", "cacheResults": false, "enabled": true, "timeout": 5, "connections": { "sunrise": { "url": "https://api.sunrise-sunset.org/json", "requireTail": false, "method": "GET", "dataPath": "results", "headers": null, "params": [ "lat", "lng", "date" ], "authType": "none", "userName": null, "password": null, "postBody": null } } } } } ➜ tmp docker run -it --rm --name drill -v "${HOME}"/tmp/bootstrap-storage-plugins.json:/opt/drill/conf/bootstrap-storage-plugins.json apache/drill WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested Apache Drill 1.21.1 "Say hello to my little Drill." apache drill> !schemas +--------------------+---------------+ | TABLE_SCHEM | TABLE_CATALOG | +--------------------+---------------+ | cp.default | DRILL | | dfs.default | DRILL | | dfs.root | DRILL | | dfs.tmp | DRILL | | information_schema | DRILL | | sunrise | DRILL | | sys | DRILL | +--------------------+---------------+ apache drill> SELECT version FROM sys.version; +---------+ | version | +---------+ | 1.21.1 | +---------+ 1 row selected (2.235 seconds) apache drill> SELECT sunrise, sunset FROM sunrise.sunrise WHERElat
= 36.7201600 ANDlng
= -4.4203400 ANDdate
= 'today'; +------------+------------+ | sunrise | sunset | +------------+------------+ | 6:32:42 AM | 5:30:55 PM | +------------+------------+ 1 row selected (2.545 seconds) apache drill> use sunrise; +------+-------------------------------------+ | ok | summary | +------+-------------------------------------+ | true | Default schema changed to [sunrise] | +------+-------------------------------------+ 1 row selected (0.188 seconds) apache drill (sunrise)> SELECT sunrise, sunset FROM sunrise.sunrise WHERElat
= 36.7201600 ANDlng
= -4.4203400 ANDdate
= 'today'; +------------+------------+ | sunrise | sunset | +------------+------------+ | 6:32:42 AM | 5:30:55 PM | +------------+------------+ 1 row selected (1.146 seconds) apache drill (sunrise)> SELECT sunrise, sunset FROM sunrise WHERElat
= 36.7201600 ANDlng
= -4.4203400 ANDdate
= 'today'; +------------+------------+ | sunrise | sunset | +------------+------------+ | 6:32:42 AM | 5:30:55 PM | +------------+------------+ 1 row selected (1.143 seconds) apache drill (sunrise)> SELECT version FROM sys.version; Error: CONNECTION ERROR: API 'sys' does not exist in HTTP storage plugin 'sunrise'[Error Id: 8cb31758-252b-4949-a30e-100b469d2476 ] (state=,code=0) apache drill (sunrise)> use sys; Error: CONNECTION ERROR: API 'sys' does not exist in HTTP storage plugin 'sunrise'
[Error Id: 3d1e62b3-f395-4509-9001-5a47376e6063 ] (state=,code=0) apache drill (sunrise)> !schemas +--------------------+---------------+ | TABLE_SCHEM | TABLE_CATALOG | +--------------------+---------------+ | cp.default | DRILL | | dfs.default | DRILL | | dfs.root | DRILL | | dfs.tmp | DRILL | | information_schema | DRILL | | sunrise | DRILL | | sys | DRILL | +--------------------+---------------+ apache drill (sunrise)> !quit ➜ tmp
Before submitting a bug report, please verify that you are using the most current version of Drill.
Describe the bug i create a http plugin named "http" and then use "use http" command to switch schema. i query http Data with "select * from http.sunrise",It report except
To Reproduce Steps to reproduce the behavior:
Expected behavior
Error detail, log output or screenshots
Error: CONNECTION ERROR: API 'http' does not exist in HTTP storage plugin 'http'
Drill version 1.22.0
Additional context