Beispiel #1
0
Datei: views.py Projekt: RoxC/hue
def editor(request):
  editor_id = request.GET.get('editor')

  if editor_id:
    editor = Notebook(document=Document2.objects.get(id=editor_id))
  else:
    editor = Notebook()
    data = editor.get_data()
    data['name'] = 'Hive SQL Editor'
    data['snippets'] = json.loads('[{"id":"c111cbb4-f475-4050-c5a1-02df6c31e3d8","name":"","type":"hive","editorMode":"text/x-hiveql","statement_raw":"Example: SELECT * FROM tablename, or press CTRL + space","codemirrorSize":100,"status":"ready","properties":{"settings":[],"files":[]},"variables":[],"variableNames":[],"statement":"Example: SELECT * FROM tablename, or press CTRL + space","result":{"id":"149347d9-3ae7-8d06-4cc8-d4bce5e72dc8","type":"table","hasResultset":true,"handle":{},"meta":[],"cleanedMeta":[],"fetchedOnce":false,"startTime":"2015-07-17T20:38:21.970Z","endTime":"2015-07-17T20:38:21.970Z","executionTime":0,"cleanedNumericMeta":[],"cleanedStringMeta":[],"cleanedDateTimeMeta":[],"data":[],"logs":"","logLines":0,"errors":"","hasSomeResults":false},"showGrid":true,"showChart":false,"showLogs":false,"progress":0,"size":12,"offset":0,"isLoading":false,"klass":"snippet card card-widget","editorKlass":"editor span12","resultsKlass":"results hive","errorsKlass":"results hive alert alert-error","chartType":"bars","chartSorting":"none","chartYMulti":[],"chartData":[],"tempChartOptions":{},"isLeftPanelVisible":false,"codeVisible":true,"settingsVisible":false,"checkStatusTimeout":null}]')
    editor.data = json.dumps(data)

  autocomplete_base_url = ''
  try:
    autocomplete_base_url = reverse('beeswax:api_autocomplete_databases', kwargs={})
  except:
    LOG.exception('failed to get autocomplete base url')

  return render('editor.mako', request, {
      'notebooks_json': json.dumps([editor.get_data()]),
      'options_json': json.dumps({
          'languages': [{"name": "Hive SQL", "type": "hive"}],
          'snippet_placeholders' : {
              'scala': _('Example: 1 + 1, or press CTRL + space'),
              'python': _('Example: 1 + 1, or press CTRL + space'),
              'impala': _('Example: SELECT * FROM tablename, or press CTRL + space'),
              'hive': _('Example: SELECT * FROM tablename, or press CTRL + space'),
              'text': _('<h2>This is a text snippet</h2>Type your text here')
          }
      }),
      'autocomplete_base_url': autocomplete_base_url,
  })
Beispiel #2
0
def editor(request):
  editor_id = request.GET.get('editor')
  editor_type = request.GET.get('type', 'hive')

  if editor_id:
    editor = Notebook(document=Document2.objects.get(id=editor_id))
  else:
    editor = Notebook()
    data = editor.get_data()
    data['name'] = 'Untitled %s Query' % editor_type.title()
    data['type'] = 'query-%s' % editor_type
    editor.data = json.dumps(data)

  autocomplete_base_url = ''
  try:
    autocomplete_base_url = reverse('beeswax:api_autocomplete_databases', kwargs={})
  except:
    LOG.exception('failed to get autocomplete base url')

  return render('editor.mako', request, {
      'notebooks_json': json.dumps([editor.get_data()]),
      'options_json': json.dumps({
          'languages': [{"name": "%s SQL" % editor_type.title(), "type": editor_type}],
          'mode': 'editor',
      }),
      'editor_type': editor_type,
      'autocomplete_base_url': autocomplete_base_url,
  })
