Exemple #1
0
    def _upload_query_result(self, cursor, statement_execution_id: int):
        # While uploading, the first few rows are fetched and stored as well
        # CACHE_ROW_SIZE = 50000  the number of rows stored to mysql, keep it < than previous value
        rows_uploaded = 0
        columns = cursor.get_columns()
        if (
            columns is None or len(columns) == 0
        ):  # No need to go through queries because no information
            return None, rows_uploaded

        key = "querybook_temp/%s/result.csv" % str(statement_execution_id)
        uploader = GenericUploader(key)
        uploader.start()

        uploader.write(row_to_csv(columns))
        rows_uploaded += 1  # 1 row for the column

        for row in cursor.get_rows_iter():
            did_upload = uploader.write(row_to_csv(row))
            if not did_upload:
                break
            rows_uploaded += 1
        uploader.end()

        return uploader.upload_url, rows_uploaded
Exemple #2
0
    def test_string_escape(self):
        multiline_row = [123, "Hello\nWorld", 123]
        self.assertEqual(row_to_csv(multiline_row), '123,"Hello\nWorld",123\n')

        comma_row = [123, "Hello,World", 123]
        self.assertEqual(row_to_csv(comma_row), '123,"Hello,World",123\n')

        quote_row = [123, 'Hello"World', 123]
        self.assertEqual(row_to_csv(quote_row), '123,"Hello""World",123\n')
Exemple #3
0
 def test_json_case(self):
     row = ["Hello", [], {}]
     self.assertEqual(row_to_csv(row), "Hello,[],{}\n")
Exemple #4
0
 def test_simple_case(self):
     row = ["Hello World", 1234, 0.5, "中文"]
     self.assertEqual(row_to_csv(row), "Hello World,1234,0.5,中文\n")