Esempio n. 1
0
    def _collect_elements(self):
        # If expr is a ValueExpr, we must seek out the TableExprs that it
        # references, build their ASTs, and mark them in our QueryContext

        # For now, we need to make the simplifying assumption that a value
        # expression that is being translated only depends on a single table
        # expression.

        source_expr = self.query_expr

        # hm, is this the best place for this?
        root_op = source_expr.op()
        if isinstance(root_op, ops.Join) and not isinstance(
                root_op, ops.MaterializedJoin):
            # Unmaterialized join
            source_expr = source_expr.materialize()

        if isinstance(root_op, ops.TableNode):
            self._collect(source_expr, toplevel=True)
            if self.table_set is None:
                raise com.InternalError('no table set')
        else:
            # Expressions not depending on any table
            if isinstance(root_op, ops.ExpressionList):
                self.select_set = source_expr.exprs()
            else:
                self.select_set = [source_expr]
Esempio n. 2
0
 def _get_cursor(self):
     try:
         cursor = self.connection_pool.popleft()
     except IndexError:  # deque is empty
         with self.lock:
             # NB: Do not put a lock around the entire if statement.
             # This will cause a deadlock because _new_cursor calls the
             # ImpalaCursor constructor which takes a lock to increment the
             # connection pool size.
             connection_pool_size = self.connection_pool_size
         if connection_pool_size < self.max_pool_size:
             return self._new_cursor()
         raise com.InternalError('Too many concurrent / hung queries')
     else:
         if (cursor.database != self.database
                 or cursor.options != self.options):
             return self._new_cursor()
         cursor.released = False
         return cursor