Beispiel #3
0
def create_notebook(request):
    response = {'status': -1}

    editor_type = request.POST.get('type', 'notebook')
    gist_id = request.POST.get('gist')
    directory_uuid = request.POST.get('directory_uuid')

    if gist_id:
        gist_doc = _get_gist_document(uuid=gist_id)
        statement = json.loads(gist_doc.data)['statement']

        editor = make_notebook(name='',
                               description='',
                               editor_type=editor_type,
                               statement=statement,
                               is_presentation_mode=True)
    else:
        editor = Notebook()

    data = editor.get_data()

    if editor_type != 'notebook':
        data['name'] = ''
        data[
            'type'] = 'query-%s' % editor_type  # TODO: Add handling for non-SQL types

    data['directoryUuid'] = directory_uuid
    editor.data = json.dumps(data)

    response['notebook'] = editor.get_data()
    response['status'] = 0

    return JsonResponse(response)
Beispiel #4
0
def editor(request):
  editor_id = request.GET.get('editor')
  editor_type = request.GET.get('type', 'hive')

  if editor_id:  # Open existing saved editor document
    editor = Notebook(document=Document2.objects.get(id=editor_id))
    editor_type = editor.get_data()['type'].rsplit('-', 1)[-1]
    editor = upgrade_session_properties(request, notebook=editor)
  else:  # Create new editor
    editor = Notebook()
    data = editor.get_data()

    data['name'] = ''
    data['type'] = 'query-%s' % editor_type  # TODO: Add handling for non-SQL types
    editor.data = json.dumps(data)

  return render('editor.mako', request, {
      'notebooks_json': json.dumps([editor.get_data()]),
      'options_json': json.dumps({
          'languages': [{"name": "%s SQL" % editor_type.title(), "type": editor_type}],
          'mode': 'editor',
          'is_optimizer_enabled': has_optimizer(),
      }),
      'editor_type': editor_type,
  })
Beispiel #5
0
def editor(request):
    editor_id = request.GET.get('editor')
    editor_type = request.GET.get('type', 'hive')

    if editor_id:
        editor = Notebook(document=Document2.objects.get(id=editor_id))
        editor_type = editor.get_data()['type'].rsplit('-', 1)[-1]
    else:
        editor = Notebook()
        data = editor.get_data()
        data['name'] = 'Untitled %s Query' % editor_type.title()
        data['type'] = 'query-%s' % editor_type
        editor.data = json.dumps(data)

    return render(
        'editor.mako', request, {
            'notebooks_json':
            json.dumps([editor.get_data()]),
            'options_json':
            json.dumps({
                'languages': [{
                    "name": "%s SQL" % editor_type.title(),
                    "type": editor_type
                }],
                'mode':
                'editor',
            }),
            'editor_type':
            editor_type,
        })
Beispiel #6
0
def editor(request):
    editor_id = request.GET.get('editor')
    editor_type = request.GET.get('type', 'hive')

    if editor_id:  # Open existing saved editor document
        editor = Notebook(document=Document2.objects.get(id=editor_id))
        editor_type = editor.get_data()['type'].rsplit('-', 1)[-1]
        editor = upgrade_session_properties(request, notebook=editor)
    else:  # Create new editor
        editor = Notebook()
        data = editor.get_data()

        data['name'] = ''
        data[
            'type'] = 'query-%s' % editor_type  # TODO: Add handling for non-SQL types
        editor.data = json.dumps(data)

    return render(
        'editor.mako', request, {
            'notebooks_json':
            json.dumps([editor.get_data()]),
            'options_json':
            json.dumps({
                'languages': [{
                    "name": "%s SQL" % editor_type.title(),
                    "type": editor_type
                }],
                'mode':
                'editor',
                'is_optimizer_enabled':
                has_optimizer(),
            }),
            'editor_type':
            editor_type,
        })
