Esempio n. 1
0
 def inspect(self, format_settings=None):
     catalog = server.get(self.uri).json()
     schema = FrameSchema.from_strings_to_types(catalog["metadata"]['columns'])
     data = catalog["data"]
     self.rows = map(lambda row: Row(schema, row), data)
     default_format_setting = ui.InspectSettings(wrap=len(schema), truncate=10, width=200)
     format_settings = default_format_setting if format_settings is None else format_settings
     return RowsInspection(data, schema, 0, format_settings)
Esempio n. 2
0
    def query(self, query_url):
        """
        Issues the query_request to the server
        """
        logger.info("Issuing query " + query_url)
        try:
            response = server.get(query_url)
        except:
            # do a single retry
            response = server.get(query_url)

        response_json = response.json()

        schema = response_json["result"]["schema"]['columns']

        if response_json["complete"]:
            data = response_json["result"]["data"]
            return QueryResult(data, schema)
        else:
            command = self.poll_command_info(response)

            #retreive the data
            printer = ProgressPrinter()
            total_pages = command.result["total_pages"] + 1

            start = 1
            data = []
            for i in range(start, total_pages):
                next_partition = self.get_query_response(command.id_number, i)
                data_in_page = next_partition.result["data"]

                data.extend(data_in_page)

                #if the total pages is greater than 10 display a progress bar
                if total_pages > 5:
                    finished = i == (total_pages - 1)
                    if not finished:
                        time.sleep(.5)
                    progress = [{
                        "progress": (float(i) / (total_pages - 1)) * 100,
                        "tasks_info": {
                            "retries": 0
                        }
                    }]
                    printer.print_progress(progress, finished)
        return QueryResult(data, schema)
Esempio n. 3
0
    def query(self, query_url):
        """
        Issues the query_request to the server
        """
        logger.info("Issuing query " + query_url)
        try:
            response = server.get(query_url)
        except:
            # do a single retry
            response = server.get(query_url)

        response_json = response.json()

        schema = response_json["result"]["schema"]['columns']

        if response_json["complete"]:
            data = response_json["result"]["data"]
            return QueryResult(data, schema)
        else:
            command = self.poll_command_info(response)

            #retreive the data
            printer = ProgressPrinter()
            total_pages = command.result["total_pages"] + 1

            start = 1
            data = []
            for i in range(start, total_pages):
                next_partition = self.get_query_response(command.id_number, i)
                data_in_page = next_partition.result["data"]

                data.extend(data_in_page)

                #if the total pages is greater than 10 display a progress bar
                if total_pages > 5:
                    finished = i == (total_pages - 1)
                    if not finished:
                        time.sleep(.5)
                    progress = [{
                        "progress": (float(i)/(total_pages - 1)) * 100,
                        "tasks_info": {
                            "retries": 0
                        }
                    }]
                    printer.print_progress(progress, finished)
        return QueryResult(data, schema)
Esempio n. 4
0
 def inspect(self, format_settings=None):
     catalog = server.get(self.uri).json()
     schema = FrameSchema.from_strings_to_types(
         catalog["metadata"]['columns'])
     data = catalog["data"]
     self.rows = map(lambda row: Row(schema, row), data)
     default_format_setting = ui.InspectSettings(wrap=len(schema),
                                                 truncate=10,
                                                 width=200)
     format_settings = default_format_setting if format_settings is None else format_settings
     return RowsInspection(data, schema, 0, format_settings)
Esempio n. 5
0
 def get_query_response(self, id, partition):
     """
     Attempt to get the next partition of data as a CommandInfo Object. Allow for several retries
     :param id: Query ID
     :param partition: Partition number to pull
     """
     max_retries = 20
     for i in range(max_retries):
         try:
             info = CommandInfo(server.get("queries/%s/data/%s" % (id, partition)).json())
             return info
         except HTTPError as e:
             time.sleep(5)
             if i == max_retries - 1:
                 raise e
Esempio n. 6
0
def default_repr(self, collection_name):
    """Default __repr__ for a synthesized class"""
    entity = type(self).__name__
    try:
        from trustedanalytics.rest.atkserver import server
        uri = server.create_full_uri(self.uri)
        response = server.get(uri).json()
        name = response.get('name', None)
        if name:
            details = ' "%s"' % response['name']
        else:
            details = ' <unnamed@%s>' % response['uri']
    except:
        raise
        #details = " (Unable to collect details from server)"
    return entity + details
Esempio n. 7
0
 def get_query_response(self, id, partition):
     """
     Attempt to get the next partition of data as a CommandInfo Object. Allow for several retries
     :param id: Query ID
     :param partition: Partition number to pull
     """
     max_retries = 20
     for i in range(max_retries):
         try:
             info = CommandInfo(
                 server.get("queries/%s/data/%s" % (id, partition)).json())
             return info
         except HTTPError as e:
             time.sleep(5)
             if i == max_retries - 1:
                 raise e
Esempio n. 8
0
def default_repr(self, collection_name):
    """Default __repr__ for a synthesized class"""
    entity = type(self).__name__
    try:
        from trustedanalytics.rest.atkserver import server
        uri = server.create_full_uri(collection_name + "/" + str(self._id))
        response = server.get(uri).json()
        name = response.get('name', None)
        if name:
            details = ' "%s"' % response['name']
        else:
            details = ' <unnamed@%s>' % response['id']
    except:
        raise
        #details = " (Unable to collect details from server)"
    return entity + details
Esempio n. 9
0
 def _get_model_info(self):
     response = server.get(self._get_model_full_uri())
     return ModelInfo(response.json())
Esempio n. 10
0
 def _get_command_info(uri):
     response = server.get(uri)
     return CommandInfo(response.json())
Esempio n. 11
0
 def _get_command_info(uri):
     response = server.get(uri)
     return CommandInfo(response.json())