[
https://issues.apache.org/jira/browse/BEAM-7246?focusedWorklogId=363634&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-363634
]
ASF GitHub Bot logged work on BEAM-7246:
----------------------------------------
Author: ASF GitHub Bot
Created on: 26/Dec/19 16:04
Start Date: 26/Dec/19 16:04
Worklog Time Spent: 10m
Work Description: mszb commented on pull request #9606: [BEAM-7246] Add
Google Spanner IO Read on Python SDK
URL: https://github.com/apache/beam/pull/9606#discussion_r361484541
##########
File path: sdks/python/apache_beam/io/gcp/spannerio.py
##########
@@ -0,0 +1,558 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""Google Cloud Spanner IO
+
+This is an experimental module for reading and writing data from Google Cloud
+Spanner. Visit: https://cloud.google.com/spanner for more details.
+
+To read from Cloud Spanner apply _ReadFromSpanner transformation. It will
+return a PCollection, where each element represents an individual row returned
+from the read operation. Both Query and Read APIs are supported.
+
+_ReadFromSpanner relies on the _ReadOperation objects which is exposed by the
+SpannerIO API. _ReadOperation holds the immutable data which is responsible to
+execute batch and naive reads on Cloud Spanner. This is done for more
+convenient programming.
+
+_ReadFromSpanner reads from Cloud Spanner by providing either an 'sql' param
+in the constructor or 'table' name with 'columns' as list. For example:::
+
+ records = (pipeline
+ | _ReadFromSpanner(PROJECT_ID, INSTANCE_ID, DB_NAME,
+ sql='Select * from users'))
+
+ records = (pipeline
+ | _ReadFromSpanner(PROJECT_ID, INSTANCE_ID, DB_NAME,
+ table='users', columns=['id', 'name', 'email']))
+
+You can also perform multiple reads by providing a list of _ReadOperations
+to the _ReadFromSpanner transform constructor. _ReadOperation exposes two
static
+methods. Use 'query' to perform sql based reads, 'table' to perform read from
+table name. For example:::
+
+ read_operations = [
+ _ReadOperation.table('customers', ['name', 'email']),
+ _ReadOperation.table('vendors', ['name', 'email']),
+ ]
+ all_users = pipeline | _ReadFromSpanner(PROJECT_ID, INSTANCE_ID, DB_NAME,
+ read_operations=read_operations)
+
+ ...OR...
+
+ read_operations = [
+ _ReadOperation.query('Select name, email from
customers'),
+ _ReadOperation.query(
+ sql='Select * from users where id <= @user_id',
+ params={'user_id': 100},
+ params_type={'user_id': param_types.INT64}
+ ),
+ ]
+ # `params_types` are instance of `google.cloud.spanner_v1.param_types`
Review comment:
I've updated the code. Now it referenced to
`google.cloud.spanner.param_types`.
But there is one import (`google.cloud.spanner_v1.database.BatchSnapshot`)
which we need in our pipeline. Unfortunately, spanner sdk does not have its
alias set in the package so the only option we have is to import is via
version-specific.
https://github.com/googleapis/google-cloud-python/blob/master/spanner/google/cloud/spanner.py
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 363634)
Time Spent: 9h (was: 8h 50m)
> Create a Spanner IO for Python
> ------------------------------
>
> Key: BEAM-7246
> URL: https://issues.apache.org/jira/browse/BEAM-7246
> Project: Beam
> Issue Type: Bug
> Components: io-py-gcp
> Reporter: Reuven Lax
> Assignee: Shehzaad Nakhoda
> Priority: Major
> Time Spent: 9h
> Remaining Estimate: 0h
>
> Add I/O support for Google Cloud Spanner for the Python SDK (Batch Only).
> Testing in this work item will be in the form of DirectRunner tests and
> manual testing.
> Integration and performance tests are a separate work item (not included
> here).
> See https://beam.apache.org/documentation/io/built-in/. The goal is to add
> Google Clound Spanner to the Database column for the Python/Batch row.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)