Exemple #1
0
 def test_multi_line_comments(self):
     assert is_select("""
         /*
         Comment 1
         Comment 2
         */
         SELECT
     """)
Exemple #2
0
    def submit(
        self,
        operation: str,
        parameters: PARAMETERS = None,
    ) -> Query:
        """
        Submit a query and return.

        This is a non-blocking method that starts a query and returns.
        Returns a :class:`Query` instance for monitoring query execution
        and downloading results later.

        An existing query can be returned, if the caching was configured.
        Only SELECT queries are cached.

        :param operation: an SQL query to be executed
            Can contain ``%s`` or ``%(key)s`` placeholders for substitution
            by *parameters*.
        :param parameters: parameters to substitute in *operation*.
            All substitute parameters are quoted appropriately.
            See the :meth:`.quote` method for a supported parameter types.
        :type parameters: Union[None, Tuple[SQL_SCALAR, ...], Mapping[str, SQL_SCALAR]]
        :return: a query instance
        """
        sql = self._get_sql(operation, parameters)
        should_cache = is_select(sql)
        if should_cache:
            execution_id = self._cache.load_execution_id(self.database, sql)
            if execution_id is not None:
                return self.get_query(execution_id)
        execution_id = self._proxy.start_query_execution(
            sql,
            database=self.database,
            workgroup=self.workgroup,
            output_location=self.output_location,
        )
        if should_cache:
            self._cache.save_execution_id(self.database, sql, execution_id)
        return self.get_query(execution_id)
Exemple #3
0
    def get_results(self) -> QueryResults:
        """
        Download results of this query execution.

        Cached results can be returned, if the caching was configured.
        Only SELECT queries are cached.

        Waits until this query execution finishes and downloads results.
        Raises :class:`.AthenaQueryError` if the query failed.
        """
        # When a user calls athena.get_query(execution_id).get_results(),
        # we have to look into the cache without knowing what SQL was executed,
        # so whether the query is cacheable.
        results = self._cache.load_results(self._execution_id)
        if results is not None:
            return results
        self.join()
        info = self.get_info()
        results = self._proxy.get_query_results(info)
        should_cache = is_select(info.sql)
        if should_cache:
            self._cache.save_results(self._execution_id, results)
        return results
Exemple #4
0
 def test_with_select_lowercase(self):
     assert is_select("with (...) AS t select ...")
Exemple #5
0
 def test_with_select(self):
     assert is_select("WITH (...) AS t SELECT ...")
Exemple #6
0
 def test_select_lowercase(self):
     assert is_select("select 1")
Exemple #7
0
 def test_select(self):
     assert is_select("SELECT 1")
Exemple #8
0
 def test_multi_line_comment_escaped(self):
     assert is_select(r"""
         /* *\/ */
         SELECT
     """)
Exemple #9
0
 def test_single_line_comments(self):
     assert is_select("""
         -- Comment 1
         -- Comment 2
         SELECT
     """)
Exemple #10
0
 def test_select_without_whitesplace(self):
     assert is_select("SELECT*FROM ...")
Exemple #11
0
 def test_create(self):
     assert not is_select("CREATE TABLE AS ... SELECT")
Exemple #12
0
 def test_insert(self):
     assert not is_select("INSERT ... AS SELECT")