Ejemplo n.º 1
0
    def test_get_function(self):
        db = Mock()
        db.client = Mock(query_server={'dialect': 'hive'})
        db.get_function = Mock(return_value=[
            [
                'floor_month(param) - Returns the timestamp at a month granularity'
            ], ['param needs to be a timestamp value'], ['Example:'],
            [
                "> SELECT floor_month(CAST('yyyy-MM-dd HH:mm:ss' AS TIMESTAMP)) FROM src;"
            ], ['yyyy-MM-01 00:00:00']
        ])

        data = _autocomplete(db, database='floor_month', operation='function')

        assert_equal(
            data['function'], {
                'name':
                'floor_month',
                'signature':
                'floor_month(param)',
                'description':
                'Returns the timestamp at a month granularity\nparam needs to be a timestamp value\nExample:\n'
                '> SELECT floor_month(CAST(\'yyyy-MM-dd HH:mm:ss\' AS TIMESTAMP)) FROM src;\nyyyy-MM-01 00:00:00'
            })

        db.client = Mock(query_server={'dialect': 'impala'})
        data = _autocomplete(db, operation='function')

        assert_equal(data['function'], {})
Ejemplo n.º 2
0
    def autocomplete(self,
                     snippet,
                     database=None,
                     table=None,
                     column=None,
                     nested=None):
        db = self._get_db(snippet, interpreter=self.interpreter)
        query = None

        if snippet.get('query'):
            query = snippet.get('query')
        elif snippet.get('source') == 'query':
            document = Document2.objects.get(id=database)
            document.can_read_or_exception(self.user)
            notebook = Notebook(document=document).get_data()
            snippet = notebook['snippets'][0]
            query = self._get_current_statement(notebook, snippet)['statement']
            database, table = '', ''

        return _autocomplete(db,
                             database,
                             table,
                             column,
                             nested,
                             query=query,
                             cluster=self.interpreter)
Ejemplo n.º 3
0
    def autocomplete(self,
                     snippet,
                     database=None,
                     table=None,
                     column=None,
                     nested=None,
                     operation=None):
        db = self._get_db(snippet, interpreter=self.interpreter)
        query = None

        if snippet.get('query'):
            query = snippet.get('query')
        elif snippet.get('source') == 'query':
            document = Document2.objects.get(id=database)
            document.can_read_or_exception(self.user)
            notebook = Notebook(document=document).get_data()
            snippet = notebook['snippets'][0]
            query = self._get_current_statement(notebook, snippet)['statement']
            database, table = '', ''

        resp = _autocomplete(db,
                             database,
                             table,
                             column,
                             nested,
                             query=query,
                             cluster=self.interpreter,
                             operation=operation)

        if resp.get('error'):
            resp['message'] = resp.pop('error')
            if 'Read timed out' in resp['message']:
                raise QueryExpired(resp['message'])

        return resp
Ejemplo n.º 4
0
 def autocomplete(self,
                  snippet,
                  database=None,
                  table=None,
                  column=None,
                  nested=None):
     db = self._get_db(snippet)
     return _autocomplete(db, database, table, column, nested)
Ejemplo n.º 5
0
    def test_autocomplete_time_out(self):
        get_tables_meta = Mock(side_effect=ReadTimeout(
            "HTTPSConnectionPool(host='gethue.com', port=10001): Read timed out. (read timeout=120)"
        ))
        db = Mock(get_tables_meta=get_tables_meta)

        resp = _autocomplete(db, database='database')

        assert_equal(
            resp, {
                'code':
                500,
                'error':
                "HTTPSConnectionPool(host='gethue.com', port=10001): Read timed out. (read timeout=120)"
            })
Ejemplo n.º 6
0
    def autocomplete(self,
                     snippet,
                     database=None,
                     table=None,
                     column=None,
                     nested=None,
                     operation=None):
        db = self._get_db(snippet, cluster=self.cluster)

        return _autocomplete(db,
                             database,
                             table,
                             column,
                             nested,
                             query=None,
                             cluster=self.cluster)
Ejemplo n.º 7
0
    def test_get_functions(self):
        with patch('beeswax.api._get_functions') as _get_functions:
            db = Mock()
            _get_functions.return_value = [{
                'name': 'f1'
            }, {
                'name': 'f2'
            }, {
                'name': 'f3'
            }]
            resp = _autocomplete(db, database='default', operation='functions')

            assert_equal(resp['functions'], [{
                'name': 'f1'
            }, {
                'name': 'f2'
            }, {
                'name': 'f3'
            }])
Ejemplo n.º 8
0
 def autocomplete(self, snippet, database=None, table=None, column=None, nested=None):
   db = self._get_db(snippet)
   return _autocomplete(db, database, table, column, nested)