浏览代码

[api] Port impala/api/analyze to public API (#2316)

- Do not hardcode impala in API Url
- Send empty HttpResponse for not supported dialects
Harsh Gupta 4 年之前
父节点
当前提交
61f7ce9ad6

+ 14 - 1
desktop/core/src/desktop/api_public.py

@@ -17,7 +17,7 @@
 
 import logging
 
-from django.http import QueryDict
+from django.http import QueryDict, HttpResponse
 from rest_framework.decorators import api_view
 
 from filebrowser import views as filebrowser_views
@@ -29,6 +29,8 @@ from desktop import api2 as desktop_api
 from desktop.auth.backend import rewrite_user
 from desktop.lib import fsmanager
 
+from beeswax import api as beeswax_api
+
 
 LOG = logging.getLogger(__name__)
 
@@ -159,6 +161,16 @@ def get_history(request):
   django_request = get_django_request(request)
   return notebook_api.get_history(django_request)
 
+@api_view(["POST"])
+def analyze_table(request, dialect, database, table, columns=None):
+  django_request = get_django_request(request)
+
+  if dialect in ["impala", "beeswax"]:
+    return beeswax_api.analyze_table(django_request, database, table, columns=None)
+  else:
+    return HttpResponse(status=204)
+
+
 # Storage API
 
 @api_view(["GET"])
@@ -188,6 +200,7 @@ def guess_field_types(request):
   django_request = get_django_request(request)
   return indexer_api3.guess_field_types(django_request)
 
+
 # Utils
 
 def _get_interpreter_from_dialect(dialect, user):

+ 4 - 0
desktop/core/src/desktop/api_public_urls.py

@@ -92,6 +92,10 @@ urlpatterns += [
   re_path(r'^storage/upload/file/?$', api_public.storage_upload_file, name='storage_upload_file'),
 ]
 
+urlpatterns += [
+  re_path(r'^(?P<dialect>.+)/analyze/(?P<database>\w+)/(?P<table>\w+)(?:/(?P<columns>\w+))?/?$', api_public.analyze_table, name='dialect_analyze_table'),
+]
+
 # Slack install API for using CORS by default
 urlpatterns += [
   re_path(r'^slack/install/?$', botserver_api.generate_slack_install_link, name='botserver.api.slack_install_link'),

+ 2 - 2
desktop/core/src/desktop/js/catalog/api.ts

@@ -104,9 +104,9 @@ const performAnalyze = ({
     });
     try {
       const analyzeResponse = await post<DefaultApiResponse & { watch_url?: string }>(
-        `/${
+        `/api/${
           entry.getConnector().id === 'hive' ? 'beeswax' : entry.getConnector().id
-        }/api/analyze/${getEntryUrlPath(entry)}`,
+        }/analyze/${getEntryUrlPath(entry)}`,
         undefined,
         { silenceErrors }
       );