Ejemplo n.º 1
0
def search_entities_interactive(request):
    api = NavigatorApi()

    query_s = request.POST.get('query_s', '')
    prefix = request.POST.get('prefix')
    offset = request.POST.get('offset', 0)
    limit = request.POST.get('limit', 25)
    field_facets = json.loads(request.POST.get('field_facets') or '[]')
    sources = json.loads(request.POST.get('sources') or '[]')

    fqs = []
    fq_type = []

    if 'hive' in sources or 'impala' in sources:
        fq_type.append('TABLE')
        fq_type.append('VIEW')  # 'DATABASE', 'PARTITION', 'FIELD'
    elif 'hdfs' in sources:
        fq_type.append('FILE')
        fq_type.append('DIRECTORY')

    fqs += ['{!tag=type} %s' % ' OR '.join(['type:%s' % fq for fq in fq_type])]

    response = api.search_entities_interactive(query=query_s,
                                               limit=limit,
                                               offset=offset,
                                               facetFields=field_facets,
                                               facetPrefix=prefix,
                                               facetRanges=None,
                                               filterQueries=fqs,
                                               firstClassEntitiesOnly=None)

    response['status'] = 0

    return JsonResponse(response)
Ejemplo n.º 2
0
def list_tags(request):
    api = NavigatorApi(request.user)

    prefix = request.POST.get('prefix')
    offset = request.POST.get('offset', 0)
    limit = request.POST.get('limit', 25)

    data = api.search_entities_interactive(facetFields=['tags'],
                                           facetPrefix=prefix,
                                           limit=limit,
                                           offset=offset)

    response = {'tags': data['facets']['tags'], 'status': 0}

    return JsonResponse(response)
Ejemplo n.º 3
0
def list_tags(request):
  api = NavigatorApi(request.user)

  prefix = request.POST.get('prefix')
  offset = request.POST.get('offset', 0)
  limit = request.POST.get('limit', 25)

  data = api.search_entities_interactive(facetFields=['tags'], facetPrefix=prefix, limit=limit, offset=offset)

  response = {
    'tags': data['facets']['tags'],
    'status': 0
  }

  return JsonResponse(response)
Ejemplo n.º 4
0
def search_entities_interactive(request):
    """
  For search autocomplete.
  """
    api = NavigatorApi(request.user)

    query_s = json.loads(request.POST.get('query_s', ''))
    prefix = request.POST.get('prefix')
    offset = request.POST.get('offset', 0)
    limit = int(request.POST.get('limit', 25))
    field_facets = json.loads(request.POST.get('field_facets') or '[]')
    sources = json.loads(request.POST.get('sources') or '[]')

    f = {
        "outputFormat": {
            "type": "dynamic"
        },
        "name": {
            "type": "dynamic"
        },
        "lastModified": {
            "type": "date"
        },
        "sourceType": {
            "type": "dynamic"
        },
        "parentPath": {
            "type": "dynamic"
        },
        "lastAccessed": {
            "type": "date"
        },
        "type": {
            "type": "dynamic"
        },
        "sourceId": {
            "type": "dynamic"
        },
        "partitionColNames": {
            "type": "dynamic"
        },
        "serDeName": {
            "type": "dynamic"
        },
        "created": {
            "type": "date"
        },
        "fileSystemPath": {
            "type": "dynamic"
        },
        "compressed": {
            "type": "bool"
        },
        "clusteredByColNames": {
            "type": "dynamic"
        },
        "originalName": {
            "type": "dynamic"
        },
        "owner": {
            "type": "dynamic"
        },
        "extractorRunId": {
            "type": "dynamic"
        },
        "userEntity": {
            "type": "bool"
        },
        "sortByColNames": {
            "type": "dynamic"
        },
        "inputFormat": {
            "type": "dynamic"
        },
        "serDeLibName": {
            "type": "dynamic"
        },
        "originalDescription": {
            "type": "dynamic"
        },
        "lastModifiedBy": {
            "type": "dynamic"
        }
    }

    field_facets = ["tags", "type"] + f.keys()
    query_s = query_s.strip() + '*'

    last_query_term = [term for term in query_s.split()][-1]

    if last_query_term and last_query_term != '*':
        last_query_term = last_query_term.rstrip('*')
        (fname,
         fval) = last_query_term.split(':') if ':' in last_query_term else (
             last_query_term, '')
        field_facets = [f for f in field_facets if f.startswith(fname)]
    field_facets = field_facets[:5]

    response = api.search_entities_interactive(query_s=query_s,
                                               limit=limit,
                                               offset=offset,
                                               facetFields=field_facets,
                                               facetPrefix=prefix,
                                               facetRanges=None,
                                               firstClassEntitiesOnly=None,
                                               sources=sources)

    if response.get('facets'):  # Remove empty facets
        for fname, fvalues in response['facets'].items():
            if NAVIGATOR.APPLY_SENTRY_PERMISSIONS.get():
                fvalues = []
            else:
                fvalues = sorted([(k, v) for k, v in fvalues.items() if v > 0],
                                 key=lambda n: n[1],
                                 reverse=True)
            response['facets'][fname] = OrderedDict(fvalues)
            if ':' in query_s and not response['facets'][fname]:
                del response['facets'][fname]

    _augment_highlighting(query_s, response.get('results'))

    response['status'] = 0

    return JsonResponse(response)