Beispiel #7
0
def editor(request):
    editor_id = request.GET.get('editor')

    if editor_id:
        editor = Notebook(document=Document2.objects.get(id=editor_id))
    else:
        editor = Notebook()
        data = editor.get_data()
        data['name'] = 'Hive SQL Editor'
        data['snippets'] = json.loads(
            '[{"id":"c111cbb4-f475-4050-c5a1-02df6c31e3d8","name":"","type":"hive","editorMode":"text/x-hiveql","statement_raw":"Example: SELECT * FROM tablename, or press CTRL + space","codemirrorSize":100,"status":"ready","properties":{"settings":[],"files":[]},"variables":[],"variableNames":[],"statement":"Example: SELECT * FROM tablename, or press CTRL + space","result":{"id":"149347d9-3ae7-8d06-4cc8-d4bce5e72dc8","type":"table","hasResultset":true,"handle":{},"meta":[],"cleanedMeta":[],"fetchedOnce":false,"startTime":"2015-07-17T20:38:21.970Z","endTime":"2015-07-17T20:38:21.970Z","executionTime":0,"cleanedNumericMeta":[],"cleanedStringMeta":[],"cleanedDateTimeMeta":[],"data":[],"logs":"","logLines":0,"errors":"","hasSomeResults":false},"showGrid":true,"showChart":false,"showLogs":false,"progress":0,"size":12,"offset":0,"isLoading":false,"klass":"snippet card card-widget","editorKlass":"editor span12","resultsKlass":"results hive","errorsKlass":"results hive alert alert-error","chartType":"bars","chartSorting":"none","chartYMulti":[],"chartData":[],"tempChartOptions":{},"isLeftPanelVisible":false,"codeVisible":true,"settingsVisible":false,"checkStatusTimeout":null}]'
        )
        editor.data = json.dumps(data)

    autocomplete_base_url = ''
    try:
        autocomplete_base_url = reverse('beeswax:api_autocomplete_databases',
                                        kwargs={})
    except:
        LOG.exception('failed to get autocomplete base url')

    return render(
        'editor.mako', request, {
            'notebooks_json':
            json.dumps([editor.get_data()]),
            'options_json':
            json.dumps({
                'languages': [{
                    "name": "Hive SQL",
                    "type": "hive"
                }],
                'snippet_placeholders': {
                    'scala':
                    _('Example: 1 + 1, or press CTRL + space'),
                    'python':
                    _('Example: 1 + 1, or press CTRL + space'),
                    'impala':
                    _('Example: SELECT * FROM tablename, or press CTRL + space'
                      ),
                    'hive':
                    _('Example: SELECT * FROM tablename, or press CTRL + space'
                      ),
                    'text':
                    _('<h2>This is a text snippet</h2>Type your text here')
                }
            }),
            'autocomplete_base_url':
            autocomplete_base_url,
        })
Beispiel #8
0
def notebook(request):
  notebook_id = request.GET.get('notebook')

  if notebook_id:
    notebook = Notebook(document=Document2.objects.get(id=notebook_id))
  else:
    notebook = Notebook()

  autocomplete_base_url = ''
  try:
    autocomplete_base_url = reverse('beeswax:api_autocomplete_databases', kwargs={})
  except:
    LOG.exception('failed to get autocomplete base url')

  is_yarn_mode = False
  try:
    from spark.conf import LIVY_SERVER_SESSION_KIND
    is_yarn_mode = LIVY_SERVER_SESSION_KIND.get()
  except:
    LOG.exception('Spark is not enabled')

  return render('notebook.mako', request, {
      'notebooks_json': json.dumps([notebook.get_data()]),
      'options_json': json.dumps({
          'languages': get_interpreters(request.user),
          'session_properties': SparkApi.PROPERTIES,
      }),
      'autocomplete_base_url': autocomplete_base_url,
      'is_yarn_mode': is_yarn_mode
  })
Beispiel #9
0
def notebook(request):
    notebook_id = request.GET.get('notebook')

    if notebook_id:
        notebook = Notebook(document=Document2.objects.get(id=notebook_id))
    else:
        notebook = Notebook()

    is_yarn_mode = False
    try:
        from spark.conf import LIVY_SERVER_SESSION_KIND
        is_yarn_mode = LIVY_SERVER_SESSION_KIND.get()
    except:
        LOG.exception('Spark is not enabled')

    return render(
        'notebook.mako', request, {
            'notebooks_json':
            json.dumps([notebook.get_data()]),
            'options_json':
            json.dumps({
                'languages': get_interpreters(request.user),
                'session_properties': SparkApi.PROPERTIES,
            }),
            'is_yarn_mode':
            is_yarn_mode
        })
