소스 검색

HUE-9441 [editor] Support empty database URLs for Notebook and Table Browser APIs

Johan Ahlen 5 년 전
부모
커밋
c7009e8ea3

+ 15 - 15
apps/metastore/src/metastore/urls.py

@@ -23,20 +23,20 @@ urlpatterns = [
 
   url(r'^databases/?$', metastore_views.databases, name='databases'),
   url(r'^databases/drop/?$', metastore_views.drop_database, name='drop_database'),
-  url(r'^databases/(?P<database>\w+)/alter$', metastore_views.alter_database, name='alter_database'),
-  url(r'^databases/(?P<database>\w+)/metadata$', metastore_views.get_database_metadata, name='get_database_metadata'),
+  url(r'^databases/(?P<database>[^/?]*)/alter$', metastore_views.alter_database, name='alter_database'),
+  url(r'^databases/(?P<database>[^/?]*)/metadata$', metastore_views.get_database_metadata, name='get_database_metadata'),
 
-  url(r'^tables(?:/(?P<database>\w+))?/?$', metastore_views.show_tables, name='show_tables'),
-  url(r'^tables/drop/(?P<database>\w+)$', metastore_views.drop_table, name='drop_table'),
-  url(r'^table/(?P<database>\w+)/(?P<table>\w+)/?$', metastore_views.describe_table, name='describe_table'),
-  url(r'^table/(?P<database>\w+)/(?P<table>\w+)/alter$', metastore_views.alter_table, name='alter_table'),
-  url(r'^table/(?P<database>\w+)/(?P<table>\w+)/metadata$', metastore_views.get_table_metadata, name='get_table_metadata'),
-  url(r'^table/(?P<database>\w+)/(?P<table>\w+)/load$', metastore_views.load_table, name='load_table'),
-  url(r'^table/(?P<database>\w+)/(?P<table>\w+)/read$', metastore_views.read_table, name='read_table'),
-  url(r'^table/(?P<database>\w+)/(?P<table>\w+)/queries$', metastore_views.table_queries, name='table_queries'),
-  url(r'^table/(?P<database>\w+)/(?P<table>\w+)/partitions/?$', metastore_views.describe_partitions, name='describe_partitions'),
-  url(r'^table/(?P<database>\w+)/(?P<table>\w+)/partitions/(?P<partition_spec>.+?)/read$', metastore_views.read_partition, name='read_partition'),
-  url(r'^table/(?P<database>\w+)/(?P<table>\w+)/partitions/(?P<partition_spec>.+?)/browse$', metastore_views.browse_partition, name='browse_partition'),
-  url(r'^table/(?P<database>\w+)/(?P<table>\w+)/partitions/drop$', metastore_views.drop_partition, name='drop_partition'),
-  url(r'^table/(?P<database>\w+)/(?P<table>\w+)/alter_column$', metastore_views.alter_column, name='alter_column'),
+  url(r'^tables(?:/(?P<database>[^/?]*))?/?$', metastore_views.show_tables, name='show_tables'),
+  url(r'^tables/drop/(?P<database>[^/?]*)$', metastore_views.drop_table, name='drop_table'),
+  url(r'^table/(?P<database>[^/?]*)/(?P<table>\w+)/?$', metastore_views.describe_table, name='describe_table'),
+  url(r'^table/(?P<database>[^/?]*)/(?P<table>\w+)/alter$', metastore_views.alter_table, name='alter_table'),
+  url(r'^table/(?P<database>[^/?]*)/(?P<table>\w+)/metadata$', metastore_views.get_table_metadata, name='get_table_metadata'),
+  url(r'^table/(?P<database>[^/?]*)/(?P<table>\w+)/load$', metastore_views.load_table, name='load_table'),
+  url(r'^table/(?P<database>[^/?]*)/(?P<table>\w+)/read$', metastore_views.read_table, name='read_table'),
+  url(r'^table/(?P<database>[^/?]*)/(?P<table>\w+)/queries$', metastore_views.table_queries, name='table_queries'),
+  url(r'^table/(?P<database>[^/?]*)/(?P<table>\w+)/partitions/?$', metastore_views.describe_partitions, name='describe_partitions'),
+  url(r'^table/(?P<database>[^/?]*)/(?P<table>\w+)/partitions/(?P<partition_spec>.+?)/read$', metastore_views.read_partition, name='read_partition'),
+  url(r'^table/(?P<database>[^/?]*)/(?P<table>\w+)/partitions/(?P<partition_spec>.+?)/browse$', metastore_views.browse_partition, name='browse_partition'),
+  url(r'^table/(?P<database>[^/?]*)/(?P<table>\w+)/partitions/drop$', metastore_views.drop_partition, name='drop_partition'),
+  url(r'^table/(?P<database>[^/?]*)/(?P<table>\w+)/alter_column$', metastore_views.alter_column, name='alter_column'),
 ]