Ejemplo n.º 5
0
def search_entities_interactive(request):
  """
  For search autocomplete.
  """
  api = NavigatorApi(request.user)

  query_s = json.loads(request.POST.get('query_s', ''))
  prefix = request.POST.get('prefix')
  offset = request.POST.get('offset', 0)
  limit = request.POST.get('limit', 25)
  field_facets = json.loads(request.POST.get('field_facets') or '[]')
  sources = json.loads(request.POST.get('sources') or '[]')

  f = {
      "outputFormat" : {
        "type" : "dynamic"
      },
      "name" : {
        "type" : "dynamic"
      },
      "lastModified" : {
        "type" : "date"
      },
      "sourceType" : {
        "type" : "dynamic"
      },
      "parentPath" : {
        "type" : "dynamic"
      },
      "deleteTime" : {
        "type" : "date"
      },
      "lastAccessed" : {
        "type" : "date"
      },
      "type" : {
        "type" : "dynamic"
      },
      "sourceId" : {
        "type" : "dynamic"
      },
      "partitionColNames" : {
        "type" : "dynamic"
      },
      "serDeName" : {
        "type" : "dynamic"
      },
      "created" : {
        "type" : "date"
      },
      "fileSystemPath" : {
        "type" : "dynamic"
      },
      "compressed" : {
        "type" : "bool"
      },
      "clusteredByColNames" : {
        "type" : "dynamic"
      },
      "deleted" : {
        "type" : "bool"
      },
      "originalName" : {
        "type" : "dynamic"
      },
      "owner" : {
        "type" : "dynamic"
      },
      "extractorRunId" : {
        "type" : "dynamic"
      },
      "userEntity" : {
        "type" : "bool"
      },
      "sortByColNames" : {
        "type" : "dynamic"
      },
      "inputFormat" : {
        "type" : "dynamic"
      },
      "serDeLibName" : {
        "type" : "dynamic"
      },
      "originalDescription" : {
        "type" : "dynamic"
      },
      "lastModifiedBy" : {
        "type" : "dynamic"
      }
    }

  field_facets = ["tags", "type"] + f.keys()
  query_s = query_s.strip() + '*'

  last_query_term = [term for term in query_s.split()][-1]

  if last_query_term and last_query_term != '*':
    last_query_term = last_query_term.rstrip('*')
    (fname, fval) = last_query_term.split(':') if ':' in last_query_term else (last_query_term, '')
    field_facets = [f for f in field_facets if f.startswith(fname)]
  field_facets = field_facets[:5]

  response = api.search_entities_interactive(
      query_s=query_s,
      limit=limit,
      offset=offset,
      facetFields=field_facets,
      facetPrefix=prefix,
      facetRanges=None,
      firstClassEntitiesOnly=None,
      sources=sources
  )

  if response.get('facets'): # Remove empty facets
    for fname, fvalues in response['facets'].items():
      fvalues = sorted([(k, v) for k, v in fvalues.items() if v > 0], key=lambda n: n[1], reverse=True)
      response['facets'][fname] = OrderedDict(fvalues)
      if ':' in query_s and not response['facets'][fname]:
        del response['facets'][fname]

  _augment_highlighting(query_s, response.get('results'))

  response['status'] = 0

  return JsonResponse(response)