Beispiel #10
0
def execute_and_watch(request):
  notebook_id = request.GET.get('editor', request.GET.get('notebook'))
  snippet_id = int(request.GET['snippet'])
  action = request.GET['action']
  destination = request.GET['destination']

  notebook = Notebook(document=Document2.objects.get(id=notebook_id))
  snippet = notebook.get_data()['snippets'][snippet_id]
  editor_type = snippet['type']

  api = get_api(request, snippet)

  if action == 'save_as_table':
    sql, success_url = api.export_data_as_table(snippet, destination)
    editor = make_notebook(name='Execute and watch', editor_type=editor_type, statement=sql, status='ready-execute')
  elif action == 'insert_as_query':
    sql, success_url = api.export_large_data_to_hdfs(snippet, destination)
    editor = make_notebook(name='Execute and watch', editor_type=editor_type, statement=sql, status='ready-execute')
  else:
    raise PopupException(_('Action %s is unknown') % action)

  return render('editor.mako', request, {
      'notebooks_json': json.dumps([editor.get_data()]),
      'options_json': json.dumps({
          'languages': [{"name": "%s SQL" % editor_type.title(), "type": editor_type}],
          'mode': 'editor',
          'success_url': success_url
      }),
      'editor_type': editor_type,
  })
Beispiel #11
0
def action_parameters(request):
  response = {'status': -1}
  parameters = set()

  try:
    node_data = json.loads(request.POST.get('node', '{}'))

    parameters = parameters.union(set(Node(node_data).find_parameters()))

    script_path = node_data.get('properties', {}).get('script_path', {})
    if script_path:
      script_path = script_path.replace('hdfs://', '')

      if request.fs.do_as_user(request.user, request.fs.exists, script_path):
        data = request.fs.do_as_user(request.user, request.fs.read, script_path, 0, 16 * 1024 ** 2)

        if node_data['type'] in ('hive', 'hive2'):
          parameters = parameters.union(set(find_dollar_braced_variables(data)))
        elif node_data['type'] == 'pig':
          parameters = parameters.union(set(find_dollar_variables(data)))
    elif node_data['type'] == 'hive-document':
      notebook = Notebook(document=Document2.objects.get_by_uuid(user=request.user, uuid=node_data['properties']['uuid']))
      parameters = parameters.union(set(find_dollar_braced_variables(notebook.get_str())))
    elif node_data['type'] == 'sqoop-document':
      notebook = Notebook(document=Document2.objects.get_by_uuid(user=request.user, uuid=node_data['properties']['uuid']))
      parameters = parameters.union(set(find_dollar_braced_variables(notebook.get_str())))
    elif node_data['type'] == 'spark-document':
      notebook = Notebook(document=Document2.objects.get_by_uuid(user=request.user, uuid=node_data['properties']['uuid']))
      for arg in notebook.get_data()['snippets'][0]['properties']['spark_arguments']:
        parameters = parameters.union(set(find_dollar_braced_variables(arg)))

    response['status'] = 0
    response['parameters'] = list(parameters)
  except Exception, e:
    response['message'] = str(e)
Beispiel #12
0
def notebook(request):
    notebook_id = request.GET.get("notebook")

    if notebook_id:
        notebook = Notebook(document=Document2.objects.get(id=notebook_id))
    else:
        notebook = Notebook()

    autocomplete_base_url = ""
    try:
        autocomplete_base_url = reverse("beeswax:api_autocomplete_databases", kwargs={})
    except:
        LOG.exception("failed to get autocomplete base url")

    is_yarn_mode = False
    try:
        from spark.conf import LIVY_SERVER_SESSION_KIND

        is_yarn_mode = LIVY_SERVER_SESSION_KIND.get()
    except:
        LOG.exception("Spark is not enabled")

    return render(
        "notebook.mako",
        request,
        {
            "notebooks_json": json.dumps([notebook.get_data()]),
            "options_json": json.dumps(
                {"languages": get_interpreters(request.user), "session_properties": SparkApi.PROPERTIES}
            ),
            "autocomplete_base_url": autocomplete_base_url,
            "is_yarn_mode": is_yarn_mode,
        },
    )