+ 6 - 4
desktop/core/src/desktop/js/api/apiHelper.js

@@ -1267,10 +1267,10 @@ class ApiHelper {
     } else {
       let url = URLS.AUTOCOMPLETE_API_PREFIX;
       if (options.databaseName) {
-        url += options.databaseName;
+        url += options.databaseName + '/';
       }
       if (options.tableName) {
-        url += '/' + options.tableName;
+        url += options.tableName + '/';
       }
       if (options.fields) {
         url += options.fields.length > 0 ? '/' + options.fields.join('/') : '';
@@ -1338,7 +1338,9 @@ class ApiHelper {
     const request = $.ajax({
       type: 'POST',
       url:
-        URLS.AUTOCOMPLETE_API_PREFIX + (isQuery ? options.path.slice(1) : options.path).join('/'),
+        URLS.AUTOCOMPLETE_API_PREFIX +
+        (isQuery ? options.path.slice(1) : options.path).join('/') +
+        (options.path.length ? '/' : ''),
       data: {
         notebook: {},
         snippet: ko.mapping.toJSON({
@@ -2145,7 +2147,7 @@ class ApiHelper {
     };
 
     simplePost(
-      URLS.SAMPLE_API_PREFIX + options.path.join('/'),
+      URLS.SAMPLE_API_PREFIX + options.path.join('/') + (options.path.length ? '/' : ''),
       {
         notebook: {},
         snippet: JSON.stringify({

+ 1 - 1
desktop/core/src/desktop/js/sql/reference/apiUtils.ts

@@ -128,7 +128,7 @@ const createUrl = (database?: string, udf?: UdfDetails): string => {
     return `${AUTOCOMPLETE_API_PREFIX}${database}/${udf.name}`;
   }
   if (database) {
-    return `${AUTOCOMPLETE_API_PREFIX}${database}`;
+    return `${AUTOCOMPLETE_API_PREFIX}${database}/`;
   }
   if (udf) {
     return `${AUTOCOMPLETE_API_PREFIX}${udf.name}`;

+ 15 - 15
desktop/libs/notebook/src/notebook/urls.py

@@ -35,7 +35,7 @@ urlpatterns = [
 
   url(r'^editor/?$', notebook_views.editor, name='editor'),
   url(r'^editor_m/?$', notebook_views.editor_m, name='editor_m'),
-  url(r'^browse/(?P<database>\w+)/(?P<table>\w+)(?:/(?P<partition_spec>.+?))?/?$', notebook_views.browse, name='browse'),
+  url(r'^browse/(?P<database>[^/?]+)/(?P<table>\w+)(?:/(?P<partition_spec>.+?))?/?$', notebook_views.browse, name='browse'),
   url(r'^execute_and_watch/?$', notebook_views.execute_and_watch, name='execute_and_watch'),
 ]
 
@@ -75,24 +75,24 @@ urlpatterns += [
 urlpatterns += [
   # HS2, RDBMS, JDBC
   url(r'^api/autocomplete/?$', notebook_api.autocomplete, name='api_autocomplete_databases'),
-  url(r'^api/autocomplete/(?P<database>[\w_]+)/?$', notebook_api.autocomplete, name='api_autocomplete_tables'),
-  url(r'^api/autocomplete/(?P<database>[\w_]+)/(?P<table>[\w_\-]+)/?$', notebook_api.autocomplete, name='api_autocomplete_columns'),
-  url(r'^api/autocomplete/(?P<database>[\w_]+)/(?P<table>[\w_\-]+)/(?P<column>\w+)/?$', notebook_api.autocomplete, name='api_autocomplete_column'),
-  url(r'^api/autocomplete/(?P<database>[\w_]+)/(?P<table>[\w_\-]+)/(?P<column>\w+)/(?P<nested>.+)/?$', notebook_api.autocomplete, name='api_autocomplete_nested'),
-  url(r'^api/sample/(?P<database>[\w_]+)/(?P<table>[\w_\-]+)/?$', notebook_api.get_sample_data, name='api_sample_data'),
-  url(r'^api/sample/(?P<database>[\w_]+)/(?P<table>[\w_\-]+)/(?P<column>\w+)/?$', notebook_api.get_sample_data, name='api_sample_data_column'),
+  url(r'^api/autocomplete/(?P<database>[^/?]*)/?$', notebook_api.autocomplete, name='api_autocomplete_tables'),
+  url(r'^api/autocomplete/(?P<database>[^/?]*)/(?P<table>[\w_\-]+)/?$', notebook_api.autocomplete, name='api_autocomplete_columns'),
+  url(r'^api/autocomplete/(?P<database>[^/?]*)/(?P<table>[\w_\-]+)/(?P<column>\w+)/?$', notebook_api.autocomplete, name='api_autocomplete_column'),
+  url(r'^api/autocomplete/(?P<database>[^/?]*)/(?P<table>[\w_\-]+)/(?P<column>\w+)/(?P<nested>.+)/?$', notebook_api.autocomplete, name='api_autocomplete_nested'),
+  url(r'^api/sample/(?P<database>[^/?]*)/(?P<table>[\w_\-]+)/?$', notebook_api.get_sample_data, name='api_sample_data'),
+  url(r'^api/sample/(?P<database>[^/?]*)/(?P<table>[\w_\-]+)/(?P<column>\w+)/?$', notebook_api.get_sample_data, name='api_sample_data_column'),
 
   # SQLite
-  url(r'^api/autocomplete//?(?P<server>[\w_\-/]+)/(?P<database>[\w._\-0-9]+)/?$', notebook_api.autocomplete, name='api_autocomplete_tables'),
-  url(r'^api/autocomplete//?(?P<server>[\w_\-/]+)/(?P<database>[\w._\-0-9]+)/(?P<table>\w+)/?$', notebook_api.autocomplete, name='api_autocomplete_columns'),
-  url(r'^api/autocomplete//?(?P<server>[\w_\-/]+)/(?P<database>[\w._\-0-9]+)/(?P<table>\w+)/(?P<column>\w+)/?$', notebook_api.autocomplete, name='api_autocomplete_column'),
-  url(r'^api/sample/(?P<server>[\w_\-/]+)/(?P<database>[\w._\-0-9]+)/(?P<table>\w+)/?$', notebook_api.get_sample_data, name='api_sample_data'),
-  url(r'^api/sample/(?P<server>[\w_\-/]+)/(?P<database>[\w._\-0-9]+)/(?P<table>\w+)/(?P<column>\w+)/?$', notebook_api.get_sample_data, name='api_sample_data_column'),
+  url(r'^api/autocomplete//?(?P<server>[\w_\-/]+)/(?P<database>[^/?]*)/?$', notebook_api.autocomplete, name='api_autocomplete_tables'),
+  url(r'^api/autocomplete//?(?P<server>[\w_\-/]+)/(?P<database>[^/?]*)/(?P<table>\w+)/?$', notebook_api.autocomplete, name='api_autocomplete_columns'),
+  url(r'^api/autocomplete//?(?P<server>[\w_\-/]+)/(?P<database>[^/?]*)/(?P<table>\w+)/(?P<column>\w+)/?$', notebook_api.autocomplete, name='api_autocomplete_column'),
+  url(r'^api/sample/(?P<server>[\w_\-/]+)/(?P<database>[^/?]*)/(?P<table>\w+)/?$', notebook_api.get_sample_data, name='api_sample_data'),
+  url(r'^api/sample/(?P<server>[\w_\-/]+)/(?P<database>[^/?]*)/(?P<table>\w+)/(?P<column>\w+)/?$', notebook_api.get_sample_data, name='api_sample_data_column'),
 ]
 
 # Table API
 urlpatterns += [
-  url(r'^api/describe/(?P<database>\w+)/?$', notebook_api.describe, name='api_describe_database'),
-  url(r'^api/describe/(?P<database>\w+)/(?P<table>[\w_\-]+)/?$', notebook_api.describe, name='api_describe_table'),
-  url(r'^api/describe/(?P<database>\w+)/(?P<table>\w+)/stats(?:/(?P<column>\w+))?/?$', notebook_api.describe, name='api_describe_column'),
+  url(r'^api/describe/(?P<database>[^/]*)/?$', notebook_api.describe, name='api_describe_database'),
+  url(r'^api/describe/(?P<database>[^/]*)/(?P<table>[\w_\-]+)/?$', notebook_api.describe, name='api_describe_table'),
+  url(r'^api/describe/(?P<database>[^/]*)/(?P<table>\w+)/stats(?:/(?P<column>\w+))?/?$', notebook_api.describe, name='api_describe_column'),
 ]