locally finite + quasi compact vs finite An elementary question of algebraic geometry which was posted on math.stackexchange but received no answer there.
Let $f: X \rightarrow Y$ be a morphism of schemes.
Assume that 
(i) $f: X \rightarrow Y$ is locally finite, in this sense: $Y$ can be covered by affine open
sets $U_i=spec\  A_i$, and $f^{-1}(U_i)$ can be in turn covered by affine open sets $V_{i,j} = spec \ B_{i,j}$, in
such a way that each $B_{i,j}$ is finitely generated as an $A_i$-module.
(ii) $f$ is quasi-compact.
Then does it imply that $f$ is a finite morphism?
 A: $\newcommand\Spec{\mathrm{Spec}}$
$ $
Since finiteness is local in the base, we may
assume that $Y = \Spec(A)$ is affine.
The assumption then becomes that $f: X \rightarrow \Spec(A)$ is
quasi-compact, and that $X$ may be covered by finitely many
(by quasi-compactness)
open affines $\Spec(B)$ which are finite over $A$.
Suppose that $f$ is an open immersion. We show that $X$ is closed
and hence finite in $Y$.
Since conditions (i) and (ii) are local on the base, we may
assume that $Y = \Spec(A)$ is connected.
Then, for each $\Spec(B)$ in our cover of $X$,
$\Spec(B)$ is open in $X$ and hence $Y$, and yet finite and thus closed in $Y$.
Since $Y$ is connected, it follows that either $\Spec(B) = X = Y$,
or $X$ is the empty set.
Suppose that $f$ is separated. Then, by Zariski's main theorem, there
exists a factorization
$$X \rightarrow \Spec(A') = Y' \rightarrow \Spec(A) = Y$$
where the first map is an open immersion and the second is finite.
It follows that for each $B$ there is a map $A \rightarrow A'
\rightarrow B$ which makes $B$ finite over $A$. It follows that $B$
is also finite over $A'$. Hence, by the argument above, $X$ is finite
over $Y'$,
and thus $X \rightarrow Y$ is also finite.
Suppose, however, that $f$ is not separated. Then take $X$ to be the
affine line with the origin doubled and $Y$ to be the affine line.
Then the map $X \rightarrow Y$ is not finite because it is not even affine.