Beispiel #13
0
def notebook(request):
  notebook_id = request.GET.get('notebook')

  if notebook_id:
    notebook = Notebook(document=Document2.objects.get(id=notebook_id))
  else:
    notebook = Notebook()

  autocomplete_base_url = ''
  try:
    autocomplete_base_url = reverse('beeswax:api_autocomplete_databases', kwargs={})
  except:
    LOG.exception('failed to get autocomplete base url')

  return render('notebook.mako', request, {
      'notebooks_json': json.dumps([notebook.get_data()]),
      'options_json': json.dumps({
          'languages': get_interpreters(),
          'snippet_placeholders' : {
              'sql': _('Example: 1 + 1, or press CTRL + space'),
              'spark': _('Example: 1 + 1, or press CTRL + space'),
              'pyspark': _('Example: 1 + 1, or press CTRL + space'),
              'impala': _('Example: SELECT * FROM tablename, or press CTRL + space'),
              'hive': _('Example: SELECT * FROM tablename, or press CTRL + space'),
              'r': _('Example: 1 + 1, or press CTRL + space')
          },
          'session_properties': SparkApi.PROPERTIES
      }),
      'autocomplete_base_url': autocomplete_base_url,
      'is_yarn_mode': LIVY_SERVER_SESSION_KIND.get()
  })
Beispiel #14
0
def action_parameters(request):
  response = {'status': -1}
  parameters = set()

  try:
    node_data = json.loads(request.POST.get('node', '{}'))

    parameters = parameters.union(set(Node(node_data).find_parameters()))

    script_path = node_data.get('properties', {}).get('script_path', {})
    if script_path:
      script_path = script_path.replace('hdfs://', '')

      if request.fs.do_as_user(request.user, request.fs.exists, script_path):
        data = request.fs.do_as_user(request.user, request.fs.read, script_path, 0, 16 * 1024 ** 2)

        if node_data['type'] in ('hive', 'hive2'):
          parameters = parameters.union(set(find_dollar_braced_variables(data)))
        elif node_data['type'] == 'pig':
          parameters = parameters.union(set(find_dollar_variables(data)))
    elif node_data['type'] == 'hive-document':
      notebook = Notebook(document=Document2.objects.get_by_uuid(user=request.user, uuid=node_data['properties']['uuid']))
      parameters = parameters.union(set(find_dollar_braced_variables(notebook.get_str())))
    elif node_data['type'] == 'sqoop-document':
      notebook = Notebook(document=Document2.objects.get_by_uuid(user=request.user, uuid=node_data['properties']['uuid']))
      parameters = parameters.union(set(find_dollar_braced_variables(notebook.get_str())))
    elif node_data['type'] == 'spark-document':
      notebook = Notebook(document=Document2.objects.get_by_uuid(user=request.user, uuid=node_data['properties']['uuid']))
      for arg in notebook.get_data()['snippets'][0]['properties']['spark_arguments']:
        parameters = parameters.union(set(find_dollar_braced_variables(arg)))

    response['status'] = 0
    response['parameters'] = list(parameters)
  except Exception, e:
    response['message'] = str(e)
Beispiel #15
0
def browse(request, database, table):
    editor_type = request.GET.get('type', 'hive')

    snippet = {'type': editor_type}
    sql_select = get_api(request.user, snippet, request.fs,
                         request.jt).get_select_star_query(
                             snippet, database, table)

    editor = Notebook()
    editor.data = json.dumps({
        'description':
        '',
        'sessions': [{
            'type': 'hive',
            'properties': [],
            'id': None
        }],
        'selectedSnippet':
        'hive',
        'type':
        'query-%s' % editor_type,
        'snippets': [{
            'status': 'ready-execute',
            'id': 'e8b323b3-88ef-3a84-6264-af11fa5fbefb',
            'statement_raw': sql_select,
            'statement': sql_select,
            'type': editor_type,
            'properties': {
                'files': [],
                'settings': []
            },
            'name': 'Browse',
            'database': 'default',
            'result': {}
        }],
        'name':
        'Browse'
    })

    return render(
        'editor.mako', request, {
            'notebooks_json':
            json.dumps([editor.get_data()]),
            'options_json':
            json.dumps({
                'languages': [{
                    "name": "%s SQL" % editor_type.title(),
                    "type": editor_type
                }],
                'mode':
                'editor',
            }),
            'editor_type':
            editor_type,
        })
