I havent tried yet, but looks like the connection string asks for the
project to be specified.  Based on that (and cross project working for
other circumstances), I would imagine it will work, but...?  Give it a try!

One tricky place might be ensuring proper permissions, in both projects
(and without being too open).

On Sat, Jun 27, 2020, 5:46 AM Sheng Yang <liff...@163.com> wrote:

> Hi,
>
> I am working on Beam using Dataflow engine. Recently I am working on
> reading spanner data from different project. Say I run my Beam dataflow job
> in GCP project A, but the Spanner is in GCP project B. I searched all the
> documents, but can't find any documentation about SpannerIO reading data
> with the custom credential key files. Right now I am considering JdbcIO
> because it accepts custom credential as parameters and spanner also have
> jdbc api[1].
> Do I have something wrong in my description? Or am I considering the
> correct approach?
>
> String url = "jdbc:cloudspanner:/projects/my_project_id/"
>
>            + "instances/my_instance_id/"
>            + "databases/my_database_name"
>            + "?credentials=/home/cloudspanner-keys/my-key.json"
>            + ";autocommit=false";try (Connection connection = 
> DriverManager.getConnection(url)) {
>   try(ResultSet rs = connection.createStatement()
>            .executeQuery("SELECT SingerId, AlbumId, MarketingBudget FROM 
> Albums")) {
>     while(rs.next()) {
>       Long singerId = rs.getLong(1);
>     }
>   }
> }
>
>
> [1]: https://github.com/googleapis/java-spanner-jdbc
>
> Thanks,
> Sheng
>
>
>
>

Reply via email to