|
|
@@ -29,6 +29,8 @@ from desktop.api2 import __paginate
|
|
|
from desktop.lib.i18n import smart_str
|
|
|
from desktop.lib.django_util import JsonResponse
|
|
|
from desktop.models import Document2, Document
|
|
|
+from indexer.file_format import HiveFormat
|
|
|
+from indexer.fields import Field
|
|
|
|
|
|
from notebook.connectors.base import get_api, Notebook, QueryExpired, SessionExpired, QueryError, _get_snippet_name
|
|
|
from notebook.connectors.dataeng import DataEngApi
|
|
|
@@ -704,68 +706,27 @@ def export_result(request):
|
|
|
'allowed': True
|
|
|
}
|
|
|
elif data_format == 'search-index':
|
|
|
- # Open the result in the Dashboard via a SQL sub-query or the Import wizard (and its quick or scalable indexer)
|
|
|
-
|
|
|
+ # Open the result in the Dashboard via a SQL sub-query or the Import wizard (quick vs scalable)
|
|
|
if is_embedded:
|
|
|
notebook_id = notebook['id'] or request.GET.get('editor', request.GET.get('notebook'))
|
|
|
|
|
|
- if destination == '__hue__':
|
|
|
+ if destination == '__hue__':
|
|
|
engine = notebook['type'].replace('query-', '')
|
|
|
response['watch_url'] = reverse('dashboard:browse', kwargs={'name': notebook_id}) + '?source=query&engine=%(engine)s' % {'engine': engine}
|
|
|
response['status'] = 0
|
|
|
- return JsonResponse(response) # Currently do not live index into Solr, but uses a SQL sub-query
|
|
|
-
|
|
|
- destination = _get_snippet_name(notebook, unique=True, table_format=True)
|
|
|
-# live_indexing = True
|
|
|
else:
|
|
|
- live_indexing = False
|
|
|
-
|
|
|
-
|
|
|
- ## TODO
|
|
|
- ## Add to response query id and sample data
|
|
|
-
|
|
|
- sample = get_api(request, snippet).fetch_result(notebook, snippet, rows=4, start_over=True)
|
|
|
-
|
|
|
-# from indexer.api3 import _index # Will be moved to the lib
|
|
|
- from indexer.file_format import HiveFormat
|
|
|
- from indexer.fields import Field
|
|
|
- format_ = {
|
|
|
- "sample": list(sample['data']),
|
|
|
- "columns": [
|
|
|
- Field(col['name'], HiveFormat.FIELD_TYPE_TRANSLATE.get(col['type'], 'string')).to_dict()
|
|
|
- for col in sample['meta']
|
|
|
- ]
|
|
|
- }
|
|
|
-
|
|
|
- return JsonResponse({
|
|
|
- 'status': 0,
|
|
|
- 'id': notebook_id,
|
|
|
- 'source_type': 'query',
|
|
|
- 'target_type': 'index',
|
|
|
- 'target_path': destination,
|
|
|
- 'sample': format_['sample'],
|
|
|
- 'columns': format_['columns']
|
|
|
- })
|
|
|
+ sample = get_api(request, snippet).fetch_result(notebook, snippet, rows=4, start_over=True)
|
|
|
|
|
|
-# file_format = {
|
|
|
-# 'name': 'col',
|
|
|
-# 'inputFormat': 'query',
|
|
|
-# 'format': {'quoteChar': '"', 'recordSeparator': '\n', 'type': 'csv', 'hasHeader': False, 'fieldSeparator': '\u0001'},
|
|
|
-# "sample": '',
|
|
|
-# "columns": [
|
|
|
-# Field(col['name'].rsplit('.')[-1], HiveFormat.FIELD_TYPE_TRANSLATE.get(col['type'], 'string')).to_dict()
|
|
|
-# for col in sample['meta']
|
|
|
-# ]
|
|
|
-# }
|
|
|
-
|
|
|
-# if live_indexing:
|
|
|
-# file_format['inputFormat'] = 'hs2_handle'
|
|
|
-# file_format['fetch_handle'] = lambda rows, start_over: get_api(request, snippet).fetch_result(notebook, snippet, rows=rows, start_over=start_over)
|
|
|
-# response['rowcount'] = _index(request, file_format, destination, query=notebook['uuid'], start_time=start_time)
|
|
|
-# response['watch_url'] = reverse('search:browse', kwargs={'name': destination})
|
|
|
-# response['status'] = 0
|
|
|
-# else:
|
|
|
-# response = _index(request, file_format, destination, query=notebook['uuid'], start_time=start_time)
|
|
|
+ response['status'] = 0
|
|
|
+ response['id'] = notebook_id
|
|
|
+ response['source_type'] = 'query'
|
|
|
+ response['target_type'] = 'index'
|
|
|
+ response['target_path'] = destination
|
|
|
+ response['sample'] = list(sample['data'])
|
|
|
+ response['columns'] = [
|
|
|
+ Field(col['name'], HiveFormat.FIELD_TYPE_TRANSLATE.get(col['type'], 'string')).to_dict()
|
|
|
+ for col in sample['meta']
|
|
|
+ ]
|
|
|
else:
|
|
|
notebook_id = notebook['id'] or request.GET.get('editor', request.GET.get('notebook'))
|
|
|
response['watch_url'] = reverse('notebook:execute_and_watch') + '?action=index_query¬ebook=' + str(notebook_id) + '&snippet=0&destination=' + destination
|