Beispiel #16
0
def create_notebook(request):
  response = {'status': -1}

  editor_type = request.POST.get('type', 'notebook')
  directory_uuid = request.POST.get('directory_uuid')

  editor = Notebook()
  data = editor.get_data()

  if editor_type != 'notebook':
    data['name'] = ''
    data['type'] = 'query-%s' % editor_type  # TODO: Add handling for non-SQL types

  data['directoryUuid'] = directory_uuid
  editor.data = json.dumps(data)

  response['notebook'] = editor.get_data()
  response['status'] = 0

  return JsonResponse(response)
Beispiel #17
0
def create_notebook(request):
  response = {'status': -1}

  editor_type = request.POST.get('type', 'notebook')
  directory_uuid = request.POST.get('directory_uuid')

  editor = Notebook()
  data = editor.get_data()

  if editor_type != 'notebook':
    data['name'] = ''
    data['type'] = 'query-%s' % editor_type  # TODO: Add handling for non-SQL types

  data['directoryUuid'] = directory_uuid
  editor.data = json.dumps(data)

  response['notebook'] = editor.get_data()
  response['status'] = 0

  return JsonResponse(response)
Beispiel #18
0
def create_notebook(request):
    response = {"status": -1}

    editor_type = request.POST.get("type", "notebook")
    directory_uuid = request.POST.get("directory_uuid")

    editor = Notebook()
    data = editor.get_data()

    if editor_type != "notebook":
        data["name"] = ""
        data["type"] = "query-%s" % editor_type  # TODO: Add handling for non-SQL types

    data["directoryUuid"] = directory_uuid
    editor.data = json.dumps(data)

    response["notebook"] = editor.get_data()
    response["status"] = 0

    return JsonResponse(response)
Beispiel #19
0
def editor(request):
  editor_id = request.GET.get('editor')
  editor_type = request.GET.get('type', 'hive')

  if editor_id:
    editor = Notebook(document=Document2.objects.get(id=editor_id))
  else:
    editor = Notebook()
    data = editor.get_data()
    data['name'] = 'Unsaved %s Query' % editor_type.title()
    data['type'] = 'query-%s' % editor_type
    editor.data = json.dumps(data)

  return render('editor.mako', request, {
      'notebooks_json': json.dumps([editor.get_data()]),
      'options_json': json.dumps({
          'languages': [{"name": "%s SQL" % editor_type.title(), "type": editor_type}],
          'mode': 'editor',
      }),
      'editor_type': editor_type,
  })
Beispiel #20
0
def create_notebook(request):
    response = {'status': -1}

    editor_type = request.POST.get('type', 'notebook')
    gist_id = request.POST.get('gist')
    directory_uuid = request.POST.get('directory_uuid')
    is_blank = request.POST.get('blank', 'false') == 'true'

    if gist_id:
        gist_doc = _get_gist_document(uuid=gist_id)
        statement = json.loads(gist_doc.data)['statement']

        editor = make_notebook(name='',
                               description='',
                               editor_type=editor_type,
                               statement=statement,
                               is_presentation_mode=True)
    else:
        editor = Notebook()

        if EXAMPLES.AUTO_OPEN.get() and not is_blank:
            document = _get_dialect_example(dialect=editor_type)
            if document:
                editor = Notebook(document=document)
                editor = upgrade_session_properties(request, editor)

    data = editor.get_data()

    if editor_type != 'notebook':
        data['name'] = ''
        data[
            'type'] = 'query-%s' % editor_type  # TODO: Add handling for non-SQL types

    data['directoryUuid'] = directory_uuid
    editor.data = json.dumps(data)

    response['notebook'] = editor.get_data()
    response['status'] = 0

    return JsonResponse(response)
Beispiel #21
0
def editor(request):
    editor_id = request.GET.get('editor')
    editor_type = request.GET.get('type', 'hive')

    if editor_id:
        editor = Notebook(document=Document2.objects.get(id=editor_id))
    else:
        editor = Notebook()
        data = editor.get_data()
        data['name'] = 'Untitled %s Query' % editor_type.title()
        data['type'] = 'query-%s' % editor_type
        editor.data = json.dumps(data)

    autocomplete_base_url = ''
    try:
        autocomplete_base_url = reverse('beeswax:api_autocomplete_databases',
                                        kwargs={})
    except:
        LOG.exception('failed to get autocomplete base url')

    return render(
        'editor.mako', request, {
            'notebooks_json':
            json.dumps([editor.get_data()]),
            'options_json':
            json.dumps({
                'languages': [{
                    "name": "%s SQL" % editor_type.title(),
                    "type": editor_type
                }],
                'mode':
                'editor',
            }),
            'editor_type':
            editor_type,
            'autocomplete_base_url':
            autocomplete_base_url,
        })
Beispiel #22
0
def browse(request, database, table):
  editor_type = request.GET.get('type', 'hive')

  snippet = {'type': editor_type}
  sql_select = get_api(request.user, snippet, request.fs, request.jt).get_select_star_query(snippet, database, table)

  editor = Notebook()
  editor.data = json.dumps({
    'description':'',
    'sessions':[
      {
         'type':'hive',
         'properties':[

         ],
         'id':None
      }
    ],
    'selectedSnippet':'hive',
    'type': 'query-%s' % editor_type,

    'snippets':[
      {
         'status':'ready-execute',
         'id':'e8b323b3-88ef-3a84-6264-af11fa5fbefb',
         'statement_raw': sql_select,
         'statement': sql_select,
         'type': editor_type,
         'properties':{
            'files':[
            ],
            'settings':[
            ]
         },
         'name': 'Browse',
         'database':'default',
         'result':{  }
      }
    ],
    'name':'Browse'
  })

  return render('editor.mako', request, {
      'notebooks_json': json.dumps([editor.get_data()]),
      'options_json': json.dumps({
          'languages': [{"name": "%s SQL" % editor_type.title(), "type": editor_type}],
          'mode': 'editor',
      }),
      'editor_type': editor_type,
  })
Beispiel #23
0
def editor(request):
  editor_id = request.GET.get('editor')

  if editor_id:
    editor = Notebook(document=Document2.objects.get(id=editor_id))
  else:
    editor = Notebook()
    data = editor.get_data()
    data['name'] = 'My SQL query'
    editor.data = json.dumps(data)

  autocomplete_base_url = ''
  try:
    autocomplete_base_url = reverse('beeswax:api_autocomplete_databases', kwargs={})
  except:
    LOG.exception('failed to get autocomplete base url')

  return render('editor.mako', request, {
      'notebooks_json': json.dumps([editor.get_data()]),
      'options_json': json.dumps({
          'languages': [{"name": "Hive SQL", "type": "hive"}]
      }),
      'autocomplete_base_url': autocomplete_base_url,
  })
Beispiel #24
0
def notebook(request):
  notebook_id = request.GET.get('notebook')

  if notebook_id:
    notebook = Notebook(document=Document2.objects.get(id=notebook_id))
  else:
    notebook = Notebook()

  is_yarn_mode = False
  try:
    from spark.conf import LIVY_SERVER_SESSION_KIND
    is_yarn_mode = LIVY_SERVER_SESSION_KIND.get()
  except:
    LOG.exception('Spark is not enabled')

  return render('notebook.mako', request, {
      'notebooks_json': json.dumps([notebook.get_data()]),
      'options_json': json.dumps({
          'languages': get_interpreters(request.user),
          'session_properties': SparkApi.PROPERTIES,
      }),
      'is_yarn_mode': is_yarn_mode
  })
Beispiel #25
0
def notebook(request):
    notebook_id = request.GET.get('notebook')

    if notebook_id:
        notebook = Notebook(document=Document2.objects.get(id=notebook_id))
    else:
        notebook = Notebook()

    autocomplete_base_url = ''
    try:
        autocomplete_base_url = reverse('beeswax:api_autocomplete_databases',
                                        kwargs={})
    except:
        LOG.exception('failed to get autocomplete base url')

    is_yarn_mode = False
    try:
        from spark.conf import LIVY_SERVER_SESSION_KIND
        is_yarn_mode = LIVY_SERVER_SESSION_KIND.get()
    except:
        LOG.exception('Spark is not enabled')

    return render(
        'notebook.mako', request, {
            'notebooks_json':
            json.dumps([notebook.get_data()]),
            'options_json':
            json.dumps({
                'languages': get_interpreters(request.user),
                'session_properties': SparkApi.PROPERTIES,
            }),
            'autocomplete_base_url':
            autocomplete_base_url,
            'is_yarn_mode':
            is_yarn_mode
        })